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.
Usage
image_segment_manual(
img,
shape = c("free", "circle", "rectangle"),
type = c("select", "remove"),
viewer = get_pliman_viewer(),
resize = TRUE,
edge = 5,
plot = TRUE
)
Arguments
- img
An
Image
object.- shape
The type of shape to use. Defaults to "free". Other possible values are "circle" and "rectangle". Partial matching is allowed.
- type
The type of segmentation. By default (
type = "select"
) objects are selected. Usetype = "remove"
to remove the selected area from the image.- viewer
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 theset_pliman_viewer()
function. For example, you can runset_pliman_viewer("mapview")
to set the viewer option to "mapview" for all functions.- resize
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.- edge
Number of pixels to add in the edge of the segmented object when
resize = TRUE
. Defaults to 5.- plot
Plot the segmented object? Defaults to
TRUE
.
Details
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.
Examples
if (interactive()) {
img <- image_pliman("la_leaves.jpg")
seg <- image_segment_manual(img)
plot(seg$mask)
}