applying Butterworth filters on salt and paper image
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Why we are not getting the filterd image? whats the error in the 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');
% MATLAB Code | Butterworth Low Pass Filter
% Saving the size of the input_image in pixels-
% M : no of rows (height of the image)
% N : no of columns (width of the image)
[M, N] = size(I);
% Getting Fourier Transform of the input_image
% using MATLAB library function fft2 (2D fast fourier transform)
FT_img = fft2(double(I));
% Assign the order value
n = 2; % one can change this value accordingly
% Assign Cut-off Frequency
D0 = 50; % one can change this value accordingly
% Designing filter
u = 0:(M-1);
v = 0:(N-1);
idx = find(u > M/2);
u(idx) = u(idx) - M;
idy = find(v > N/2);
v(idy) = v(idy) - N;
% MATLAB library function meshgrid(v, u) returns
% 2D grid which contains the coordinates of vectors
% v and u. Matrix V with each row is a copy of v
% and matrix U with each column is a copy of u
[V, U] = meshgrid(v, u);
% Calculating Euclidean Distance
D = sqrt(U.^2 + V.^2);
% determining the filtering mask
H = 1./(1 + (D./D0).^(2*n));
% Convolution between the Fourier Transformed
% image and the mask
G = H.*FT_img;
% Getting the resultant image by Inverse Fourier Transform
% of the convoluted image using MATLAB library function
% ifft2 (2D inverse fast fourier transform)
output_image = real(ifft2(double(G)));
% Displaying Input Image and Output Image
% Dispaly result
figure(3);
imshow(output_image);
title(' Result D0=50 ');
0 Kommentare
Antworten (1)
Hrishikesh Borate
am 23 Apr. 2021
Hi,
It’s my understanding that you are trying to apply Butterworth filter on an image with salt and pepper noise, and you are unable to observe the desired output image.
This is because the output image is a gray scale image, it’s data type is double and as the display range is not defined, the default display range is used, which is [0,1].
One way to solve this, is to replace
imshow(output_image);
with
imshow(output_image,[]);
The empty matrix ([ ]) sets the default range parameter to [min(output_image(:)) max(output_image(:))].
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!