RNotes | EBImage


library(EBImage)

Make objects

x <- readImage(system.file('images', 'shapes.png', package='EBImage'))
x <- x[110:512,1:130]
y <- bwlabel(x)

Number of objects found

max(y)
## [1] 7
display(normalize(y), title='Objects')

Remove every second letter

objects <- list( seq.int(from=2, to=max(y), by=2),
                 seq.int(from=1, to=max(y), by=2)
               )
z <- rmObjects(combine(y, y), objects)
display(normalize(z), title='Object removal')
## The image contains more than one frame: only the first one is displayed. To display all frames use 'all = TRUE'.

Number of objects left in each image

apply(z, 3, max)
## [1] 4 3

Remove objects without re-enumerating

z <- rmObjects(y, objects, reenumerate = FALSE)

Labels of objects remaining

unique(as.vector(z))[-1L]
## [1] 1 3 5 7

Re-index objects

z <- reenumerate(z)
unique(as.vector(z))[-1L]
## [1] 1 2 3 4

packageVersion("EBImage")
## [1] '4.8.2'

efg
2015-01-18 2016