stim_images2matrix.m
912 Bytes
function S = stim_images2matrix(filemask)
%This function loads a set of images as a 3D matrix. Color images are
%converted to grayscale when loaded, so the resulting matrix is always 3D
%with size X x Y x Z, where:
% X is the size of the images along the X axis
% Y is the size of the images along the Y axis
% Z is the number of images
%
% all images are assumed to be the same size (though they do not have to
% be the same file format or number of bits per pixel
files = dir(filemask);
%figure out the file size
I = imread([files(1).folder '/' files(1).name]);
X = size(I, 1);
Y = size(I, 2);
Z = length(files);
S = zeros(X, Y, Z, 'uint8');
h = waitbar(0, ['Loading ' num2str(Z) ' images...']);
for i = 1:Z
I = rgb2gray(imread([files(1).folder '/' files(1).name]));
S(:, :, i) = I;
waitbar(i/Z, h);
end
close(h);
end