matlab 中 FT 图像与 cuda 中的差异

发布于 2024-11-05 06:28:01 字数 932 浏览 2 评论 0原文

我正在尝试实现一个可以进行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-11-12 06:28:01

有两件事:

  • matlab 本身使用 double 进行计算。你的 CUDA 代码也在做同样的事情吗?
  • 显示的 matlab 尝试在显示值之前缩放它们,图中有一些选项可以防止这种情况。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文