I am not sure if my output is correct regarding median filters.

3 次查看(过去 30 天)
I was asked to apply a median filter to a salt and pepper image. Upon research, I found that this code works very we. However, I am not sure if it the correct one to go for as I am very unfamiliar with this code. Especially the second line. Is it possible to explain how it works?

回答(1 个)

DGM
DGM 2023-12-1
编辑:DGM 2023-12-1
Line 2 creates an anonymous function that calculates the median of a given numeric array. It's what will process the image content within the moving window.
You can use nlfilter() if you want, but medfilt2() would probably make more sense. Still, that's just a plain median filter, not really a noise removal filter with any sort of discrimination. As the filter size gets larger or the noise density increases, the difference becomes notable.
inpict = imread('circuit.tif');
inpict = imnoise(inpict,'salt & pepper',0.2);
imshow(inpict)
A = medfilt2(inpict,[3 3]); % simple local median without noise discrimination
imshow(A) % it doesn't really get rid of noise due to the small window size
B = medfilt2(inpict,[7 7]); % so try a larger window size
imshow(B) % but that destroys details
C = amedfiltsimple(inpict); % adaptive median noise removal filter
imshow(C) % only filter the locations where there's noise

Community Treasure Hunt

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

Start Hunting!

Translated by