medfilt2 parameter coding problem

조회 수: 8 (최근 30일)
Kasy
Kasy 2013년 4월 7일
image class uint8, coding as below
>> I=imread('sample01.tif');
>> J = imnoise(I,'salt & pepper',0.02);
>> K = medfilt2(J, 'indexed',...);
it say continue entering statement, what do i need to input in order to complete the process?

채택된 답변

Image Analyst
Image Analyst 2013년 4월 7일
Pass in the window size
medianFilteredImage = medfilt2(J, 'indexed', [3 3]);
You can use whatever window size you want, but for Salt and Pepper, 3 by 3 should work as long as the noise is not really severe.
  댓글 수: 2
Kasy
Kasy 2013년 4월 7일
Does this means that for Salt and Pepper, the higher concentration of noise need larger window size in the case of median filtering? (For references)
Image Analyst
Image Analyst 2013년 4월 7일
Yes. I have a modified median filter to handle Salt and Pepper noise. Here it is (I also have a version for color images if you want):
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Read in a standard MATLAB demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'coins.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original image.
subplot(2, 2, 1);
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);
subplot(2, 2, 2);
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.
subplot(2, 2, 3);
imshow(noiseFreeImage);
title('Restored Image', 'FontSize', fontSize);

댓글을 달려면 로그인하십시오.

추가 답변 (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