| 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 Rotate block to rotate your image or video stream by a specified angle. In this example, you learn how to use the Rotate block to continuously rotate an image:
Define an RGB image in the MATLAB workspace. At the MATLAB command prompt, type
I = checker_board;
I is a 100-by-100-by-3 array of double-precision values. Each plane of the array represents the reg, green, or blue color values of the image.
To view the image this matrix represents, at the MATLAB command prompt, type
imshow(I)

Create a new Simulink model, and add to it the blocks shown in the following table.
Block | Library | Quantity |
|---|---|---|
Image From Workspace | Video and Image Processing Blockset > Sources | 1 |
Rotate | Video and Image Processing Blockset > Geometric Transformations | 1 |
Video Viewer | Video and Image Processing Blockset > Sinks | 2 |
Gain | Simulink > Math Operations | 1 |
Display | Signal Processing Blockset > Signal Processing Sinks | 1 |
Counter | Signal Processing Blockset > Signal Management > Switches and Counters | 1 |
Position the blocks as shown in the following figure.

You are now ready to set your block parameters by double-clicking the blocks, modifying the block parameter values, and clicking OK.
Use the Image From Workspace block to import the RGB image from the MATLAB workspace. On the Main pane, set the Value parameter to I.Each plane of the array represents the reg, green, or blue color values of the image.
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. Because the image is represented by double-precision floating-point values, a value of 0 corresponds to black and a value of 1 corresponds to white.
Use the Rotate block to rotate the image. Set the block parameters as follows:
Rotation angle source = Input port
Sine value computation method = Trigonometric function

The Angle port appears on the block. You use this port to input a steadily increasing angle. Setting the Output size parameter to Expanded to fit rotated input image ensures that the block does not crop the output.
Use the Video Viewer1 block to display the rotating image. Accept the default parameters.
Use the Counter block to create a steadily increasing angle. Set the block parameters as follows:
Count event = Free running
Counter size = 16 bits
Output = Count
Clear the Reset input check box.
Sample time = 1/30
The Counter block counts upward until it reaches the maximum value that can be represented by 16 bits. Then, it starts again at zero. You can view its output value on the Display block while the simulation is running. You are using the Counter block from Signal Processing Blockset software because its Count data type parameter enables you to specify the data type of its output.
Use the Gain block to convert the output of the Counter block from degrees to radians. Set the Gain parameter to pi/180.
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 = inf
Solver pane, Type = Fixed-step
Solver pane, Solver = Discrete (no continuous states)
The original image appears in the Video Viewer window.

The rotating image appears in the Video Viewer1 window.

In this example, you used the Rotate block to continuously rotate your image. For more information about this block, see the Rotate block reference page in the Video and Image Processing Blockset Reference. For more information about other geometric transformation blocks, see the Resize and Shear block reference pages.
Note If you are on a Windows operating system, you can replace the Video Viewer block with the To Video Display block, which supports code generation. |
![]() | Geometric Transformation Interpolation Methods | Resizing an Image | ![]() |

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 |