filter2D applies an arbitrary linear filter to an image.
Arguments
- image
An
Imageobject.- kernel
A matrix representing the convolution kernel.
- 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 may 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
For color images, the same kernel is applied to each channel of the
image. If you want to apply different kernels to each channel, first split
the image into separate channels with the split and process
them individually before merging them using the merge function.
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
k_edge_detection <- matrix(c(-1, -1, -1, -1, 8, -1, -1, -1, -1), nrow = 3)
balloon_edge <- filter2D(balloon, k_edge_detection)