Select regions of interest in an image using different morphological operations
Arguments
- img
- threshold
A
numeric
to be passed tothreshold
or avector
of values for each image inimg
- shrink
A
numeric
to be passed toshrink
or avector
of values for each image inimg
- grow
A
numeric
to be passed togrow
or avector
of values for each image inimg
- fill
A
numeric
to be passed tofill
or avector
of values for each image inimg
- clean
A
numeric
to be passed toclean
or avector
of values for each image inimg
- tolerance
A
numeric
to be passed tolabel
or avector
of values for each image inimg
- n
A
numeric
of the number of regions of interest or avector
of values for each image inimg
Value
A cimg
. The original input img
with an
additional attribute label
. label
is a vector
of
integer
s. The labels for the selected regions of interests starts
from 1 and 0 is ignored. When img
is a list, a list
is
returned.
Details
The function applies several imager
morphological
manipulations to select the regions of interest. These include
threshold
which sets all values below certain cut to
0; shrink
/grow
for pixel set
dilation and erosion; fill
/clean
for removing isolated regions and holes. When n
is provided, the
individual regions (connected components) are selected where tolerance
is used to determine if two pixels belong to the same region.
Examples
# load images
fl <- system.file('extdata', 'Image0001_.jpg', package = 'colocr')
img <- image_load(fl)
# choose ROI
newimg <- roi_select(img, threshold = 90)
# check the ROI labels
unique(attr(newimg, 'label'))
#> [1] 0 1