3

I am getting error for my below code: temp=reshape(img',irow*icol,1);

   Error message:Error using  ' 
   Transpose on ND array is not defined.

What is solution for this. I think I have to use permute(A,order) command. But I dont know how to use this command in my code. Do you know any solution?

 for i=1:M
str=strcat(int2str(i),'.jpg');   %concatenates two strings that form the name of the image
eval('img=imread(str);');
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
if i==3
    title('Training set','fontsize',18)
end
drawnow;
[irow icol]=size(img);    % get the number of rows (N1) and columns (N2)
temp=reshape(img',irow*icol,1);     %creates a (N1*N2)x1 matrix
S=[S temp];         %X is a N1*N2xM matrix after finishing the sequence
                    %this is our S
end
StarsSky
  • 6,721
  • 6
  • 38
  • 63
prashanth
  • 137
  • 2
  • 11
  • `[irow icol C]=size(img); temp=reshape(img',irow*icol*C,1);` Might work. – Divakar Mar 22 '14 at 10:29
  • Sir I tried this still iam getting error:Error using ' Transpose on ND array is not defined. – prashanth Mar 22 '14 at 10:38
  • 1
    You can't transpose a matrix of more than two dimensions. Why do you need to transpose exactly? – Mehrdad A. Mar 22 '14 at 10:43
  • Actually iam doing face recognition using eigen faces.So i have to convert each colored face images of dimensions(irow *icol) present in training set into face vector of (irow*icol)*1 matrix. – prashanth Mar 22 '14 at 12:27

1 Answers1

2

I assume the code was designed for grey scale images. For matrices with more than two dimensions, you have to use permute. One solution could be:

[irow icol d]=size(img);
temp=reshape(permute(img,[2,1,3]),[irow*icol,d]);

Which results in a nx3 matrix, each column corresponding to one colour. You have to change the last line as well, but I don't know what you are expecting. Maybe take a look at cat

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • I used your above code but stil iam getting error.Error using reshape To RESHAPE the number of elements must not change. – prashanth Mar 22 '14 at 12:33
  • Actually iam doing face recognition using eigen faces.So i have to convert each colored face images of dimensions(irow *icol) present in training set into face vector of (irow*icol)*1 matrix – prashanth Mar 22 '14 at 12:35
  • I updated my answer, `size` did not return the number of columns the way you used it. – Daniel Mar 22 '14 at 12:37
  • Sorry i got output for that.Thanx for your solution. – prashanth Mar 22 '14 at 12:52
  • Same problem iam getting in this line. InImage=reshape(double(InputImage)',irow*icol,1); Even i replaced this code with InImage=reshape(permute(double(InputImage,[2,1,3]),irow*icol,1)); but iam getting error:too many input arguements.Would you help me? – prashanth Mar 22 '14 at 12:56
  • InImage=reshape(double(InputImage)',irow*icol,1); how can i replace this code with permute? – prashanth Mar 22 '14 at 13:04
  • @user3448813: Use the same code from my answer. Use `permute` to swap frist and second dimension. Then use reshape to get a nx3 matrix. – Daniel Mar 22 '14 at 14:21