Part 2: Contrast Enhancement

Contrast enhancements, sometimes called radiometric enchancements, are a class of image operations that modify the frequency distribution of image values in an effort optimize the contrast and overall brightness to highlight particular ranges of digital numbers (DNs). The goal of any image enchancement operation is to improve the visualization and interpretation of the data. Contrast ehancement is also an important step in the process of generating a visually appealing colour composite image. If you recall the Balance Contrast Enhancement option that we encountered when we used the CreateColourComposite tool, it was performing a type of contrast adjustment internally to ensure that none of the input bands were proportionally brighter than the others.

There are many reasons why the contrast of satellite imagery may be poorly suited to interpretation, including atmospheric scattering and the presence of haze or cloud cover. The band1 image from the previous section is an example of how cloud cover can signficantly degrade image quality. In this section of the lab assignment, we will try to improve image radiometric quality through the use of various contrast enchancement tools.

WhiteboxTools offers at least six common contrast enchanment methods for use with single-bands of multispectral imagery including:

  1. GaussianContrastStretch
  2. HistogramEqualization
  3. MinMaxContrastStretch
  4. PercentageContrastStretch
  5. SigmoidalContrastStretch
  6. StandardDeviationContrastStretch

Each of these techniques for performing contrast enchancements offer various advantages and disadvantages that make them applicable under differing image conditions.

First, let's explore the use of the GaussianContrastStretch tool. Using VS Code, create a Python script in your Lab 2 folder (which must also contain the WBT folder with the latest version of the WhiteboxTools library) called contrast.py. Copy the following code into your script file and run it using the VS Code terminal. Be sure to modify the wbt.work_dir to point to the folder containing your lab data.

from WBT.whitebox_tools import WhiteboxTools

def main():
    wbt = WhiteboxTools()  # Initialize WhiteboxTools
    wbt.work_dir = "/path/to/your/lab/data/files/"  # Update this
    # perform the stretch
    wbt.gaussian_contrast_stretch(
        i="band1.tif",
        output="band1_gauss_cs.tif",
        num_tones=4096  # 12-bit depth output
    )
    # visualize the histogram of the resulting image
    wbt.raster_histogram(
        i="band1_gauss_cs.tif",
        output="band1_gauss_cs.html"
    )

    print("Operation complete!")


main()

Include screenshots of both the resulting contrast-stretched image (band1_gauss_cs.tif) and the associated histogram with your lab hand-in. (2 marks)

2.1. Describe how the histogram of the stretched image compares to the original band1 histogram. How has it been modified? (2 marks)

If you haven't already done so, display the band1_gauss_cs.tif using your visualization software.

2.2. Compare the contrast of the Gaussian stretched image to the original band1. In particular, what objects/land covers are associated with the darkest and the brightest parts of the image? Are you able to distinguish features, such as individual agricultural fields, better in the contrast enhanced image than the original? How much contrast is there between the water (Lake Ontario and Lake Erie) and the surrounding land? Are the streets within urban centres (e.g. Toronto) visible or are they "washed out"? (5 marks)

Now try to modify your script to use the HistogramEqualization tool instead. Be sure to save the modification as a new file. Also, generate the histogram for this newly created histogram-equalized image as well. Be sure to examine the help for this tool in the WhiteboxTools User Manual, so that you are sure you are calling the histogram_equalization() function correctly. You will also want to modify the script so that the output files are called band1_he_cs.tif and band1_he_cs.html instead.

Include your script for performing the histogram equalization contrast stretch, as well as screenshots of the resulting image (band1_he_cs.tif) and histogram, with your lab hand-in. (3 marks for the script + 2 marks for the screenshots = 5 marks)

2.3. Discuss the effects of the histogram equalization contrast stretch on the quality of the image. (5 marks)

Finally, modify your script again, this time making it apply the MinMaxContrastStretch tool to the band1 image. A min-max contrast stretch is one in which:

DNout = ((DNin – min_val)/(max_val – min_val)) x num_tones

Any DNin < min_val is assigned min_val in the output and any DNin > max_val is assigned max_val in the output. That is, all values in the input image below or above specified thresholds (min_val and max_val) are fully saturated in the output image. Use your knowledge of the original image histogram, and the DN value range (from section 1) to help guide you in setting appropriate values for the min_val and max_val parameters. Although it is somewhat subjective what these parameters should be, min_val should be greater than the overall image minimum and max_val should be set to a lower value than the image maximum. This parameterization will require some experimentation with these values until you are satified that you have set them appropriately. Remember, ideally, you would like to saturate the tonal variation within the cloud cover, in order to create an image that emphasizes as much detail in the non-cloud areas as possible. Use the level of detail in the urban areas (do the streets seem 'washed out'), the agricultural fields (can you see the differences in tones within and between fields), and the land-lake contrast as guides.

Include your final script for performing the min-max contrast stretch, as well as screenshots of the resulting image (band1_minmax_cs.tif) and histogram, with your lab hand-in. (3 marks for the script + 2 marks for the screenshots = 5 marks)

2.4. Which of the three tested contrast enhancement techniques afforded you the greatest control over the contrast properties of the output image. Be sure to provide justification for your answer. (2 marks)

2.5. What were the final values that you settled on for the min_val and max_val parameters? Which of the two parameters did you find you needed to change. How did this final image compare with the other contrast enhanced images (i.e. using the Gaussian stretch and histogram equalization)? (6 marks)

2.6. How did the shape of the histogram of the min-max contrast stretched image compare with the original image histogram? (2 marks)