Open the “stills_R_W.mdl” Simulink model (generated in the "A Framework for Image Processing with the DSK6416" module).
Add to it the blocks shown in the following table:
Table 1
| Block |
Library |
Quantity |
| Edge Detection |
Video and Image Processing Blockset / Analysis & Enhancement |
1 |
| Hough Transform |
Video and Image Processing Blockset / Transforms |
1 |
| Find Local Maxima |
Video and Image Processing Blockset / Statistics |
1 |
| Selector |
Simulink®/ Signal Routing |
2 |
| Variable Selector |
Signal Processing Blockset / Signal Management / Indexing |
2 |
| Terminator |
Simulink / Sinks |
1 |
| Hough Lines |
Video and Image Processing Blockset / Transforms |
1 |
| Draw Shapes |
Video and Image Processing Blockset / Text & Graphics |
1 |
You are now ready to set your block parameters.
Use the Image From Workspace block to import your image from the MATLAB workspace.
Set the block parameters as follows:
- Main pane, Value = I
- Main pane, Output port labels = I
Use the Edge Detection block to find the edges in the intensity image. This process improves the efficiency of the Hough Lines block as it reduces the image area over which the block searches for lines. The block also converts the image to a binary image, which is the required input for the Hough Transform block. Use the default parameters.
Use the Video Viewer block to display the edges found by the Edge Detection block. Set the Input image type parameter to Intensity.
Use the Hough Transform block to compute the Hough matrix by transforming the input image into the rho-theta parameter space. The block also outputs the rho and theta values associated with the Hough matrix. Set the block parameters as follows:
- Theta resolution (radians) = pi/360
- Select the Output theta and rho values check box.
Use the Find Local Maxima block to find the location of the maximum value in the Hough matrix. Set the block parameters as follows:
- Maximum number of local maxima (N) = 1
- Select the Input is Hough matrix spanning full theta range check box.
Use the Selector blocks to separate the indices of the rho and theta values, which are output at the Idx port, that are associated with the maximum value in the Hough matrix. Set the Selector block parameters as follows:
- Index mode = Zero-based
- Elements (-1 for all elements) = 0
- Input port width = 2
Set the Selector1 block parameters as follows:
- Index mode = Zero-based
- Elements (-1 for all elements) = 1
- Input port width = 2
Use the Variable Selector blocks to index into the rho and theta vectors and determine the rho and theta values that correspond to the longest line in the original image. Set the parameters of the Variable Selector blocks as follows:
- Select = Columns
- Index mode = Zero-based
Use the Hough Lines block to determine where the longest line intersects the edges of the original image. You use these coordinates to superimpose a white line on the original image. Use the default parameters.
Use the Draw Shapes block to draw a white line over the longest line on the original image. Set the block parameters as follows:
- Input image type = Intensity
- Shape = Lines
- Border intensity = White
Use the Video Viewer block to display the original image with a white line superimposed over the longest line in the image. Set the Input image type parameter to Intensity.
Connect the blocks as shown in the figure below. Use the file circuit.tif as input.
Create a Subsystem for the Hough algorithm. Select the blocks as shown in the following picture:
In the main menu, click on Edit/Create Subsystem (you may also enter Ctrl+G), as follows:
Your model should resemble the following figure:
Double-click the "Hough Algorithm", and you should see:
Create a Subsystem for the “Line Drawing and Image Construction”. Select the blocks as shown in the following picture:
In the main menu, click on Edit/Create Subsystem (you may also enter Ctrl+G),
Your model should resemble the following figure:
Double-click the " Line Drawing and Image Construction ", and you should see:
Create a Subsystem for the “Line Detection”. Select the blocks as shown in the following picture:
The model should look as follows:
Save the file as "LineDetection.mdl"
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)
Run your model.
The Video Viewer window displays the edges found in the original image in white and the background in black. To view the image at its true size, right-click the window and select Set Display To True Size.
Running this gives you the images in Figure 1.
The Video Viewer1 window displays the original image with a white line drawn over the longest line in the image.
You may repeat the simulation here to experiment the various algorithms with different thresholds.