This R code is a function that allows the user to manually segment an image based on the parameters provided. This only works in an interactive section.
image_segment_manual(
img,
shape = c("free", "circle", "rectangle"),
type = c("select", "remove"),
viewer = get_pliman_viewer(),
resize = TRUE,
edge = 5,
plot = TRUE
)
A list with the segmented image and the mask used for segmentation.
An Image
object.
The type of shape to use. Defaults to "free". Other possible values are "circle" and "rectangle". Partial matching is allowed.
The type of segmentation. By default (type = "select"
) objects
are selected. Use type = "remove"
to remove the selected area from the
image.
The viewer option. If not provided, the value is retrieved
using get_pliman_viewer()
. This option controls the type of viewer to use
for interactive plotting. The available options are "base" and "mapview".
If set to "base", the base R graphics system is used for interactive
plotting. If set to "mapview", the mapview package is used. To set this
argument globally for all functions in the package, you can use the
set_pliman_viewer()
function. For example, you can run
set_pliman_viewer("mapview")
to set the viewer option to "mapview" for
all functions.
By default, the segmented object is resized to fill the
original image size. Use resize = FALSE
to keep the segmented object in
the original scale.
Number of pixels to add in the edge of the segmented object when
resize = TRUE
. Defaults to 5.
Plot the segmented object? Defaults to TRUE
.
If the shape is "free", it allows the user to draw a perimeter to select/remove objects. If the shape is "circle", it allows the user to click on the center and edge of the circle to define the desired area. If the shape is "rectangle", it allows the user to select two points to define the area.
if (interactive()) {
img <- image_pliman("la_leaves.jpg")
seg <- image_segment_manual(img)
plot(seg$mask)
}
Run the code above in your browser using DataLab