一个Matlab
例子。这应该是你开始的好地方。
加载图片:
%Blur Demo
%Import image in matlab default image set.
origimage = imread('cameraman.tif');
%Plot image
figure, imagesc(origimage)
axis square
colormap gray
title('Original Image')
set(gca, 'XTick', [], 'YTick', [])
整个过程:
%Blur Kernel
ksize = 31;
kernel = zeros(ksize);
%Gaussian Blur
s = 3;
m = ksize/2;
[X, Y] = meshgrid(1:ksize);
kernel = (1/(2*pi*s^2))*exp(-((X-m).^2 + (Y-m).^2)/(2*s^2));
%Display Kernel
figure, imagesc(kernel)
axis square
title('Blur Kernel')
colormap gray
%Embed kernel in image that is size of original image
[h, w] = size(origimage);
kernelimage = zeros(h,w);
kernelimage(1:ksize, 1:ksize) = kernel;
%Perform 2D FFTs
fftimage = fft2(double(origimage));
fftkernel = fft2(kernelimage);
%Set all zero values to minimum value
fftkernel(abs(fftkernel)<1e-6) = 1e-6;
%Multiply FFTs
fftblurimage = fftimage.*fftkernel;
%Perform Inverse 2D FFT
blurimage = ifft2(fftblurimage);
%Display Blurred Image
figure, imagesc(blurimage)
axis square
title('Blurred Image')
colormap gray
set(gca, 'XTick', [], 'YTick', [])
图片前:
后图像:
请注意,由于零填充没有将内核置于中心位置,因此您会得到一个偏移量。这个答案解释了包装问题。 FFT 高斯模糊