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.
Running this example requires a DSP System Toolbox™ license.
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 red, green, or blue
color values of the image.
To view the image this matrix represents, at the MATLAB command prompt, type
Create a new Simulink® model, and add to it the blocks shown in the following table.
Image From Workspace
Computer Vision System Toolbox™ > Sources
Computer Vision System Toolbox > Geometric Transformations
Computer Vision System Toolbox > Sinks
Simulink > Math Operations
DSP System Toolbox > Sinks
DSP System Toolbox > Signal Management > Switches and Counters
Use the Image From Workspace block
to import the RGB image from the MATLAB workspace. On the Main
pane, set the Value parameter to
Each plane of the array represents the red, 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 =
Sine value computation method =
The Angle port appears on the block. You use this port to input
a steadily increasing angle. Setting the Output size parameter
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 =
Counter size =
Clear the Reset input check box.
Sample time =
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. The Counter block's Count data type parameter enables you to specify it's output data type.
Use the Gain block to convert the output
of the Counter block from degrees to radians. Set the Gain parameter
Connect the blocks as shown in the following figure.
Set the configuration parameters. Open the Configuration dialog box by selecting Model Configuration Parameters from the Simulation menu. Set the parameters as follows:
Solver pane, Stop
Solver pane, Type =
Solver pane, Solver =
(no continuous states)
Run the model.
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 Computer Vision System Toolbox Reference. For more information about other geometric transformation blocks, see the Resize and Shear block reference pages.
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.