noise removal without bulitin functions

i was wandering is there any other way to remove the salt and pepper effect with out using the built in function for matlab ?

 Réponse acceptée

Chandra Kurniawan
Chandra Kurniawan le 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 commentaires

qaiserayyy
qaiserayyy le 2 Nov 2018
could you please explain this code? thankyou
Image Analyst
Image Analyst le 2 Nov 2018
I would not recommend that method. See the modified median filter methods I've attached.
kotha umeshchandra
kotha umeshchandra le 6 Fév 2019
COULD YOU PLEASE EXPLAIN THIS CODE.
kotha umeshchandra
kotha umeshchandra le 6 Fév 2019
PLEASE EXPLAIN THAT CODE BY MAKING A VIDEO ON IT.
kotha umeshchandra
kotha umeshchandra le 6 Fév 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 le 7 Fév 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.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 30 Nov 2011

0 votes

Yes. But why? Why not just use the Salt and Pepper removal code I've posted here before?

2 commentaires

hosam
hosam le 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 le 1 Déc 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.

Connectez-vous pour commenter.

Bjorn Gustavsson
Bjorn Gustavsson le 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 commentaire

hosam
hosam le 30 Nov 2011
thank you and no offense taken bjorn :)
i just wanted to learn more about matlab that all

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by