【发布时间】:2012-12-11 03:34:00
【问题描述】:
我的主要目标是证明卷积定理有效(只是提醒一下:卷积定理意味着idft(dft(im) .* dft(mask)) = conv(im, mask))。我正在尝试对其进行编程。
这是我的代码:
function displayTransform( im )
% This routine displays the Fourier spectrum of an image.
%
% Input: im - a grayscale image (values in [0,255])
%
% Method: Computes the Fourier transform of im and displays its spectrum,
% (if F(u,v) = a+ib, displays sqrt(a^2+b^2)).
% Uses display techniques for visualization: log, and stretch values to full range,
% cyclic shift DC to center (use fftshift).
% Use showImage to display and fft2 to apply transform.
%displays the image in grayscale in the Frequency domain
imfft = fft2(im);
imagesc(log(abs(fftshift(imfft))+1)), colormap(gray);
% building mask and padding it with Zeros in order to create same size mask
b = 1/16*[1 1 1 1;1 1 1 1; 1 1 1 1; 1 1 1 1];
paddedB = padarray(b, [floor(size(im,1)/2)-2 floor(size(im,2)/2)-2]);
paddedB = fft2(paddedB);
C = imfft.*paddedB;
resIFFT = ifft2(C);
%reguler convolution
resConv = conv2(im,b);
showImage(resConv);
end
我想比较resIFFT 和resConv。我想我错过了一些铸造,因为如果我使用铸造来加倍,我会让矩阵中的数字更接近另一个。
也许我在铸造或填充的地方有一些错误?
【问题讨论】:
-
我在这里没有看到问题。我所看到的只是代码转储和您“缺少某些东西”的声明。嗯,是的,你可能是,我们也是 - 即清楚地描述你的问题。
-
@IlmariKaronen 我试图澄清我的问题。请再次查看。
-
@Androidy - 仍然不清楚。将您的
im和b转换为双精度。 -
@Shai 我想在 matlab 中编写一个简单的演示程序来证明卷积定理有效。我的想法是拍摄一张与面具 b 进行卷积的图像。在另一边 ifft2(fft2(im).*fft2(b))。然后比较两个结果的值。但是我的问题是我得到了两个不同的矩阵。
-
是否可以使用两个不同长度的向量
标签: matlab convolution dft