Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

correlate

Correlation/convolution of image by filter


Description

The correlation of image im by filter flt is defined as: res(x,y,z) = sum_{i,j,k} im(x + i,y + j,z + k)*flt(i,j,k). The convolution of an image img by filter flt is defined to be: res(x,y,z) = sum_{i,j,k} img(x-i,y-j,z-k)*flt(i,j,k)

Usage

correlate(im, filter, dirichlet = TRUE, normalise = FALSE)

convolve(im, filter, dirichlet = TRUE, normalise = FALSE)

Arguments

im

an image

filter

the correlation kernel.

dirichlet

boundary condition. Dirichlet if true, Neumann if false (default TRUE, Dirichlet)

normalise

compute a normalised correlation (ie. local cosine similarity)

Functions

  • convolve: convolve image with filter

Examples

#Edge filter
filter <- as.cimg(function(x,y) sign(x-5),10,10) 
layout(t(1:2))
#Convolution vs. correlation 
correlate(boats,filter) %>% plot(main="Correlation")
convolve(boats,filter) %>% plot(main="Convolution")

imager

Image Processing Library Based on 'CImg'

v0.42.10
LGPL-3
Authors
Simon Barthelme [aut], David Tschumperle [ctb], Jan Wijffels [ctb], Haz Edine Assemlal [ctb], Shota Ochi [cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.