[Math] How to calculate median and standard deviation from histogram

statistics

I have a 256 bin histogram of an 8 bit image.

Is it possible to calculate the Median, Variance and Standard deviation of the image from the given histogram?

If yes, then what is the procedure?

Thank you.

Best Answer

You can't calculate any of them exactly because all you have is the interval of values that they belong to and not their exact values. It is the mode and not the median that is in the tallest bin. You can determine which bin the median is in and thus know the two end points of its bin are values that it falls betweem. To find where the median is you just total the number of data points in each bin starting from the left unit the get to the integer equal to (n-1)/2 when n is odd and (n+1)/2 if (n-1)/2 and (n+1)/2 are in the same bin. If (n+1)/2 is in a higher bin then (n-1)/2 you can't be sure which bin the median is in but you know it is near the boundary separating the two adjacent bins.

You can calculate grouped mean and grouped variances which may be rough approximations to the actual sample means and variances but not exact.