Givin an image with multiple objects, object_export()
will split the
objects into a list of objects using object_split()
and then export them to
multiple images into the current working directory (or a subfolder). Batch
processing is performed by declaring a file name pattern that matches the
images within the working directory.
object_export(
img,
pattern = NULL,
dir_original = NULL,
dir_processed = NULL,
format = ".jpg",
squarize = FALSE,
augment = FALSE,
times = 12,
index = "NB",
lower_size = NULL,
watershed = FALSE,
invert = FALSE,
fill_hull = FALSE,
filter = 2,
threshold = "Otsu",
extension = NULL,
tolerance = NULL,
object_size = "medium",
edge = 20,
remove_bg = FALSE,
parallel = FALSE,
verbose = TRUE
)
A NULL
object.
The image to be analyzed.
A pattern of file name used to identify images to be
processed. 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 and processed. 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
. It can be either a full path, e.g., "C:/Desktop/imgs"
, or a
subfolder within the current working directory, e.g., "/imgs"
.
Optional character string indicating a subfolder within the current working directory to save the image(s). If the folder doesn't exist, it will be created.
The format of image to be exported.
Squarizes the image before the exportation? If TRUE
,
image_square()
will be called internally.
A logical indicating if exported objects should be augmented using
image_augment()
. Defaults to FALSE
.
The number of times to rotate the image.
A character value specifying the target mode for conversion to
binary image when foreground
and background
are not declared. Defaults
to "NB"
(normalized blue). See image_index()
for more details. User can
also calculate your own index using the bands names, e.g. index = "R+B/G"
Plant images often contain dirt and dust. To prevent dust from
affecting the image analysis, objects with lesser than 10% of the mean of all objects
are removed. Set lower_limit = 0
to keep all the objects.
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. This is useful to process
images with a black background. Defaults to FALSE
. If reference = TRUE
is use, invert
can be declared as a logical vector of length 2 (eg.,
invert = c(FALSE, TRUE
). In this case, the segmentation of objects and
reference from the foreground using back_fore_index
is performed using the
default (not inverted), and the segmentation of objects from the reference
is performed by inverting the selection (selecting pixels higher than the
threshold).
Fill holes in the binary image? Defaults to FALSE
. This is
useful to fill holes in objects that have portions with a color similar to
the background. IMPORTANT: Objects touching each other can be combined into
one single object, which may underestimate the number of objects in an
image.
Performs median filtering in the binary image? See more at
image_filter()
. Defaults to FALSE
. Use a positive integer to define the
size of the median filtering. Larger values are effective at removing noise,
but adversely affect edges.
The theshold method to be used.
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.
If threshold = "adaptive"
, adaptive thresholding (Shafait et al. 2008)
is used, and will depend on the k
and windowsize
arguments.
If any non-numeric value different than "Otsu"
and "adaptive"
is used,
an iterative section will allow you to choose the threshold based on a
raster plot showing pixel intensity of the index.
Radius of the neighborhood in pixels for the detection of neighboring objects. Higher value smooths out small objects.
The minimum height of the object in the units of image intensity between its highest point (seed) and the point where it contacts another object (checked for every contact pixel). If the height is smaller than the tolerance, the object will be combined with one of its neighbors, which is the highest.
The size of the object. Used to automatically set up
tolerance
and extension
parameters. One of the following. "small"
(e.g, wheat grains), "medium"
(e.g, soybean grains), "large"
(e.g, peanut
grains), and "elarge"
(e.g, soybean pods)`.
The number of pixels to be added in the edge of the segmented object. Defaults to 5.
If TRUE
, the pixels that are not part of objects are
converted to white.
If TRUE
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, especially when pattern
is used is informed.
When object_index
is informed, multiple sections will be used to extract
the RGB values for each object in the image. This may significantly speed up
processing time when an image has lots of objects (say >1000).
If TRUE
(default) a summary is shown in the console.
if(interactive()){
library(pliman)
img <- image_pliman("potato_leaves.jpg")
object_export(img,
remove_bg = TRUE)
}
Run the code above in your browser using DataLab