morph applies various morphological operations (see Note)
to an Image object.
Usage
morph(
image,
operation,
kernel = NULL,
k_shape = "rectangle",
k_height = 5,
k_width = 5,
iterations = 1,
target = "new",
in_place = NULL
)Arguments
- image
An
Imageobject.- operation
A string corresponding to the name of a morphological operation to apply to the image (see Note).
- kernel
A binary matrix.
- k_shape
A string corresponding to the shape of the kernel for the morphological operation (see Note; default: "rectangle"). Ignored if a custom
kernelis provided.- k_height
The half-height in pixels of the kernel. Ignored if a custom
kernelis provided.- k_width
The half-width in pixels of the kernel. Ignored if a custom
kernelis provided.- iterations
The number of times the morphological operations should be applied.
- target
The location where the results should be stored. It can take 3 values:
- "new":
a new
Imageobject is created and the results are stored inside (the default).- "self":
the results are stored back into
image(faster but destructive).- An
Imageobject: the results are stored in another existing
Imageobject. This is fast and will not replace the content ofimagebut will replace that oftarget. Note that iftargetdoes not have the same dimensions, number of channels, and bit depth asimage, an error will be thrown.
- in_place
Deprecated. Use
targetinstead.
Value
If target="new", the function returns an Image
object. If target="self", the function returns nothing and modifies
image in place. If target is an Image object,
the function returns nothing and modifies that Image object in
place.
Note
There are 8 types of morphological operations that can be achieved with this function:
- "erode":
for each point, returns the minimum of the points in its neighborhood, with that neighborhood defined by the kernel.
- "dilate":
for each point, returns the maximum of the points in its neighborhood, with that neighborhood defined by the kernel.
- "open":
erosion followed by dilation.
- "close":
dilation followed by erosion.
- "gradient":
difference between the dilation and the erosion of an image.
- "tophat":
difference between an input image and its opening.
- "blackhat":
difference between the closing and its input image.
- "hitmiss":
(1) erodes the image with
kernel > 0; (2) erodes the complement of the image withkernel < 0; (3) returns the intersection (AND) of step 1 and step 2. The hit-or-miss transform is the basis of more advanced morphological operations such as thinning or pruning.
There are 3 types of predetermined kernel shapes that can be used with
this function when a custom kernel is not provided:
"rectangle"
"cross"
"ellipse"
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
balloon_eroded <- morph(balloon, "erode")