Why is the lenna image rotated?
Show older comments
Opened lenna.raw file in figure.
By the way, the image is rotated 90 degrees counterclockwise. It was a 256x256 image, and I printed the image using mat2gray.
I'm curious as to why and how the image is spinning.
please help me thank you.
4 Comments
DGM
on 22 Feb 2022
mat2gray() doesn't save or print anything. It just takes a weighted average of the image channels.
Without knowing what you did to the image and what you're doing now, nobody has any way of knowing. Attach a small example of the code which can demonstrate the problem.
I'm going to go out on a limb and guess that you're doing some point-by-point looping and you have your row and column subscripts swapped.
niniki
on 22 Feb 2022
When you read the image into a rectangular geometry such as in this call:
a = fread(raw,[256,256])
understand that what you're doing is taking the raw data in the file (a vector) and devectorizing it. This is the same as reshaping any other vector.
Consider the example:
myimagevector = 1:25; % pretend this is the image data
myimagematrix = reshape(myimagevector,5,5)
The contents of the vector are placed columnwise into the output geometry. If the original data had been written out row-wise, then the result will be transposed -- not rotated.
@yanqi liu is correct. All you likely need to do is transpose the incoming image.
niniki
on 23 Feb 2022
Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox 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!