title: Male/Female Classification with Matlab- About Finding Mean Image
body: <p>I am working on a project which is about pattern (male/female)classification with matlab.I have a problem, I need your help, please.</p>
  
  <p>My program should find mean images of datasets. First dataset is women,second dataset is men. So first mean image has to look like a woman and second a man.I have different datasets which all have format of jpeg. I am trying different datasets for my program to check if it is working but when I use different datasets I can not see true mean images all the time, for ex:</p>
  
  <p>They are mean images from a dataset:</p>
  
  <p><img src="https://i.stack.imgur.com/qo2KZ.jpg" alt="enter image description here"></p>
  
  <p>But when I use another dataset my mean images are like this, they have no meanings, I mean they dont look like face:</p>
  
  <p><img src="https://i.stack.imgur.com/FdCj8.jpg" alt="enter image description here"></p>
  
  <p>What can be the reason for this? I should work with different datasets. Please help.
      `</p>
  
  <pre><code>filenamesA = dir(fullfile(pathfora, '*.jpg'));
  Train_NumberA = numel(filenamesA);
  
  %%%%%%%%%%%%%%%%%%%% Finding Image Vectors for A
  
  imagesA= [];
  for k = 1 : Train_NumberA
  
      str = int2str(k);
  
      str= strcat(str);
  
      str = strcat('\',str,'b','.jpg');
      str = strcat(pathfora,str);
  
      imgA = imread(str);
      imgA = rgb2gray(imgA);
      [irowA icolA] = size(imgA);
      tempA = reshape(imgA',irowA*icolA,1);   % Reshaping 2D images into 1D image vectors
      imagesA = [imagesA tempA]; % 'imagesA' grows after each turn 
  
      imagesA=double(imagesA);
  end`
  
  
  `%%%%%%%%%%%%%%%%%%%%%%%% Calculate the MEAN IMAGE VECTOR for A
  
  mean_vectorA= mean(imagesA,2); % Computing the average vector m = (1/P)*sum(Tj's)    (j = 1 : P)
  mean_imageA= reshape(mean_vectorA,irowA,icolA);   % Average matrix of training set A
  meanimgA=mat2gray(mean_imageA);
  figure(1);
  imshow(rot90(meanimgA,3));`
  
  
  
  -------------------------------------And same for dataset B (male)
  </code></pre>