Effacer les filtres
Effacer les filtres

Local variance estimation for image filtering

19 vues (au cours des 30 derniers jours)
Albert Tagtum
Albert Tagtum le 21 Juin 2022
Commenté : Bjorn Gustavsson le 24 Juin 2022
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?

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 21 Juin 2022
Modifié(e) : Bjorn Gustavsson le 21 Juin 2022
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 commentaires
Albert Tagtum
Albert Tagtum le 24 Juin 2022
Thank you Bjorn for very detailed answers and proposals of solutions!
Much appreciated.
Bjorn Gustavsson
Bjorn Gustavsson le 24 Juin 2022
My pleasure, happy that it helped.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 21 Juin 2022
Try stdfilt if you have the Image Processing Toolbox. It gives the standard deviation in a local window.

Community Treasure Hunt

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

Start Hunting!

Translated by