how to solve the transpose error of an image

2 views (last 30 days)
dhvani patel
dhvani patel on 11 Mar 2015
Edited: ag on 6 Aug 2024
InputImage= imread(strcat('C:\Users\lay\Desktop\Project\photo\1.jpg')); figure(5) subplot(1,2,1) imshow(InputImage); colormap('gray'); title('Input image','fontsize',18) InImage=reshape(double(InputImage)',irow*icol,1); [LINE:-195] temp=InImage; me=mean(temp); st=std(temp); temp=(temp-me)*ustd/st+um; NormImage = temp; Difference = temp-m; NormImage = Difference; p = []; aa=size(u,2);
****************************ERROR:- error using ' Transpose on ND array is not defined. Use PERMUTE instead.
Error in face_rec (line 195) InImage=reshape(double(InputImage)',irow*icol,1);

Answers (1)

ag
ag on 6 Aug 2024
Edited: ag on 6 Aug 2024
Hi Dhvani, the error message that you are facing is caused by using "transpose" function on an ND array. Transpose function can only be used on a Vector(1D array) or Matrix(2D array).
To resolve this issue, either of the below workarounds can be used:
1. Convert the image matrix to a gray scale, this will convert the "InputImage" from an ND array to a 2D array(matrix). The below code snippet demonstrates how to convert image to a gray scale, and use transpose:
grayImage = rgb2gray(InputImage);
reshapedImage = transpose(rgb2gray(InputImage));
2. Use Permute to reshape the matrix. The below code snippet demonstrates it's usage:
InputImage = imread(strcat('C:\Users\lay\Desktop\Project\photo\1.jpg'));
% Use permute to rearrange the dimensions of the array as per your use case
InImage = reshape(double(permute(InputImage, [2 1 3])), irow*icol, 1);
For more details on "reshape", please refer to the following MathWorks Documentation page: https://www.mathworks.com/help/matlab/ref/reshape.html
Hope this helps!

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!