OK, my last comment haha, I don't know what I was thinking about using "adapthisteq" function. SOLUTION:
- Add the following code to runCLAHE.m:
avgBin = NrPixels/NrBins;
graylevels is the color depth of used image. If it's 8 bit, just replace "graylevels" for 255.
- If you still having the error, change "Bin=1+LUT2(round(Image));" for "Bin=1+LUT2(round(Image+1))" to avoid pixels with 0 value.