Local variance estimation for image filtering
19 ビュー (過去 30 日間)
古いコメントを表示
Albert Tagtum
2022 年 6 月 21 日
コメント済み: Bjorn Gustavsson
2022 年 6 月 24 日
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1039960/image.png)
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!