matlab 中 FT 图像与 cuda 中的差异
我正在尝试实现一个可以进行 2D 卷积的 matlab 代码。
matlab 代码首先将 3x3 内核置于图像大小的填充矩阵中。我在 C++ 代码中做了同样的事情。
我已将数组和 matlab 矩阵输出到 .csv 文件并确认它们是相同的。然后我对每一个都运行前向 FFT。在 matlab 中,内核的 FT 图像看起来就像您所期望的那样 - 基本上中间很强烈,呈圆形辐射。然而,CUDA FT 图像(我在将其导入为 csv 后在 matlab 中绘制)看起来像一个椭圆形。
可能是什么原因造成的?看起来几乎好像内核没有在图像中居中,但就像我说的,我将填充的内核数据转储到 csv 中,并使用 imagesc 在 matlab 中查看它,它看起来对我来说居中,事实上是与填充的 matlab 内核完全相同。
这是我用来将内核放在填充数组中心的代码:
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 是内核一种大小的宽度,chipW 和 ChipH 是我尝试处理的图像的宽度和高度
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两件事:
Two things :