Help with salt_and_pepper_noise_removal.m
Show older comments
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 Comment
R. B.K.
on 4 Sep 2016
Answers (1)
Mehmet Killioglu
on 14 Sep 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.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!