CLAHE - Redistributing excess pixels among histogram bins In order to clip an image's histogram to a maximum value, according to the CLAHE algorithm, the excess pixels (above the clip limit) will be distributed equally among all the histogram bins (While keeping track none of the bins exceed the max limit of course).

Now, when working with (8,8) region size and distributing 13 pixels on 256 bins, the uniform added value (13/256) will be rounded to zero and so the total number of pixels in histogram will be reduced from (8,8) -> 64px to 64 - 13 = 51px.

That doesn't make sense since I'll be neglecting 13 pixels of the region.

Any tips on how to tackle this part of the algorithm?
you have to redistributed 13 pixels(# of clipped) to the histogram.

 // clip histogram
  194 
  195             if (clipLimit_ &gt; 0)
  196             {
  197                 // how many pixels were clipped
  198                 int clipped = 0;
  199                 for (int i = 0; i &lt; histSize; ++i)
  200                 {
  201                     if (tileHist[i] &gt; clipLimit_)
  202                     {
  203                         clipped += tileHist[i] - clipLimit_;
  204                         tileHist[i] = clipLimit_;
  205                     }
  206                 }
  207 
  208                 // redistribute clipped pixels
  209                 int redistBatch = clipped / histSize;
  210                 int residual = clipped - redistBatch * histSize;
  211 
  212                 for (int i = 0; i &lt; histSize; ++i)
  213                     tileHist[i] += redistBatch;
  214 
  215                 for (int i = 0; i &lt; residual; ++i)
  216                     tileHist[i]++;
  217             }