convFFT: Convolution of 3D Arrays using the Fourier Transform

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Convolve a three-dimensinal array with another three-dimensional arry using the Fast Fourier Transform (FFT).

Usage

1
convFFT(A, B, C, FFTA = NULL)

Arguments

A

is a three-dimensional array (“the template”).

B

is a three-dimensional array (“the target”).

C

is a vector of length three (the center of “the template”).

FFTA

is the three-dimensional Fourier transform of A, this may save time when looping over multiple “targets”.

Details

The arrays A and B are transformed into the Fourier domain and multiplied together (equivalent to a convolution in the image domain across all spatial locations simultaneously).

Value

A three-dimensional array, the same dimension as the input arrays, that is the convolution of the “target” to the “template” at all spatial locations.

Author(s)

Brandon Whitcher bwhitcher@gmail.com

References

Briggs, W.L. and Henson, V.E. (1995) The DFT: An Owner's Manual for the Discrete Fourier Transform, SIAM: Philadelphia.

See Also

fft, fastTemplateMatching, shift3D

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cube <- array(0, c(20,20,1))
cube[9:12,9:12,1] <- 1
tkernel <- array(0, c(20,20,1))
tkernel[,,1] <- c(.5, 1, .5, rep(0,20-3)) %o% c(.5, 1, .5, rep(0,20-3))
tcenter <- findCenter(ifelse(tkernel > 0, TRUE, FALSE))
out <- convFFT(tkernel, cube, tcenter)
out[8:13,8:13,1]  ## text output

par(mfrow=c(2,2))  ## graphic output
image(drop(tkernel), col=oro.nifti::tim.colors(), main="Template")
image(drop(cube), col=oro.nifti::tim.colors(), main="Target")
image(drop(out), col=oro.nifti::tim.colors(), main="Output")

Example output

Loading required package: oro.nifti
oro.nifti 0.7.2
dcemriS4 0.55
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.25 0.75    1    1 0.75 0.25
[2,] 0.75 2.25    3    3 2.25 0.75
[3,] 1.00 3.00    4    4 3.00 1.00
[4,] 1.00 3.00    4    4 3.00 1.00
[5,] 0.75 2.25    3    3 2.25 0.75
[6,] 0.25 0.75    1    1 0.75 0.25

dcemriS4 documentation built on May 1, 2019, 9:23 p.m.