T
T
tj572017-04-23 14:53:01
MATLAB
tj57, 2017-04-23 14:53:01

How to rotate an image in matlab?

there is such code
img = imread('path_to_image');
[m,n,p]=size(img);
angle = 45*pi/180;
mm = round(m*cos(angle) + n*abs(sin(angle)));
nn = round(n*cos(angle) + m*abs(sin(angle)));
x0 = mm/2;
y0 = nn/2;
for x=1:mm
for y=1:nn
i = round(m/2 + (x-x0)*cos(angle) + (y-y0)*sin(angle));
j = round(n/2 + -(x-x0)*sin(angle) + (y-y0)*cos(angle));
if i>0 && j>0 && i<=m && j<=n
img2(x,y,:) = img(i,j,:);
end
end
end
imshow(img2);
if run several times in a row, the current picture will open on top of the previous one. How to fix it ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Myasoedov, 2017-04-26
@kendomag

Will it help? (If I understood the question correctly.)
www.mathworks.com/help/matlab/ref/clf.html?request...
If each picture is opened in a new window, then add a figure
www.mathworks.com/help/matlab/ref /figure.html?sear...
However, be careful if you open a lot of windows with figure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question