clc;
close all;
clear;
workspace;
format short g;
format compact;
fontSize = 15;
grayImage = imread('eight.tif');
[rows, columns, numberOfColorChannels] = size(grayImage);
noisyImage = imnoise(im2double(grayImage), 'Gaussian', 0, 0.01);
gaussianSpatialFilter = fspecial('gaussian', 15, 1.0);
spatialDomainFilteredImage = imfilter(noisyImage, gaussianSpatialFilter, 'replicate');
subplot(2, 4, 1); imshow(grayImage, []); title('Original Image', 'FontSize', fontSize); axis on;
subplot(2, 4, 2); imshow(noisyImage, []); title('Noisy Image', 'FontSize', fontSize); axis on;
subplot(2, 4, 3); imshow(gaussianSpatialFilter, []); title('Blur Kernel', 'FontSize', fontSize); axis on;
subplot(2, 4, 4); imshow(spatialDomainFilteredImage, []); title('Image filtered with Gaussian in the spatial domain', 'FontSize', fontSize); axis on;
gaussianFreqFilter = fspecial('gaussian', [rows, columns], 0.2*rows);
freqDomainImage = fftshift(fft2(noisyImage));
filteredFreqDomain = freqDomainImage .* gaussianFreqFilter;
spatialImage = real(ifft2(ifftshift(filteredFreqDomain)));
subplot(2, 4, 5); imshow(gaussianFreqFilter, []); title('Freq Domain Filter', 'FontSize', fontSize); axis on;
subplot(2, 4, 6); imshow(log(abs(freqDomainImage)), []); title('Original Freq Domain Image', 'FontSize', fontSize); axis on;
subplot(2, 4, 7); imshow(log(abs(filteredFreqDomain)), []); title('Filtered Freq Domain Image', 'FontSize', fontSize); axis on;
subplot(2, 4, 8); imshow(spatialImage, []); title('Back in Spatial Domain', 'FontSize', fontSize); axis on;
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Best Answer