Wednesday, September 19, 2007

2D and 3D convolution

Wouter Weeda needed to do some smoothing on fMR images to have a quick way for determining the likely number of active regions for his ARF (“Activated Regions Fitting”) method. I remembered I once did an FFT implementation of 2D and 3D convolution. Can't exactly remember what for, but I suppose they are pretty useful. They were modeled after the base package convolve function, so the documentation would be similar to convolve's documentation. You can download them here: An example of their use:
# random 2D field
x = matrix(rnorm(100*100), 100)

# Gaussian filter kernel
n=9
w=3
support = seq(-w,w,len=n)
filter = outer(support,support,function(a,b) dnorm(a)*dnorm(b))

# depict original and convolved version
layout(t(1:2))
image(x)
image(convolve2d(x, filter, type='filter'))
The result is as follows:

Labels: , , , ,

0 Comments:

Post a Comment

<< Home