Search code examples
python-2.7image-processinghistogramcontrast

How to Calculate width of the middle 98% mass of the gray level histogram of a image


I need to calculate the contrast of an color image, so the steps that was given to me are,

  1. computed the histogram for RGB channel separately and combined it together as Histogram = histOfRedC + histOfBlueC + histOfgreenC.
  2. normalize it to unit length, as each image is of different size.
  3. The contrast quality, is equal to the width of the middle 98% mass of the histogram.

I have done the first 2 steps but unable to understand what to compute in 3rd step. Can somebody please explain me what it means?


Solution

  • Let the total mass of the histogram be M.

    Accumulate the mass in the bins, starting from index zero, until you pass 0.01 M. You get an index Q01.

    Decumulate the mass in the bins, starting from the maximum index, until you pass 0.99 M. You get an index Q99.

    These indexes are the so-called first and last percentiles. The contrast is estimated as Q99-Q01.