| 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 |
You can use the Selector block to crop your image or video stream. In this example, you learn how to use the Selector block to trim an image down to a particular region of interest:
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 |
Video Viewer | Video and Image Processing Blockset > Sinks | 2 |
Selector | Simulink > Signal Routing | 1 |
Position the blocks as shown in the following figure.

Use the Image From File block to import the intensity image. Set the File name parameter to coins.png. The image is a 246-by-300 matrix of 8-bit unsigned integer values.
Use the Video Viewer block to display the original image. Accept the default parameters.
The Video Viewer block automatically displays the original image in the Video Viewer window when you run the model.
Use the Selector block to crop the image. Set the block parameters as follows:
Number of input dimensions = 2
1
Index Option = Starting index (dialog)
Index = 140
Output Size = 70
2
Index Option = Starting index (dialog)
Index = 200
Output Size = 70

The Selector block starts at row 140 and column 200 of the image and outputs the next 70 rows and columns of the image.
Use the Video Viewer1 block to display the cropped image.
The Video Viewer1 block automatically displays the modified image in the Video Viewer window when you run the model.
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 cropped image appears in the Video Viewer window. The following image is shown at its true size.

In this example, you used the Selector block to crop an image. For more information about the Selector block, see the Simulink documentation. For information about the imcrop function, see the Image Processing Toolbox documentation.
![]() | Resizing an Image | Morphological Operations | ![]() |

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 |