Main Content

Rotate an Image in Simulink

This example shows you how to rotate an image.

Example Model

Open the Simulink® model.

modelname = "ex_blkrotatepeppers.slx";
open_system(modelname)

The model reads an input image using an Image From File block with the File name parameter set to peppers.png and the Sample time parameter set to inf. To rotate the input image, the model uses a Rotate block with the Angle (radians) parameter set to pi/6 radians and the Output size parameter set to Expanded to fit rotated input image.

Simulate the Model

Run the model. The Video Viewer blocks display the input image and the output image containing the rotated image. Note that, due to the specified Output size value, the output image crops the corners of the rotated image to fit the original image dimensions..

output = sim(modelname)

Figure Output Image contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The hidden axes object contains an object of type image.

Figure Input Image contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The hidden axes object contains an object of type image.

output = 
  Simulink.SimulationOutput:
                   tout: [51x1 double] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char]