[R-sig-Geo] Equivalent imclearborder matlab function

Andres Diaz madiazl at gmail.com
Tue Apr 5 11:29:14 CEST 2016


Hi everybody,

Someone known an equivalent function for imclearborder? Basically
imclearborder detects when a path is connected to the border of a matrix
(raster, grid etc..) and remove the binary data

In the example of mathlab (BW is the original matrix):

BW = [0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      1     0     0     1     1     1     0     0     0
      0     1     0     1     1     1     0     0     0
      0     0     0     1     1     1     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0];


Clear pixels on the border of the image using 4-connectivity.

BWc1 = imclearborder(BW,4)


BWc1 =

     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     1     0     0     0
     0     1     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0


 Note that imclearborder does not clear the pixel at (5,2) because, with
4-connectivity, it is not considered connected to the border pixel at (4,1).

with 8-conectivity

BWc2 = imclearborder(BW,8)


BWc2 =

     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0


Thank you in advance.



Andrés D.

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list