1
我的主要目標是證明卷積定理起作用(只是提醒一下:卷積定理意味着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我試圖清除我的問題。請再次查看。 – Gilad
@Androidy - 仍然不清楚。將你的'im'和'b'轉換成雙打。 – Shai