MATLAB: Ctranspose Transpose on ND array is not defined.

eigenfaces

face recognition program
% Acquire new image
% Note: the input image must have a bmp or jpg extension.
% It should have the same size as the ones in your training set.
% It should be placed on your desktop
InputImage = input('Please enter the name of the image and its extension \n','s');
InputImage = imread(strcat('C:\Users\Sudha\Desktop\',InputImage));
figure(5)
subplot(1,2,1)
imshow(InputImage); colormap('gray');title('Input image','fontsize',18)
InImage=reshape(double(InputImage)',irow*icol,1);
temp=InImage;
me=mean(temp);
st=std(temp);
temp=(temp-me)*ustd/st+um;
NormImage = temp;
Difference = temp-m;
p = [];
aa=size(u,2);
for i = 1:aa
pare = dot(NormImage,u(:,i));
p = [p; pare];
end
ReshapedImage = m + u(:,1:aa)*p; %m is the mean image, u is the eigenvector
ReshapedImage = reshape(ReshapedImage,icol,irow);
ReshapedImage = ReshapedImage';
%show the reconstructed image.
subplot(1,2,2)
imagesc(ReshapedImage); colormap('gray');
title('Reconstructed image','fontsize',18)
InImWeight = [];
for i=1:size(u,2)
t = u(:,i)';
WeightOfInputImage = dot(t,Difference');
InImWeight = [InImWeight; WeightOfInputImage];
end
ll = 1:M;
figure(68)
subplot(1,2,1)
stem(ll,InImWeight)
title('Weight of Input Face','fontsize',14)
% Find Euclidean distance
e=[];
for i=1:size(omega,2)
q = omega(:,i);
DiffWeight = InImWeight-q;
mag = norm(DiffWeight);
e = [e mag];
end
kk = 1:size(e,2);
subplot(1,2,2)
stem(kk,e)
title('Eucledian distance of input image','fontsize',14)
MaximumValue=max(e);
MinimumValue=min(e);
the error is
??? Error using ==> ctranspose
Transpose on ND array is not defined.
Error in ==> Mio at 164
InImage=reshape(double(InputImage)',irow*icol,1);
plz help me solve this error…

Best Answer

Ouch. It is strongly recommended to avoid unnecessary indirections like:
str = strcat(int2str(i),'.jpg');
eval('img=imread(str);');
This is faster, safer, cleaner and less weird:
img = imread(sprintf('%d.jpg', i));
I'd be so happy, if the crude and brute clearing whould vanish from the world of Matlab: clear all, close all, clc. This does not solve any problems, but wastes time and energy for reloading the function from the disk. At least clear variables should replace clear all.
The error message is very clear. In this line:
InImage = reshape(double(InputImage)',irow*icol,1);
the variable InputImage has more than 2 dimensions. Most likely it is a [X x Y x 3] RGB array and you want:
InImage = reshape(permute(double(InputImage), [2,1,3]), irow*icol, 3);
But I assume you will get further problems, when InImage is not a vector anymore, but a RGB matrix. Therefore something like rgb2gray might be useful.