Products & Services Solutions Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Batch Processing Image Files

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.

  1. 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}' 

  2. 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');

  3. 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});
    end
  4. Create 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

  5. Connect the blocks so your model looks similar to the following figure.

  6. Use the Video From Workspace block to import the image sequence into Simulink. Set the Signal parameter to my_video.

  7. Use the Video Viewer block to view the image sequence. Accept the default parameters.

  8. 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.

  9. 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.

  


Related Products & Applications

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