| 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 |
A common image processing task is to apply an image processing algorithm to a series of files. In this example, you import a sequence of images from a folder into the MATLAB workspace and display the sequence using the Video and Image Processing Blockset software.
Note In this example, the image files are a set of 10 microscope images of rat prostate cancer cells. These files are only the first 10 of 100 images acquired. |
Specify the folder containing the images, and use this information to create a list of the file names, as follows:
fileFolder = fullfile(matlabroot,'toolbox', ...
'images','imdemos');
dirOutput = dir(fullfile(fileFolder,'AT3_1m4_*.tif'));
fileNames = {dirOutput.name}' View one of the images, using the following command sequence:
I = imread(fileNames{1});
imshow(I);
text(size(I,2),size(I,1)+15, ...
'Image files courtesy of Alan Partin', ...
'FontSize',7,'HorizontalAlignment','right');
text(size(I,2),size(I,1)+25, ....
'Johns Hopkins University', ...
'FontSize',7,'HorizontalAlignment','right');

Use a for loop to create a variable that stores the entire image sequence. You are going to use this variable to import the sequence into Simulink.
for i = 1:length(fileNames)
my_video(:,:,i) = imread(fileNames{i});
endCreate a new Simulink model, and add to it the blocks shown in the following table.
Block | Library | Quantity |
|---|---|---|
Video From Workspace | Video and Image Processing Blockset > Sources | 1 |
Video Viewer | Video and Image Processing Blockset > Sinks | 1 |
Connect the blocks so your model looks similar to the following figure.

Use the Video From Workspace block to import the image sequence into Simulink. Set the Signal parameter to my_video.
Use the Video Viewer block to view the image sequence. Accept the default parameters.
Set the configuration parameters. Open the Configuration dialog box by selecting Simulation > Configuration Parameters. On the Solver pane, set the parameters as follows:
Stop time = 10
Type = Fixed-step
Solver = Discrete (no continuous states)
Because the Video From Workspace block's Sample time parameter is set to 1 and the Stop time parameter is set to 10, the Video Viewer block displays 10 images before the simulation stops.
Run your model. You can view the image sequence in the Video Viewer window.

For more information on the blocks used in this example, see the Video From Workspace and Video Viewer block reference pages. For additional information about batch processing, see the Batch Processing Image Files Using Distributed Computing demo in Image Processing Toolbox. You can run this demo by typing ipexbatch at the MATLAB command prompt.
![]() | Importing and Exporting Images and Video | Working with Live Video | ![]() |

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 |