Histograms & contrast stretching
Digital Image ProcessingWhat I built
I wrote histogram builders from scratch (any bin count, optional masks) and compared a brute-force double loop against indexing by intensity ÷ bin width, which was dramatically faster. Then I tried to rescue a very dark night photo with contrast stretching.
The math
What I found
Plain min–max stretching did almost nothing: a handful of bright lights already sat near 255, so the extremes were pinned at both ends. Ignoring the darkest and brightest 1–5% of pixels before stretching is what finally pulled detail out of the shadows.
Read the Python on GitHub ↗