Clear Filters
Clear Filters

Black image when blurring image using LPF

2 views (last 30 days)
Suha Ismail
Suha Ismail on 15 May 2020
Edited: Image Analyst on 17 May 2020
I get black resulting image after doing LPF ??
What may be the problem !
  3 Comments
Suha Ismail
Suha Ismail on 17 May 2020
Edited: Image Analyst on 17 May 2020
clear all;
close all;
clc;
imdata=imread('peppers.jpg');
imdata=rgb2gray(imdata);
figure(1);imshow(imdata);title('gray image');
F=fft2(imdata);
Fsh=fftshift(F);
Foruier_transform=log(1+abs(Fsh));
a=0.9
x =zeros(41,41)
for col = 1:41
for row = 1:41
x(row,col)=a.^((row-1)+(col-1))*1;
end
end
F=fft2(x);
Fsh=fftshift(F);
LPF=log(1+abs(Fsh));
[rowsf colsf numberOfColorChannelsf] = size(Foruier_transform);
[rowsl colsl numberOfColorChannelsl] = size(LPF);
if rowsl ~= rowsf colsf ~= colsl LPF = imresize(LPF, [rowsf colsf]);
end
figure(2);imshow(Foruier_transform,[]);
title('Magnitude Fourier transform of an image');
figure(3);
imshow(LPF,[]);
title('Magnitude of the Frequency Response of the filter');
Convolution = Foruier_transform.*LPF;
Convolution=log(1+abs(Convolution));
figure(4);
imshow(Convolution,[]);
title('Magnitude after processing');
I=ifft2(Convolution);
I=log(1+abs(I));
figure(5);imshow(I,[]);
title('Resulting image');
Suha Ismail
Suha Ismail on 17 May 2020
Edited: Image Analyst on 17 May 2020
This is the image, though it's a standard demo image that ships with the Image Processing Toolbox.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 17 May 2020
Edited: Image Analyst on 17 May 2020
Only the (1,1) pixel (upper left corner) has any magnitude, most of the rest are less than 1/256 so they just don't show up. By the way, the code you posted doesn't run. I've fixed several errors and the code below does run.
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
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 long g;
format compact;
fontSize = 18;
rgbImage=imread('peppers.png');
imdata=rgb2gray(rgbImage);
subplot(2, 3, 1);
imshow(rgbImage);
title('Original RGB Image', 'fontSize', fontSize);
subplot(2, 3, 2);
imshow(imdata);
title('Gray Scale Image', 'fontSize', fontSize);
F=fft2(imdata);
Fsh=fftshift(F);
Fourier_transform=log(1+abs(Fsh));
a=0.9
x =zeros(41,41);
for col = 1:41
for row = 1:41
x(row,col)=a.^((row-1)+(col-1))*1;
end
end
F=fft2(x);
Fsh=fftshift(F);
LPF=log(1+abs(Fsh));
[rowsf, colsf, numberOfColorChannelsf] = size(Fourier_transform);
[rowsl, colsl, numberOfColorChannelsl] = size(LPF);
if rowsl ~= rowsf || colsf ~= colsl
LPF = imresize(LPF, [rowsf colsf]);
end
subplot(2, 3, 3);
imshow(Fourier_transform,[]);
title('Magnitude Fourier transform of an image', 'fontSize', fontSize);
subplot(2, 3, 4);
imshow(LPF,[]);
title('Magnitude of the Frequency Response of the filter', 'fontSize', fontSize);
Convolution = Fourier_transform.*LPF;
Convolution=log(1+abs(Convolution));
subplot(2, 3, 5);
imshow(Convolution,[]);
title('Magnitude after processing', 'fontSize', fontSize);
inverseFFTImage = ifft2(Convolution);
inverseFFTImage = log(1+abs(inverseFFTImage));
subplot(2, 3, 6);
imshow(inverseFFTImage,[]);
title('Resulting image', 'fontSize', fontSize);
g = gcf;
g.WindowState = 'maximized';
See my attached demos that work (different than your code).

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!