Batch Process 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.

    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.

  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 can use this variable to import the sequence into Simulink®.

    for i = 1:length(fileNames)
        my_video(:,:,i) = imread(fileNames{i});
    end

For additional information about batch processing, see the Batch Processing Image Files in Parallel example in the Image Processing Toolbox™.

Configuration Parameters

You can locate the Model Configuration Parameters by selecting Model Configuration Parameters from the Simulation menu. For this example, the parameters on the Solver pane, are set as follows:

  • Stop time = 10

  • Type = Fixed-step

  • Solver = Discrete (no continuous states)

Was this topic helpful?