Image is rotating but becoming whitish!

8 views (last 30 days)
I am trying to rotate the image without using imrotate. Logic is fine and image is rotating as well. But image is getting noise or something and becoming whitish. Any help would be appreciated as I am a beginner in this. Thank you.
% Read input image
img = imread('dog.jpeg');
img_90 = rotate90(img);
img_180 = rotate90(img_90);
% display result
subplot(1, 3, 1), imshow(img), title('Original Image');
subplot(1, 3, 2), imshow(img_90), title('Rotated (90)');
subplot(1, 3, 3), imshow(img_180), title('Rotated (180)');
function rotated = rotate90(img)
[r, c, z] = size(img);
% Create dummy matrix to store updated matrix.
rotated(c, r, z) = 0;
% Loop to access each element of matrix.
for plane = 1:z
for i = 1:r
for j = 1:c
% Logic to rotate Matrix A by 90 degree.
rotated(c-(j-1), i, plane) = img(i, j, plane);
end
end
end
end

Accepted Answer

Ravi Keshri
Ravi Keshri on 22 Sep 2021
Edited: Ravi Keshri on 22 Sep 2021
Okay I found a solution.
rotated = uint8(rotated);
rotated was double and needs to be converted to uint8 at the end of the function.
Can anyone please explain me why this happens?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!