Median gray level value

3 vues (au cours des 30 derniers jours)
Faraz
Faraz le 25 Nov 2011
Hi there,
How can I find the median gray level of non-zero valued pixels in an image?
I am working on mammograms that have lot of zero valued pixels, but it dosent matter.
Thanks

Réponse acceptée

Sven
Sven le 25 Nov 2011
Hi Faraz, you can simply make a mask of the pixels you don't want to include, then take the median of all the others:
Im = randi(10,512,512) - 1; % Sample image with some 0s
zeroMask = Im==0; % Mask of 0s
medValue = median(Im(~zeroMask)) % Median of the rest
Or, in one command:
medValue = median(Im(Im>0));
  1 commentaire
Faraz
Faraz le 25 Nov 2011
Thanks Sven

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 25 Nov 2011
Use logical indexing. See this demo:
% Generate some sample data.
A = [1 2 4 4; 3 0 6 6; 5 0 8 8; 5 6 8 0]
% Just FYI, let's see what we're going to use
AZ = A > 0
% Normal median value
medianValue = median(A(:))
% Now get the median of where A>0
medianValue = median(A(A>0))
  1 commentaire
Faraz
Faraz le 25 Nov 2011
Thanks Image analyst

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by