sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Improve normalise option with use of histogram

Open lovell opened this issue 9 years ago • 1 comments

As suggested by @jcupitt in #19.

You could also consider taking a histogram of L* and setting the range to 1% and 99%, ie. letting the top 1% and the bottom 1% over- and under-expose. This would make it less sensitive to noise and probably produce a more pleasing image in more cases.

vips_percent() does almost this, you'd swap your vips_stats() for this code: https://github.com/jcupitt/libvips/blob/master/libvips/histogram/percent.c#L82

Python-based example:

low = image.percent(1)
high = image.percent(99)
image = (image - low) * (255 / (high - low))

lovell avatar Apr 21 '15 13:04 lovell

/cc @bkw

lovell avatar Apr 21 '15 13:04 lovell

Improved via commit https://github.com/lovell/sharp/commit/55c4d8807c231bf031ec72ca1bd42a304f9b8776 available in v0.31.0.

lovell avatar Sep 05 '22 09:09 lovell