Borrar filtros
Borrar filtros

How to implement Gaussian filter spectrum?

8 visualizaciones (últimos 30 días)
Mahabba Almheiri
Mahabba Almheiri el 30 de Abr. de 2021
Comentada: Mahabba Almheiri el 3 de Mayo de 2021
I have a problem in the code. I want to plot the spectrum of the Gaussian filter but I got wrong spectrum. Can you please help me to correct the following code :
I=imread('cameraman.tif');
figure(1);
original=imshow(I)
title('original image');
SP = imnoise(I,'salt & pepper',0.1);
figure(2);
imshow(SP)
title('salt & pepper noise');
h=fspecial('gaussian',[256 256] ,10/256);
result = imfilter(SP,h,'replicate');
figure(3)
imshow(result);
title('Result sigma=10 ');
figure(4)
H = abs(fft2(h));
mesh(x,y,(H))

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Mayo de 2021
Try this:
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 long g;
format compact;
fontSize = 14;
% Read in original image.
grayImage=imread('cameraman.tif');
nexttile;
imshow(grayImage);
title('Original image');
drawnow;
% Add noise
SP = imnoise(grayImage,'salt & pepper',0.1);
nexttile;
imshow(SP)
title('With salt & pepper noise');
drawnow;
% Create blurring filter
h = fspecial('gaussian',[256 256] ,10/256);
nexttile;
imshow(h, []);
title('Gaussian Filter h');
% Blur the image.
result = imfilter(SP, h, 'replicate');
nexttile;
imshow(result);
title('Result sigma=10 ');
drawnow;
% Get the spectrum of the Gaussian blurring filter.
H = fftshift(abs(fft2(h)));
[rows, columns] = size(H);
[x, y] = meshgrid(1:columns, 1:rows);
nexttile;
surf(x,y,H, 'EdgeColor', 'none');
title('Spectrum of blurring filter.');
fprintf('Done running %s.m ...\n', mfilename);
  1 comentario
Mahabba Almheiri
Mahabba Almheiri el 3 de Mayo de 2021
Thank you so much I appreciate your effort. The code is working

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Abr. de 2021
Did you try imgaussfilt()?
  2 comentarios
Mahabba Almheiri
Mahabba Almheiri el 30 de Abr. de 2021
Yes I Im just stuck with plotting the 3D spectrum of the gaussian filter. Could you please help me in this part and thank you
DGM
DGM el 30 de Abr. de 2021
Editada: DGM el 30 de Abr. de 2021
I'm guessing you probably want to center the spectrum with fftshift()
Your x and y are undefined, so you'll either have to define them or just let them be implicit.
figure(4)
H = abs(fftshift(fft2(h)));
mesh(H)
I also don't know why you need [256 256] worth of support for a filter with a sigma of 0.0392

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by