在 Matlab 问题中使用 FFT 的 2D 反卷积 [英] 2D Deconvolution using FFT in Matlab Problems

查看:26
本文介绍了在 Matlab 问题中使用 FFT 的 2D 反卷积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我在 matlab 中创建的图像与我也在 matlab 中定义的 2D 高斯函数进行了卷积,现在我正在尝试对结果矩阵进行解卷积,以查看是否使用 fft2 和 ifft2 命令获得了 2D 高斯函数.然而,我得到的矩阵是不正确的(据我所知).这是我迄今为止所做的代码:

I have convoluted an image I created in matlab with a 2D Gaussian function which I have also defined in matlab and now I am trying to deconvolve the resultant matrix to see if I get the 2D Gaussian function back using the fft2 and ifft2 commands. However the matrix I get as a result is incorrect (to my knowledge). Here is the code for what I have done thus far:

% 输入图像 (img) [300x300 数组] 的代码

% Code for input image (img) [300x300 array]

N = 100;
t = linspace(0,2*pi,50);
r = (N-10)/2;
circle = poly2mask(r*cos(t)+N/2+0.5, r*sin(t)+N/2+0.5,N,N);
img = repmat(circle,3,3);

% 二维高斯函数代码,c = 0 sig = 1/64 (Z) [300x300 数组]

% Code for 2D Gaussian Function with c = 0 sig = 1/64 (Z) [300x300 array]

x = linspace(-3,3,300);
y = x';
[X Y] = meshgrid(x,y);
Z = exp(-((X.^2)+(Y.^2))/(2*1/64));

% Code for 2D Convolution of img with Z (C) [599x599 array]

% Code for 2D Convolution of img with Z (C) [599x599 array]

C = conv2(img,Z);

% 我已经使用 img 和 C 的横截面轮廓向量测试了这个卷积是正确的,并且得到的 x-y 图是我对卷积的期望.

% I have tested that this convolution is correct using cross section profile vectors for img and C and the resulting x-y plots are what i expect from the convolution.

% 根据我对卷积的了解,该算法在傅立叶空间中用作乘法器,因此通过将我的输出(卷积图像)的傅立叶变换除以我的输入(im​​g),我应该得到点扩散函数(Z -2D 高斯函数)在逆傅里叶变换后通过除法应用于该结果.

% From my knowledge of convolution, the algorithm works as a multiplier in Fourier space, therefore by dividing the Fourier transform of my output (convoluted image) by my input (img) I should get back the point spread function (Z - 2D Gaussian function) after the inverse Fourier transform is applied to this result by division.

% 尝试二维反卷积的代码

% Code for attempted 2D deconvolution

Fimg = fft2(img,599,599);

添加了 % 零填充以将结果增加到 599x599 数组

% zero padding added to increase result to 599x599 array

FC = fft2(C);
R = FC/Fimg;

% 我现在收到此错误提示:警告:矩阵接近单数或严重缩放.结果可能不准确.RCOND = 2.551432e-22

% I now get this error prompt: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.551432e-22

iFR = ifft2(R);

我期待 iFR 接近 Z,但我得到了完全不同的东西.它可能是具有复数值的 Z 的近似值,但我似乎无法检查它,因为我不知道如何在 matlab 中绘制 3D 复矩阵.因此,如果有人能告诉我我的答案是正确还是错误,以及如何使这种反卷积起作用?我将不胜感激.

I'm expecting iFR to be close to Z but I'm getting something completely different. It may be an approximation of Z with complex values but I can't seem to check it since I don't know how to plot a 3D complex matrix in matlab. So if anyone can tell me whether my answer is correct or incorrect and how to get this deconvolution to work? I'd be much appreciated.

推荐答案

R = FC/Fimg 需要 R = FC./Fimg; 你需要做按元素划分.

R = FC/Fimg needs to be R = FC./Fimg; You need to do division element-wise.

这篇关于在 Matlab 问题中使用 FFT 的 2D 反卷积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆