MATLAB: Median gray level value

image analysisimage processingmammogrammedianpixels

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

Best Answer

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));
Related Question