Adjust the Contrast of Intensity Images

This example shows you how to modify the contrast in two intensity images using the Contrast Adjustment and Histogram Equalization blocks.

  1. Create a new Simulink® model, and add to it the blocks shown in the following table.

    Block

    Library

    Quantity

    Image From File

    Computer Vision System Toolbox™ > Sources

    2

    Contrast Adjustment

    Computer Vision System Toolbox > Analysis & Enhancement

    1

    Histogram Equalization

    Computer Vision System Toolbox > Analysis & Enhancement

    1

    Video Viewer

    Computer Vision System Toolbox > Sinks

    4

  2. Place the blocks listed in the table above into your new model.

  3. Use the Image From File block to import the first image into the Simulink model. Set the File name parameter to pout.tif.

  4. Use the Image From File1 block to import the second image into the Simulink model. Set the File name parameter to tire.tif.

  5. Use the Contrast Adjustment block to modify the contrast in pout.tif. Set the Adjust pixel values from parameter to Range determined by saturating outlier pixels. This block adjusts the contrast of the image by linearly scaling the pixel values between user-specified upper and lower limits.

  6. Use the Histogram Equalization block to modify the contrast in tire.tif. Accept the default parameters. This block enhances the contrast of images by transforming the values in an intensity image so that the histogram of the output image approximately matches a specified histogram.

  7. Use the Video Viewer blocks to view the original and modified images. Accept the default parameters.

  8. Connect the blocks as shown in the following figure.

  9. Set the configuration parameters. Open the Configuration dialog box by selecting Model Configuration Parameters from the Simulation menu. Set the parameters as follows:

    • Solver pane, Stop time = 0

    • Solver pane, Type = Fixed-step

    • Solver pane, Solver = Discrete (no continuous states)

  10. Run the model.

    The results appear in the Video Viewer windows.

In this example, you used the Contrast Adjustment block to linearly scale the pixel values in pout.tif between new upper and lower limits. You used the Histogram Equalization block to transform the values in tire.tif so that the histogram of the output image approximately matches a uniform histogram. For more information, see the Contrast Adjustment and Histogram Equalization reference pages.

Was this topic helpful?