vdaanen
09-15-2006, 01:29 AM
Dear all,
I have to convolve a medical volume (256*256*256) with a filter.
Si I implement a fft-based convolution using NR fourn routine.
Reading the convolution related book chapter, I 'wraparrround' the filter to avoid border effects. This was easy in 1D and 2D.
But I do not manage to 'wraparround' my 3D filter !
The wrap method I tried results in a bad volume result (borders are spoiled !)
This is the way I wrap the 3D filter : say,for the sake of clarity, I have a 3D filter of size n*n*n (n is odd). The filter center is then (n/2, n/2, n/2);
I create a 'filter ' volume of adequat size (i.e. save same size as the medical volume and set the coefficients this way :
int dx = p_src.Width()>>1;
int dy = p_src.Height()>>1;
int dz = p_src.Depth()>>1;
int W = p_dest.Width();
int H = p_dest.Height();
int D = p_dest.Depth();
for (int z=0;z<p_src.Depth();z++)
for (int y=0;y<p_src.Height();y++)
for (int x=0;x<p_src.Width();x++)
{
int x1 = x-dx;
int y1 = y-dy;
int z1 = z-dz;
if (x1<0) x1 = W+x1;
if (y1<0) y1 = H+y1;
if (z1<0) z1 = D+z1;
p_dest(z1,y1,x1) = p_src(z,y,x);
}
the p_src and p_dest C++ components acts as NR MAT_3D
Am I doing something wrong ?
Any help is welcome !
Thanks
Vince
I have to convolve a medical volume (256*256*256) with a filter.
Si I implement a fft-based convolution using NR fourn routine.
Reading the convolution related book chapter, I 'wraparrround' the filter to avoid border effects. This was easy in 1D and 2D.
But I do not manage to 'wraparround' my 3D filter !
The wrap method I tried results in a bad volume result (borders are spoiled !)
This is the way I wrap the 3D filter : say,for the sake of clarity, I have a 3D filter of size n*n*n (n is odd). The filter center is then (n/2, n/2, n/2);
I create a 'filter ' volume of adequat size (i.e. save same size as the medical volume and set the coefficients this way :
int dx = p_src.Width()>>1;
int dy = p_src.Height()>>1;
int dz = p_src.Depth()>>1;
int W = p_dest.Width();
int H = p_dest.Height();
int D = p_dest.Depth();
for (int z=0;z<p_src.Depth();z++)
for (int y=0;y<p_src.Height();y++)
for (int x=0;x<p_src.Width();x++)
{
int x1 = x-dx;
int y1 = y-dy;
int z1 = z-dz;
if (x1<0) x1 = W+x1;
if (y1<0) y1 = H+y1;
if (z1<0) z1 = D+z1;
p_dest(z1,y1,x1) = p_src(z,y,x);
}
the p_src and p_dest C++ components acts as NR MAT_3D
Am I doing something wrong ?
Any help is welcome !
Thanks
Vince