aoles / EBImage

:art: Image processing toolbox for R
71 stars 28 forks source link

8-connected bwlabels #30

Closed nickcee closed 6 years ago

nickcee commented 6 years ago

Hi,

Would it be possible to modify the bwlabels to take into account 8-connected pixels. As far as I can tell, it appears to only take into account 4-connected pixels.

Cheers, Nick

aoles commented 6 years ago

Dear Nick,

thank you for reaching out. If I understand it correctly, you would like that the following sample objects touching at corners are considered as a single entity.

library("EBImage")

# create sample image
img <- Image(dim = c(100, 100))
img[10:50, 10:50] <- img[51:90, 51:90] <- 1
display(img)

image

There are no plans of modifying the current behavior of bwlabels. You might, however, use the closing filter with the minimal cross-shaped filter of size 3 to "bridge" the objects at the touching corner. This has minimal impact of the objects' shape while ensuring their connectivity.

img <- closing(img, kern = makeBrush(3, "diamond"))
display(img)

image

Cheers, Andrzej