开发者

Difference between image of FT in matlab vs. cuda

I am trying to implement a matlab code that I have that does a 2D convolution.

The matlab code first centers the 3x3 kernel in a padded matrix the size of the Image. I do the same thing in my C++ code.

I have outputted my array and the matlab matrix to .csv files and confirmed that they are identical. I then run a forward FFT on each of these. In matlab,开发者_开发问答 the FT image of the kernel looks like you'd expect - basically intense in the middle, radiating out in a circle. However, the CUDA FT image (which i am drawing in matlab after importing it as a csv) looks like an oval.

What can be causing this? It looks almost as if the kernel was not centered in the image, but like I said, I dumped out the padded Kernel data to a csv and used imagesc to see it in matlab, and it looks centered to me, and in fact is the exact same as the padded matlab kernel.

This is the code I used to put my kernel in the center of my padded array:

kSize = 3;
halfl = 0.5*(kSize-1);

if(chipW%2 == 0)
    dcW = (.5*chipW) +1;
else
    dcW = round(chipW*.5);

if(chipH%2 == 0)
    dcH = (.5*chipH) +1;
else
    dcH = round(chipH*.5);

dcH--;
dcW--;


for(int i = dcH-halfl ; i <= dcH+halfl ; i++)

{
    for(int j = dcW -halfl ; j <= dcW+halfl ; j++)

    {
        h_PaddedKernel[i*chipW + j] = make_cuComplex(hp_kernel[(i-(dcH-halfl))*kSize + (j-(dcW-halfl))], 0.0);

    }


}

kSize is the width of one size of my kernel, chipW and chipH are the width and height of the image i am trying to process


Two things :

  • matlab natively computes using double. Is your CUDA code doing the same ?
  • matlab displayed tried to scale the values before displaying them, there is some option in plot to prevent this.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜