Search code examples
matlabmatrix3dimaging

How to stack a series of images in MATLAB


clc;clear all;


Imatrix = []
for i=1:3

  images{i} = imread(sprintf('frame-1065.png',i));
  Imatrix = cat(3, Imatrix, images{i});
  D = Imatrix;

end;

imshow(D)

This is the code I'm trying to run but the problem is I have 2000 pictures and I am only able to get one to be displayed.


Solution

  • I think what you really want is to store the images as image stacks. This will allow you to view the image stack in e.g. ImageJ and scroll through it etc.

    I would store them as one single tiff file and do something like this (please note that all your images must be of the same size):

    numOfImages = 2000;
    output_filename = 'imgstack.tif';
    for k=1:numOfImages
        loaded_image = imread(sprintf('frame-%d.png',k));
        imwrite(loaded_image, output_filename, 'WriteMode',append','Compression','none');
    end