Creating a histogram and updating the black/white points

please explain / show code.