imager (version 0.41.2)

get.stencil: Return pixel values in a neighbourhood defined by a stencil

Description

A stencil defines a neighbourhood in an image (for example, the four nearest neighbours in a 2d image). This function centers the stencil at a certain pixel and returns the values of the neighbourhing pixels.

Usage

get.stencil(im, stencil, ...)

Arguments

im

an image

stencil

a data.frame with values dx,dy,[dz],[dcc] defining the neighbourhood

...

where to center, e.g. x = 100,y = 10,z=3,cc=1

Value

pixel values in neighbourhood

Examples

Run this code
# NOT RUN {
#The following stencil defines a neighbourhood that
#includes the next pixel to the left (delta_x = -1) and the next pixel to the right (delta_x = 1)
stencil <- data.frame(dx=c(-1,1),dy=c(0,0))
im <- as.cimg(function(x,y) x+y,w=100,h=100)
get.stencil(im,stencil,x=50,y=50)

#A larger neighbourhood that includes pixels upwards and
#downwards of center (delta_y = -1 and +1)
stencil <- stencil.cross()
im <- as.cimg(function(x,y) x,w=100,h=100)
get.stencil(im,stencil,x=5,y=50)
# }

Run the code above in your browser using DataCamp Workspace