Median filter for rgb images
조회 수: 11 (최근 30일)
이전 댓글 표시
For 2d images for performing median filtering we have inbuilt function medfilt2
is there any function for performing median filtering rgb images
댓글 수: 0
채택된 답변
Image Analyst
2012년 9월 8일
The help is a good place to look for this information. If you type in median there, you'll see that you can use medfilt2() in the Image Processing Toolbox. I have a demo that uses medfilt2() to remove salt and pepper noise in RGB images, if you want to see it.
댓글 수: 9
Image Analyst
2017년 7월 13일
Your salt and pepper noise is not the same in every channel if you do it separately. So while a particular (row,column) might be 255 for red, you may not have it also be 255 for green and blue. Thus your "salt" will be colored salt, not pure white salt.
I believe you can use psnr either way, either on each color channel separately, or on the RGB image together, in which case I think it gives you one overall number rather than 3 psnrs.
추가 답변 (3개)
Jürgen
2012년 9월 8일
Hey,
I would perform it on one of the channels depinding on which features afterwards you want to extract, or perform it on each channel.
or first transform to an other color space
regardsJ
댓글 수: 0
Noor Abbas
2016년 10월 16일
Hello every one, Could you please help with code for adaptive medium filter. Thanks
댓글 수: 3
Noor Abbas
2017년 9월 12일
thanks for your consideration(Image Analyst) I would like to use the adaptive median filter with mammogram images
Image Analyst
2017년 9월 12일
So start a new question and attach your/my code, and your image, and explain what help you need, such as why it's not working the way you like, or some error that your code (after you modified mine) is throwing.
DGM
2023년 1월 9일
편집: DGM
2023년 1월 9일
If you want something akin to medfilt2() that works with multichannel images, then you have a few options.
% an RGB uint8 image
inpict = imread('peppers.png');
inpict = imresize(inpict,0.5);
% window size
ws = [11 11];
% using nlfilter() (slow)
sz = size(inpict);
op1 = zeros(sz,class(inpict));
for c = 1:size(inpict,3)
op1(:,:,c) = nlfilter(inpict(:,:,c),ws,@(x) median(x(:)));
end
% using medfilt2()
sz = size(inpict);
op2 = zeros(sz,class(inpict));
for c = 1:size(inpict,3)
op2(:,:,c) = medfilt2(inpict(:,:,c),ws,'symmetric');
end
% using medfilt3() (R2016b or newer)
op3 = medfilt3(inpict,[ws 1]);
% using MIMT nhfilter()
op4 = nhfilter(inpict,'median',ws);
Note that the last three examples have identical output for the specified options, whereas nlfilter() has no padding options, and will exhibit edge effects (pay attention to the corners). IPT medfilt2() will behave similarly with the default padding option.
Using nlfilter() for something simple like a median filter isn't really practical in comparison, but it is an option.
The first three tools are from the Image Processing Toolbox, whereas nhfilter() is from MIMT. While nhfilter() does not require IPT, it will run much faster if IPT is installed.
If instead of what OP asked, you want a noise removal filter instead, you have a few options. You can either reimplement the whole thing, or you can find one. MIMT has two options.
% an RGB uint8 image
inpict0 = imread('peppers.png');
inpict0 = imresize(inpict0,0.5);
% add noise
inpict = imnoise(inpict0,'salt & pepper',0.2);
% use a fixed-window median noise removal filter (similar to IA's demo)
op1 = fmedfilt(inpict,11);
% use an adaptive median noise removal filter
op2 = amedfilt(inpict,5);
See also:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Adaptive Filters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!