reduce reduces a 2D Image object to a 1D
Image object by treating the image rows/columns as a set of 1D
vectors and performing the specified operation on the vectors until a single
row/column is obtained. For example, the function can be used to compute
horizontal and vertical projections of a raster image. It is similar in
spirit to the apply function in base R.
Arguments
- image
An
Imageobject.- dim
The dimension of the image which the function will be applied over. 1 indicates rows (i.e., the image is reduced to a single column), 2 indicates columns (i.e., the image is reduced to a single row).
- fun
The function to be applied. It can take the following values:
"sum"
"mean"
"max"
"min"
- target
The location where the results should be stored. It can take 2 values:
- "new":
a new
Imageobject is created and the results are stored inside (the default).- 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 thattargetmust have the same number of channels asimage, otherwise it will be coerced to the same number of channels. It must also have the same bitdepth asimageiffunis equal tomaxormin. Iffunis equal tosumormeanthe bitdepth can be larger to preserve accuracy. Ifdim=1,targetmust have 1 column and the same number of rows asimage. Ifdim=2,targetmust have 1 row and the same number of columns asimage.
Value
If target="new", the function returns an Image
object. If target is an Image object, the function
returns nothing and modifies that Image object in place.
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
sum_by_row <- reduce(balloon, 1, "sum")