I have jpegs on a webpage. I would like to perform client-side equalization (contrast stretching) on these images without browser plugins. I would also accept a solution for histogram equalization.
I currently use a poor approximation with a combination of two CSS filters (-webkit-filter: contrast() brightness()).
I am hoping to be able to accomplish this with something like processing.js or pixastic.
I do not know of a library that contains an efficient histogram equalization method without introducing too much overhead. However, you could lump together your own implementation pretty fast.
You could start with this very optimized histogram equalization algorithm for 8-bit single channel images taken from js-objectdetect based on back-projection:
You could apply this method to the individual channels of an RGB image independently, but this will produce undesired results. Wikipedia describes a better method:
You then need an image and a canvas element:
How to perform RGBA <-> HSL conversation in Javascript is described here.
Keep in mind that there are 511 possible luminance values for an 8-bit RGB image using the referenced conversion method. Your histogram should then be an array of 511 instead of 256 values. You also would have to make sure that your luminance values are in the correct range, possibly by multiplying with 510 or by modifying the conversion method: