Session Ready
Exercise

Equalizing an image histogram

Histogram equalization is an image processing procedure that reassigns image pixel intensities. The basic idea is to use interpolation to map the original CDF of pixel intensities to a CDF that is almost a straight line. In essence, the pixel intensities are spread out and this has the practical effect of making a sharper, contrast-enhanced image. This is particularly useful in astronomy and medical imaging to help us see more features.

For this exercise, you will again work with the grayscale image of Hawkes Bay, New Zealand (originally by Phillip Capper, modified by User:Konstable, via Wikimedia Commons, CC BY 2.0). Notice the sample code produces the same plot as the previous exercise. Your task is to modify the code from the previous exercise to plot the new equalized image as well as its PDF and CDF.

  • The arrays image and pixels are extracted for you in advance.
  • The CDF of the original image is computed using plt.hist().
  • Notice an array new_pixels is created for you that interpolates new pixel values using the original image CDF.
Instructions 1/2
undefined XP
  • 1
  • 2

Plot the new equalized image.

  • Use the NumPy array method .reshape() to create a 2-D array new_image from the 1-D array new_pixels.

    • The resulting new_image should have the same shape as image.shape, which can be accomplished by passing this as the argument to .reshape().
  • Display new_image with a 'gray' color map to display the sharper, equalized image.