Help with salt_and_p​epper_nois​e_removal.​m

조회 수: 2 (최근 30일)
R. B.K.
R. B.K. 2016년 9월 3일
답변: Mehmet Killioglu 2016년 9월 14일
I found a matlab code to remove salt and pepper noise from a color image written by Image analyst in here . I have two question regarding to the code.
1. How to skip the first and last column and row of the image from median filter?
2.
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
What is the value of variable named noiseImage? Is it a matrix same size as the parent image but has value only where greenchannel is 0 and 255?
  댓글 수: 1
R. B.K.
R. B.K. 2016년 9월 4일
For my 1st question's solution I tried to add restriction in median filter with this method.
% Median Filter the channels:
redMF = medfilt2(redChannel(2:rows-1, 2:columns-1), [3 3]);
greenMF = medfilt2(greenChannel(2:rows-1, 2:columns-1), [3 3]);
blueMF = medfilt2(blueChannel(2:rows-1, 2:columns-1), [3 3]);
But this gives me an error:
??? Index exceeds matrix dimensions.
Error in ==> salt_and_pepper_denoising at 88
noiseFreeRed(noiseImage) = redMF(noiseImage);

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

답변 (1개)

Mehmet Killioglu
Mehmet Killioglu 2016년 9월 14일
1. You already proposed a solution but you're changing redMF's size. You should merge with redChannel's first and last columns and rows.
% Median Filter the channels:
redMF = medfilt2(redChannel(2:rows-1, 2:columns-1), [3 3]);
greenMF = medfilt2(greenChannel(2:rows-1, 2:columns-1), [3 3]);
blueMF = medfilt2(blueChannel(2:rows-1, 2:columns-1), [3 3]);
redTemp = redChannel; % Create a copy of red channel
redTemp(2:rows-1, 2:columns-1) = redMF; % Skip first and last column and row, change inside with redMF
redMF = redTemp; % Assign new redMF
greenTemp = greenChannel;
greenTemp(2:rows-1, 2:columns-1) = greenMF;
greenMF = greenTemp;
blueTemp = blueChannel;
blueTemp(2:rows-1, 2:columns-1) = blueMF;
blueMF = blueTemp;
This process will maintain image's size for next lines to prevent errors like you had.
2. noiseImage is a binary image with size of the main picture. It's 1 where greenChannel's value is 0 or 255.
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
This line will change only operates where noiseImage pixel's value is 1. This line will replace 0 or 255 value at pixel with corresponding value from median filtered image. Instead of blurring all the picture, it will only focus on the 0 and 255 values.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by