object_id()
get the object identification in an image.
object_coord()
get the object coordinates and (optionally) draw a
bounding rectangle around multiple objects in an image.
object_contour()
returns the coordinates (x
and y
) for the contours
of each object in the image.
object_isolate()
isolates an object from an image.
object_coord(
img,
id = NULL,
index = "NB",
watershed = TRUE,
invert = FALSE,
opening = FALSE,
closing = FALSE,
filter = FALSE,
fill_hull = FALSE,
threshold = "Otsu",
edge = 2,
extension = NULL,
tolerance = NULL,
object_size = "medium",
parallel = FALSE,
workers = NULL,
plot = TRUE,
verbose = TRUE
)object_contour(
img,
pattern = NULL,
dir_original = NULL,
center = FALSE,
index = "NB",
invert = FALSE,
opening = FALSE,
closing = FALSE,
filter = FALSE,
fill_hull = FALSE,
smooth = FALSE,
threshold = "Otsu",
watershed = TRUE,
extension = NULL,
tolerance = NULL,
object_size = "medium",
parallel = FALSE,
workers = NULL,
plot = TRUE,
verbose = TRUE
)
object_isolate(
img,
id = NULL,
parallel = FALSE,
workers = NULL,
verbose = TRUE,
...
)
object_id(img, parallel = FALSE, workers = NULL, verbose = TRUE, ...)
object_id()
An image of class "Image"
containing the object's
identification.
object_coord()
A list with the coordinates for the bounding rectangles.
If id = "all"
or a numeric vector, a list with a vector of coordinates is
returned.
object_isolate()
An image of class "Image"
containing the isolated
object.
An image of class Image
or a list of Image
objects.
For object_coord()
, a vector (or scalar) of object id
to compute the
bounding rectangle. Object ids can be obtained with object_id()
. Set id = "all"
to compute the coordinates for all objects in the image. If id = NULL
(default) a bounding rectangle is drawn including all the objects.
For object_isolate()
, a scalar that identifies the object to be extracted.
The index to produce a binary image used to compute bounding
rectangle coordinates. See image_binary()
for more details.
If TRUE
(default) performs watershed-based object
detection. This will detect objects even when they are touching one other.
If FALSE
, all pixels for each connected set of foreground pixels are set
to a unique object. This is faster but is not able to segment touching
objects.
Inverts the binary image, if desired. Defaults to FALSE
.
Morphological operations (brush size)
opening
performs an erosion followed by a dilation. This helps to
remove small objects while preserving the shape and size of larger objects.
closing
performs a dilatation followed by an erosion. This helps to
fill small holes while preserving the shape and size of larger objects.
filter
performs median filtering in the binary image. Provide a positive
integer > 1 to indicate the size of the median filtering. Higher values are
more efficient to remove noise in the background but can dramatically impact
the perimeter of objects, mainly for irregular perimeters such as leaves
with serrated edges.
Hierarchically, the operations are performed as opening > closing > filter. The value declared in each argument will define the brush size.
Fill holes in the objects? Defaults to FALSE
.
By default (threshold = "Otsu"
), a threshold value based
on Otsu's method is used to reduce the grayscale image to a binary image.
If a numeric value is informed, this value will be used as a threshold.
Inform any non-numeric value different than "Otsu" to iteratively chosen
the threshold based on a raster plot showing pixel intensity of the index.
The number of pixels in the edge of the bounding rectangle.
Defaults to 2
.
Controls the watershed segmentation of
objects in the image. See analyze_objects()
for more details.
Processes the images asynchronously (in parallel) in separate
R sessions running in the background on the same machine. It may speed up
the processing time when image
is a list. The number of sections is set
up to 50% of available cores.
A positive numeric scalar or a function specifying the maximum number of parallel processes that can be active at the same time.
Shows the image with bounding rectangles? Defaults to
TRUE
.
If TRUE
(default) a summary is shown in the console.
A pattern of file name used to identify images to be imported.
For example, if pattern = "im"
all images in the current working directory
that the name matches the pattern (e.g., img1.-, image1.-, im2.-) will be
imported as a list. Providing any number as pattern (e.g., pattern = "1"
)
will select images that are named as 1.-, 2.-, and so on. An error will be
returned if the pattern matches any file that is not supported (e.g.,
img1.pdf).
The directory containing the original images. Defaults
to NULL
, which means that the current working directory will be
considered.
If TRUE
returns the object contours centered on the origin.
whether the object contours should be smoothed with
poly_smooth()
. Defaults to FALSE
. To smooth use a numeric value
indicating the number of interactions used to smooth the contours.
For object_isolate()
, further arguments passed on to object_coord()
.
For object_id()
, further arguments passed on to analyze_objects()
.
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
img <- image_pliman("la_leaves.jpg")
# Get the object's (leaves) identification
object_id(img)
# Get the coordinates and draw a bounding rectangle around leaves 1 and 3
object_coord(img, id = c(1, 3))
# Isolate leaf 3
isolated <- object_isolate(img, id = 3)
plot(isolated)
}
Run the code above in your browser using DataLab