To remove the noise using Median Filtering.

6 次查看(过去 30 天)
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);

采纳的回答

kash
kash 2013-3-1
编辑:kash 2013-3-1
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 个评论
sudha
sudha 2013-3-1
ya i got it..thank you..
If i want to apply on RGB images then wat to do???
kash
kash 2013-3-1
Accept the answer if it is correct and open a new forum,because RGB is different from gray scale filtering

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by