how to solve the transpose error of an image

2 次查看(过去 30 天)
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);

回答(1 个)

ag
ag 2024-8-6
编辑:ag 2024-8-6
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!

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by