Azzera filtri
Azzera filtri

Help with salt_and_p​epper_nois​e_removal.​m

2 visualizzazioni (ultimi 30 giorni)
R. B.K.
R. B.K. il 3 Set 2016
Risposto: Mehmet Killioglu il 14 Set 2016
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 Commento
R. B.K.
R. B.K. il 4 Set 2016
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);

Accedi per commentare.

Risposte (1)

Mehmet Killioglu
Mehmet Killioglu il 14 Set 2016
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.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by