MATLAB: How to calculate the median and mode of an image from the histogram

median

I have used the following code to calculate the mode
[pixelCount grayLevels] = imhist(LBP_Im);
maximum=max(pixelCount);
r=find(pixelCount==maximum);
whether this is correct to calculate the mode. Likewise I wish to know the code for calculating the median of an image

Best Answer

Why not simply use the mode and median function?
imgmode = mode(LBP_Im(:));
imgmedian = median(LBP_Im(:));
Related Question