필터 지우기
필터 지우기

To remove the noise using Median Filtering.

조회 수: 4 (최근 30일)
sudha
sudha 2013년 3월 1일
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에서 Digital Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by