Skip to contents

Converts a binary matrix to an sf polygon

Usage

binaryImageToSF(binaryMatrix, xmin, xmax, ymin, ymax)

Arguments

binaryMatrix

matrix; binary matrix

xmin

integer; minimum x coordinate of the coordinate system

xmax

integer; maximum x coordinate of the coordinate system

ymin

integer; minimum y coordinate of the coordinate system

ymax

integer; maximum y coordinate of the coordinate system

Value

sf object

Examples

matrix_R <- matrix(c(
    0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 1, 1, 1, 1, 1, 0, 0, 0,
    0, 1, 1, 0, 0, 1, 1, 0, 0,
    0, 1, 1, 0, 0, 1, 1, 0, 0,
    0, 1, 1, 1, 1, 1, 0, 0, 0,
    0, 1, 1, 0, 1, 1, 0, 0, 0,
    0, 1, 1, 0, 0, 1, 1, 0, 0,
    0, 1, 1, 0, 0, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0
), nrow = 9, byrow = TRUE)
poly_R <- binaryImageToSF(matrix_R, xmin = 0, xmax = 1, ymin = 0, ymax = 1)
plot(poly_R)