Local variance estimation for image filtering
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi,
while implementing median filter, medfilt2(), why does medfilt2(I.^2) and medfilt2(I).^2 produce same result?
I am interested in calculating local variance , but using this methodology it is exactly 0.
How do I implement the formula correctly?
댓글 수: 0
채택된 답변
Bjorn Gustavsson
2022년 6월 21일
편집: Bjorn Gustavsson
2022년 6월 21일
You get that result because medfilt2 will select the median value of the pixel-intensities of your region, and completely discard all the other values. Therefore when you square that median value you get medfilt2(I).^2. Since x^2 is a monotnous function the element that is median of x, will also be the median element of x.^2, and that's why you always get zero's. Simple illustrating example:
x = [1 3 4 412 -3]
x2 = x.^2
Q0 = median(x)
Q1 = median(x).^2
Q2 = median(x2)
Have a look at the code of wiener2 to see how it is done with local averaging filtering. If you want a different variance-type operation you could try mad instead of std (you have to figure out how you want to handle the conversion from mad similar to the conversion between std and var). Or you could try something like:
localMedian = medfilt2(x,nhood,'symmetric');
localMEDVar = medfilt2((x-localMedian).^2,nhood,'symmetric');
% or:
localMADVar = (filter2(ones(nhood), abs(x-localMedian) ) / prod(nhood)).^2;
You have so many options to calculate some measur of the local intensity variations. Which one suits your needs best is difficult to judge. At least you now know why you get the all-zeros result from your first-stab.
HTH
댓글 수: 7
추가 답변 (1개)
Image Analyst
2022년 6월 21일
Try stdfilt if you have the Image Processing Toolbox. It gives the standard deviation in a local window.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!