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?
Reference article of the algorithm (Pages 365366):
http://www.cs.unc.edu/Research/MIDAG/pu ... ations.pdf
CLAHE  Redistributing excess pixels among histogram bins

 Posts: 13034
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: CLAHE  Redistributing excess pixels among histogram bins
Thanks for the link.
The question is: does it matter much that the count is reduced by 13? I doubt that it does, but I've never tried with such small images, where there are more buckets than pixels. If it bothers you, you could add one to some buckets and zero to others, so the count remains the same.
Or you could store counts as floatingpoint numbers so the question doesn't arise. If 13 pixels are to be redistributed among 256 buckets, each count will increase by 13/256 = 0.0508. This seems the obvious solution.
In my implementation of CLAHE, bucket counts are integers, and the total count across all the buckets varies with each iteration. See http://im.snibgo.com/eqlimit.htm
The question is: does it matter much that the count is reduced by 13? I doubt that it does, but I've never tried with such small images, where there are more buckets than pixels. If it bothers you, you could add one to some buckets and zero to others, so the count remains the same.
Or you could store counts as floatingpoint numbers so the question doesn't arise. If 13 pixels are to be redistributed among 256 buckets, each count will increase by 13/256 = 0.0508. This seems the obvious solution.
In my implementation of CLAHE, bucket counts are integers, and the total count across all the buckets varies with each iteration. See http://im.snibgo.com/eqlimit.htm
snibgo's IM pages: im.snibgo.com
Re: CLAHE  Redistributing excess pixels among histogram bins
Thank you for sharing your implementation.
I've decided, in the case of more buckets than pixels, to distribute the one pixel to some buckets and others zero.
In the example of 13 pixels excess pixels, then 256 / 13 = 19.7 ~ 19, so one pixels will be added on every 19th bucket.
I've decided, in the case of more buckets than pixels, to distribute the one pixel to some buckets and others zero.
In the example of 13 pixels excess pixels, then 256 / 13 = 19.7 ~ 19, so one pixels will be added on every 19th bucket.