This page is optimized for mobile devices, if you would prefer the desktop version just click here

3.2 Finding shapes in images  (Page 2/4)

  • 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.

Line Detection
<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, From matlab and simulink to real-time with ti dsp's. OpenStax CNX. Jun 08, 2009 Download for free at http://cnx.org/content/col10713/1.1
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.