Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab how to turn image 90 degree?

I have 100 gray images (256*256 pixels) and they are stored in faces.mat file. So in the faces.mat file, there are 100 rows and 65536(256*256) columns. Each row represents one image.

Now I want to reshape the faces matrix and showed the images.

I use:

for i=1:N    
    imagesc(reshape(faces(i,:)'),256,256));
    colormap gray;
end

But I found my image turn 90 degree! enter image description here

Could someone tell me how to turn the image right? Did I process images wrong when I turn them into face.mat? Below is the code I wrote to store images to matrix.

function ImageGenerate
Files = dir(strcat('D:\face\','*.tiff'));
LengthFiles = length(Files);
faces = [];
for i = 1:LengthFiles;
    Img = imread(strcat('D:\face\',Files(i).name));
    temp = im2double(Img);
    [row, col] = size(temp);
    vector = [];
    for i =1 : row
        for j = 1:col
            vector = [vector temp(i,j)];
        end
    end
    faces = [faces;vector];
end
save('faces2.mat','faces');
like image 944
Freya Ren Avatar asked Nov 30 '25 16:11

Freya Ren


1 Answers

For rotating images with int multipliers of 90 degrees there is rot90 function:

rot90(Img);

This is more efficient than imrotate and more general than just transpose that were proposed in other answers.

like image 162
Shai Avatar answered Dec 02 '25 07:12

Shai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!