noise removal without bulitin functions
11 views (last 30 days)
Show older comments
i was wandering is there any other way to remove the salt and pepper effect with out using the built in function for matlab ?
0 Comments
Accepted Answer
Chandra Kurniawan
on 30 Nov 2011
Use 'median filtering' technique.
clear; clc;
I = imread('eight.tif');
I = imnoise(I, 'salt & pepper', 0.01);
[r c] = size(I);
Rep = zeros(r + 2, c + 2);
for x = 2 : r + 1
for y = 2 : c + 1
Rep(x,y) = I(x - 1, y - 1);
end
end
B = zeros(r, c);
for x = 1 : r
for y = 1 : c
for i = 1 : 3
for j = 1 : 3
q = x - 1; w = y -1;
array((i - 1) * 3 + j) = Rep(i + q, j + w);
end
end
B(x, y) = median(array(:));
end
end
figure, imshow(I);
figure, imshow(uint8(B));
6 Comments
kotha umeshchandra
on 6 Feb 2019
[r c] = size(I);
Rep = zeros(r + 2, c + 2);
for x = 2 : r + 1
for y = 2 : c + 1
Rep(x,y) = I(x - 1, y - 1);
end
end
EXPLAIN THIS
Image Analyst
on 7 Feb 2019
kotha, we have absolutely no idea what you're asking about. Explain what? Make a video of what?
Explain a supertrivial assignment statement in a for loop - about the simplest thing in MATLAB? Try this link
Rep is just a shifted version of I, though I don't know why you use x for the vertical/row direction and y for the horizontal/column direction which flied in the face of centuries of conventional usage of x and y as horizontal and vertical directions respectively.
More Answers (2)
Image Analyst
on 30 Nov 2011
Yes. But why? Why not just use the Salt and Pepper removal code I've posted here before?
2 Comments
Image Analyst
on 1 Dec 2011
Your image that it pulls "good" values from can be anything you want. It can be a median image, it can be an average image gotten via conv2(), or it can be any other type of noise removal filter such as bilateral, etc. but I doubt the exact kind of image will be noticeable at all in the final image because the noise is so infrequent in salt and pepper situations.
Bjorn Gustavsson
on 30 Nov 2011
Sure thing!
You can for example use the excelent http://www.mathworks.co.uk/matlabcentral/fileexchange/20645 tool to manually identify your bright and dark pixels. Maybe something like this will make it:
d = yourData;
imagesc(d)
[X,Y,B] = ginput2;
for i1 = 1:length(X)
d(Y(i1),X(i1)) = median(d(Y(i1)+[-1:1],X(i1)+[-1:1]));
end
One thing for you to keep in mind in the future (no offense intended): EVERY time someone have aske for a solution to a problem with the constrain "without bulitin" it has been about getting a homework problem solved. This is something that is not all that fun to do since it is not my task to learn their (and your?) course so that they (you?) can pass without learning...
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!