clean | R Documentation |
Cleaning up a pixel set here means removing small isolated elements (speckle). Filling in means removing holes. Cleaning up can be achieved by shrinking the set (removing speckle), followed by growing it back up. Filling in can be achieved by growing the set (removing holes), and shrinking it again.
clean(px, ...)
fill(px, ...)
px |
a pixset |
... |
parameters that define the structuring element to use, passed on to "grow" and "shrink" |
fill()
: Fill in holes using morphological closing
Simon Barthelme
im <- load.example("birds") %>% grayscale
sub <- imsub(-im,y> 380) %>% threshold("85%")
plot(sub)
#Turn into a pixel set
px <- sub==1
layout(t(1:2))
plot(px,main="Before clean-up")
clean(px,3) %>% plot(main="After clean-up")
#Now fill in the holes
px <- clean(px,3)
plot(px,main="Before filling-in")
fill(px,28) %>% plot(main="After filling-in")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.