| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Video and Image Processing Blockset |
| Contents | Index |
| Learn more about Video and Image Processing Blockset |
Global threshold techniques, which are often the first step in object measurement, cannot be applied to unevenly illuminated images. To correct this problem, you can change the lighting conditions and take another picture, or you can use morphological operators to even out the lighting in the image. Once you have corrected for nonuniform illumination, you can pick a global threshold that delineates every object from the background. In this topic, you use the Opening block to correct for uneven lighting in an intensity image:
Create a new Simulink model, and add to it the blocks shown in the following table.
Block | Library | Quantity |
|---|---|---|
Image From File | Video and Image Processing Blockset > Sources | 1 |
Opening | Video and Image Processing Blockset > Morphological Operations | 1 |
Video Viewer | Video and Image Processing Blockset > Sinks | 4 |
Constant | Simulink > Sources | 1 |
Sum | Simulink > Math Operations | 2 |
Data Type Conversion | Simulink > Signal Attributes | 1 |
Position the blocks as shown in the following figure.

Once you have assembled the blocks required to correct for uneven illumination, you need to set your block parameters. To do this, double-click the blocks, modify the block parameter values, and click OK.
Use the Image From File block to import the intensity image. Set the File name parameter to rice.png. This image is a 256-by-256 matrix of 8-bit unsigned integer values.
Use the Video Viewer block to view the original image. Accept the default parameters.
Use the Opening block to estimate the background of the image. Set the Neighborhood or structuring element parameter to strel('disk',15).

The strel function creates a circular STREL object with a radius of 15 pixels. When working with the Opening block, pick a STREL object that fits within the objects you want to keep. It often takes experimentation to find the neighborhood or STREL object that best suits your application.
Use the Video Viewer1 block to view the background estimated by the Opening block. Accept the default parameters.
Use the first Sum block to subtract the estimated background from the original image. Set the block parameters as follows:
Icon shape = rectangular
List of signs = -+
Use the Video Viewer2 block to view the result of subtracting the background from the original image. Accept the default parameters.
Use the Constant block to define an offset value. Set the Constant value parameter to 80.
Use the Data Type Conversion block to convert the offset value to an 8-bit unsigned integer. Set the Output data type mode parameter to uint8.
Use the second Sum block to lighten the image so that it has the same brightness as the original image. Set the block parameters as follows:
Icon shape = rectangular
List of signs = ++
Use the Video Viewer3 block to view the corrected image. Accept the default parameters.
Connect the blocks as shown in the following figure.

Set the configuration parameters. Open the Configuration dialog box by selecting 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)
The original image appears in the Video Viewer window.

The estimated background appears in the Video Viewer1 window.

The image without the estimated background appears in the Video Viewer2 window.

The preceding image is too dark. The Constant block provides an offset value that you used to brighten the image.
The corrected image, which has even lighting, appears in the Video Viewer3 window. The following image is shown at its true size.

In this section, you have used the Opening block to remove irregular illumination from an image. For more information about this block, see the Opening block reference page in the Video and Image Processing Blockset Reference. For related information, see the Top-hat block reference page. For more information about STREL objects, see the strel function in the Image Processing Toolbox documentation.
![]() | Counting Objects in an Image | Example Applications | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |