Skip to content

AFNI and NIfTI Server for NIMH/NIH/PHS/DHHS/USA/Earth

Sections
Personal tools
You are here: Home » SSCC » rwcox's Home » Cox's Brain Blog » Gaussian Blurring with a mask

Gaussian Blurring with a mask Gaussian Blurring with a mask

Document Actions
Submitted by bpittman. on 2005-12-28 09:46.
Gaussian blurring, as in AFNI's edt_blur.c functions, is easily implemented using FFTs and/or convolution. But if there is a mask involved, and we don't want to include data from outside the mask, what to do?

The obvious thing to do is to treat Gaussian blurring as the solution to the heat/diffusion PDE in boundaryless space. We then add boundaries. Neumann boundary conditions are appropriate, since otherwise the edge values are fixed and unsmoothed. If we think of diffusion as an averaging over the values visited by an ensemble of Brownian particles, then Neumann BCs one the PDE come from assuming reflecting BCs for the particle paths (Dirichlet come from assuming absorbing BCs).

In the discrete world of image processing, we deal with random walks, not Brownian motions. One way is to implement diffusion is with an Euler step using a finite-difference stencil. In 1D space, the stencil is:
  1   -2   1
so that the evolution of some grid-function u() is
  u(n,t+1) = u(n,t) + ε [ u(n-1,t) - 2⋅u(n,t) + u(n-1,t) ]
  u(n,t+1) = (1-2ε)u(n,t) + εu(n-1,t) + εu(n+1,t)
where ε is some small quantity, n is the grid index, and t is some artificial 'time'. However, at a mask boundary, we don't want to include the n-1 or n+1 value. The Neumann BC says that when a particle leaves the boundary, it is reflected back. So if u(n-1,t) is the value we don't want to include, but u(n+1,t) is OK to keep, then we modify the evolution at the nth grid point to be
  u(n,t+1) = (1-ε)u(n,t) + εu(n+1,t)
since the u(n-1,t) 'exploration' by the wandering particle is reflected back to u(n,t). (Implicitly, this is setting the boundary half-way between the n-1 and n grid points.)

In higher dimensions, we modify the stencil similarly, taking the weights that would have come from the non-central points that are outside the mask, and lumping those back into the central point. Then, to get more than a tiny amount of blurring, we iterate the process repeatedly. Obviously, this will not be possible to do in FFT space. Also obviously, this will be a slow way to get a lot of blurring, and is really only useful when a limited amount of blurring is required. That is the case for what we need this procedure for, in the AFNI program 3danisosmooth.


Gaussian blurring with a mask

Posted by dglen at 2006-02-13 16:34
3danisosmooth supports masks but does not use this for the gaussian blurring part of the program yet. Bob mentions this problem because the idea was to remove any outside effect of areas outside a mask. The rest of 3danisosmooth handles masks differently than described here. It sets outside voxels to the value of the edge voxel that is at the center of the spatial kernel (rather than reflecting).

The current gaussian blurring routine doesn't take a mask as an option. The program already reflects back voxel values at edges of the volume for the first reflected voxel only and zeros after that. I think it should be relatively simple to add the mask option to this function or add a new function. The FFT method could be done too if you break up into various line segments in each direction, but there's no current need, and the spatial method is faster for small blurring.
Blog
« April 2024 »
Su Mo Tu We Th Fr Sa
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
 
 

Powered by Plone

This site conforms to the following standards: