title: Reading face images into array using MATLAB
body: <p>I currently have a program using MATLAB where we have to perform face recognition on images in folders Training_images and Testing_images. I have written the code to do turn these images into a matlab database:</p>
  
  <pre><code>function database = buildImagesDataBase(directory, Imageprefix, extension, maxN, namesFile)
      database = initDB(maxN);
      names = readImgInfo([directory namesFile]);
      for i=1:1:maxN
          imgFileName = [directory, Imageprefix, num2str(i), '.', extension];
          database(i).name = names{i};
          database(i).rgb = imread(imgFileName);  
          if ( length(size(database(i).rgb)) == 3)
              database(i).gray = rgb2gray(database(i).rgb);        
  else
              database(i).gray = database(i).rgb;        
          end;
          database(i).grayCrop = cropHead(database(i).gray);
          database(i).grayResize = imresize(database(i).grayCrop, [84 64]);   
          database(i).dataVect = database(i).grayResize(:);
  end 
  </code></pre>
  
  <p>end</p>
  
  <p>Then when I run the code it will be something like: </p>
  
  <pre><code>&gt;&gt;dbWink = buildImagesDB('Testing\', 'person', 'wink.gif', 10, 'names.txt');
  </code></pre>
  
  <p>However I need to modify the code so it does not take a .txt file to get the names, instead it gets it from each individual file name dynamically eg. Steven_happy, Michael_happy etc, so from my understanding this means the 'subject' field will need to be changed too so that the filenames are not fixed with a subject prefix ie. person1.wink 
  I am unsure how to do this with MATLAB so any help would be greatly appreciated.
  Thanks,
  Mark</p>