imager (version 0.42.7)

patchstat: Return image patch summary

Description

Patches are rectangular image regions centered at cx,cy with width wx and height wy. This function provides a fast way of extracting a statistic over image patches (for example, their mean). Supported functions: sum,mean,min,max,median,var,sd, or any valid CImg expression. WARNINGS: - values outside of the image region are considered to be 0. - widths and heights should be odd integers (they're rounded up otherwise).

Usage

patchstat(im, expr, cx, cy, wx, wy)

Arguments

im

an image

expr

statistic to extract. a string, either one of the usual statistics like "mean","median", or a CImg expression.

cx

vector of x coordinates for patch centers

cy

vector of y coordinates for patch centers

wx

vector of patch widths (or single value)

wy

vector of patch heights (or single value)

Value

a numeric vector

See Also

extract_patches

Examples

Run this code
# NOT RUN {
im <- grayscale(boats)
#Mean of an image patch centered at (10,10) of size 3x3
patchstat(im,'mean',10,10,3,3)
#Mean of image patches centered at (10,10) and (20,4) of size 2x2
patchstat(im,'mean',c(10,20),c(10,4),5,5)
#Sample 10 random positions
ptch <- pixel.grid(im) %>% dplyr::sample_n(10)
#Compute median patch value
with(ptch,patchstat(im,'median',x,y,3,3))
# }

Run the code above in your browser using DataLab