noise removal without bulitin functions

11 views (last 30 days)
i was wandering is there any other way to remove the salt and pepper effect with out using the built in function for matlab ?

Accepted Answer

Chandra Kurniawan
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
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
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.

Sign in to comment.

More Answers (2)

Image Analyst
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
hosam
hosam on 30 Nov 2011
it because i want to see if i can remove the salt and pepper effect without using median effect :)
and i am sorry i didn't know you posted about it already gonna check it out now
Image Analyst
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.

Sign in to comment.


Bjorn Gustavsson
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...
  1 Comment
hosam
hosam on 30 Nov 2011
thank you and no offense taken bjorn :)
i just wanted to learn more about matlab that all

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!