Error using .* Integers can only be combined with integers of the same class, or scalar doubles.

4 views (last 30 days)
clc
clear all
close all
lena = imread('eight.tif');
A = fftshift(fft2(lena));
S = imnoise(lena,'Gaussian',0,1);
% define spatial filters
h_gauss= fspecial('gaussian', 15, 1.0);
% results after spatial filtering
lena_h_gauss = imfilter(S, h_gauss, 'replicate');
% fourier transformed filters
H_gauss = fftshift(fft2(lena_h_gauss));
% filtering in frequency domain
%Lena_H_gauss = S .* H_gauss;
w= (abs(H_gauss))
size(S)
size(w)
lena_H_gauss = S.* w;
lena_H_gauss = ifft2(ifftshift(lena_H_gauss));
% print results
subplot(3,3,1); imshow(lena); title('Original Image');
subplot(3,3,2); imshow(lena_h_gauss); title('Gauss-Filtered Image');
subplot(3,3,3); imshow(real(log(double(lena))), []); title('FT (Original Image)');
subplot(3,3,4); imshow(real(log(double(H_gauss))), []); title('FT (Gauss Filter)');
subplot(3,3,5); imshow(lena_H_gauss); title('Result FT Gauss');

Accepted Answer

Image Analyst
Image Analyst on 8 Sep 2017
I think this is really what you were trying to do:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
% Get noise-free original gray scale image.
grayImage = imread('eight.tif');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
% Create noisy image from it.
noisyImage = imnoise(im2double(grayImage), 'Gaussian', 0, 0.01);
% Define spatial filters as a 15x15 window.
gaussianSpatialFilter = fspecial('gaussian', 15, 1.0);
% Do a filter by blurring with a Gaussian kernel in the spatial domain:
spatialDomainFilteredImage = imfilter(noisyImage, gaussianSpatialFilter, 'replicate');
% Display results:
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;
% Define frequency domain filter the same size as the image.
gaussianFreqFilter = fspecial('gaussian', [rows, columns], 0.2*rows); % Keep the low frequencies.
% gaussianFreqFilter = ones(rows, columns); % Keep all frequencies.
% Fourier transform the noisy image.
freqDomainImage = fftshift(fft2(noisyImage));
% Now do filtering in the frequency domain
filteredFreqDomain = freqDomainImage .* gaussianFreqFilter;
% Now transform back to spatial domain:
spatialImage = real(ifft2(ifftshift(filteredFreqDomain)));
% Display results:
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 up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!