To remove the noise using Median Filtering.

8 vues (au cours des 30 derniers jours)
sudha
sudha le 1 Mar 2013
This is my code for median filtering..i have 5 image in "class2" folder. Am able to display only the 1st image of original & noise image. Its not displaying the resorted image, as well the other remaining 4 images..can anyone help me out to correct the error..
myFolder='E:\MRP\accuracy\class2';
m=input('Type the Number of Images to Process:');
for k = 1:m
jpgFilename = sprintf('%d.jpg', k);
fullFileName = fullfile(myFolder, jpgFilename);
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original image.
figure,imshow(grayImage);
title('Original Gray Scale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Generate a noisy image with salt and pepper noise.
noisyImage = imnoise(grayImage,'salt & pepper', 0.05);
figure,imshow(noisyImage);
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
% Median Filter the image:
medianFilteredImage = medfilt2(noisyImage, [3 3]);
% Find the noise. It will have a gray level of either 0 or 255.
noiseImage = (noisyImage == 0 | noisyImage == 255);
% Get rid of the noise by replacing with median.
noiseFreeImage = noisyImage; % Initialize
noiseFreeImage(noiseImage) = medianFilteredImage(noiseImage); % Replace.
% Display the image.
figure,imshow(noiseFreeImage);
title('Restored Image', 'FontSize', fontSize);

Réponse acceptée

kash
kash le 1 Mar 2013
Modifié(e) : kash le 1 Mar 2013
EDITED
clc
clear all
myFolder='E:\MRP\accuracy\class2'
m=input('Type the Number of Images to Process:');
for k = 1:m
jpgFilename = sprintf('%d.jpg', k);
fullFileName = fullfile(myFolder, jpgFilename);
% end
grayImage = imread(fullFileName))
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands==3
grayImage=rgb2gray(grayImage);
else
grayImage=grayImage;
end
% Display the original image.
figure('name','grayImage','numbertitle','off');imshow(grayImage);
fontSize=10
% Enlarge figure to full screen.
% Generate a noisy image with salt and pepper noise.
noisyImage = imnoise(grayImage,'salt & pepper', 0.05);
figure('name','noisyImage','numbertitle','off');imshow(noisyImage);
% Median Filter the image:
medianFilteredImage = medfilt2(noisyImage, [3 3]);
% Find the noise. It will have a gray level of either 0 or 255.
noiseImage = (noisyImage == 0 | noisyImage == 255);
% Get rid of the noise by replacing with median.
noiseFreeImage = noisyImage; % Initialize
noiseFreeImage(noiseImage) = medianFilteredImage(noiseImage); % Replace.
% Display the image.
figure('name','Restored Image','numbertitle','off');imshow(noiseFreeImage);
% figure,imshow(noiseFreeImage);
% title('Restored Image', 'FontSize', fontSize);
end
  6 commentaires
sudha
sudha le 1 Mar 2013
ya i got it..thank you..
If i want to apply on RGB images then wat to do???
kash
kash le 1 Mar 2013
Accept the answer if it is correct and open a new forum,because RGB is different from gray scale filtering

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by