Blame view

matlab/stim_images2matrix.m 912 Bytes
55417e1e   David Mayerich   fixed data type l...
1
2
3
4
5
6
7
8
9
10
11
  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
  
3e3f30a2   David Mayerich   added a matlab fu...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      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