An histogram equalization is a way to enhance local contrasts in an image by using an histogram of its values. I explain the idea in this blog post Here I use d3.scale.quantile for bucketing, inspired by these nice algorithms explained here.
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js