Error in sharpening image.How can I solve it?
Afficher commentaires plus anciens
I am using MatLab R2018a and i want to sharpen a x-ray image.So far I convert my image to frequency domain and filter using high pass filtering.Now I want to sharpen my image.But it give me an error when sharpening.Here is my code.I understand that I want to convert this image in two rgb or gray or binary form to sharpen image.But I don't know what is the correct form of the image.I am greatful if you can help me to find a solution.
close all;
clear all;
clc;
img = imread('003.bmp');
img2 = imnoise(img,'salt & pepper',0.025);
img3 = img2;
for c = 1 : 3
img3(:, :, c) = medfilt2(img2(:, :, c), [5, 5]);%add median filter
end
I=rgb2gray(img3); % convert the image to grey
A = fft2(double(I)); % compute FFT of the grey image
A1=fftshift(A); % frequency scaling
% Gaussian Filter Response Calculation
[M, N]=size(A); % image size
R=15; % filter size parameter
X=0:N-1;
Y=0:M-1;
[X, Y]=meshgrid(X,Y);
Cx=0.3*N;
Cy=0.3*M;
Lo=exp(-((X-Cx).^2+(Y-Cy).^2)./(2*R).^2);
Hi=1-Lo; % High pass filter=1-low pass filter
% Filtered image=ifft(filter response*fft(original image))
J=A1.*Lo;
J1=ifftshift(J);
B1=ifft2(J1);
K=A1.*Hi;
K1=ifftshift(K);
B2=ifft2(K1);
%----visualizing the results----------------------------------------------
figure(1)
subplot(2,2,1)
imshow(I);colormap gray
title('Original image')
subplot(2,2,2)
imshow(img3);colormap gray
title('Median Filterd image')
subplot(2,2,3)
imshow(abs(A1),[-12 300000]), colormap gray
title('fft of original image')
% figure(3)
% imshow(abs(B1),[12 290]), colormap gray
% title('low pass filtered image','fontsize',14)
subplot(2,2,4)
imshow(abs(B2),[12 290]), colormap gray
title('High pass filtered image')
figure(2)
subplot(1,3,1);
imshow(img)
title('Original image')
subplot(1,3,2);
imshow(img3)
title('Median filtered image')
% subplot(2, 2, 3);
% imshow(abs(B1),[12 290]), colormap gray
% title('low pass filtered image','fontsize',14)
subplot(1,3,3);
imshow(abs(B2),[12 290])
title('High pass filtered image');
% b = imsharpen(B2);
% figure(6);
% imshow(b)
% title('Sharpened Image');
2 commentaires
Walter Roberson
le 23 Oct 2018
What is the error message?
Nayana R
le 23 Oct 2018
Modifié(e) : Walter Roberson
le 23 Oct 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!