フィルターのクリア

I want to rotate the rotated image in the forward direction. How do I do this?

3 ビュー (過去 30 日間)
채호 박
채호 박 2022 年 12 月 8 日
コメント済み: 채호 박 2022 年 12 月 9 日
I know I need to rotate the picture with imrotate. However, imrotate rotates based on the center point, so I need to know the angle of the picture, but I don't know how to write it in code. I want to find the angle after inputting three points (red circles) with the mouse. (Picture description: Rotate the rotated image of picture 1 by the corresponding angle to make it look like picture 2)
Below is the code to obtain the angles of three input points through ginput(3).
[x, y] = ginput(3);
app.UIFigure.HandleVisibility = fhv;
x = round(x);
y = round(y);
z=[x,y];
d=diff(z);
Angle=acos(dot(-d(1,:),d(2,:))/norm(d(1,:))/norm(d(2,:)));
  1 件のコメント
Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 8 日
You actually only need two points to determine the angle of rotation needed.

サインインしてコメントする。

採用された回答

DGM
DGM 2022 年 12 月 8 日
編集済み: DGM 2022 年 12 月 8 日
For this specific image, you could also try calculating the angles by finding certain features.
For what it's worth:
% the initial image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1224457/image.png');
% find the red circles in HSV, create a mask
inhsv = rgb2hsv(inpict);
mk = inhsv(:,:,2) > 0.1;
% get the centers of the red circles
S = regionprops(mk,'centroid');
C = vertcat(S.Centroid);
% reorder them
C = C([2 1 3],:);
% find the angles between adjacentpairs
th = atan2d(diff(C(:,2)),diff(C(:,1)));
th = mod(th,90)
th = 2×1
7.1944 6.9314
% just use the mean
th = mean(th);
% rotate the image
% i'm going to be lazy and rotate the whole composite image
outpict = imrotate(inpict,th);
% show it
imshow(outpict)
Note that this is a drawn image. The red circles are not accurately on the vertices, so we should expect some error. While it's likely that the nominal rotation is supposed to be 7 degrees, it's also likely that whoever drew it used an inaccurate method of rotating the object (grab & drag versus direct transform). Even the person who drew it might not know that it's not exactly 7 degrees.
  1 件のコメント
채호 박
채호 박 2022 年 12 月 9 日
This is really amazing code. Once again I am in awe of matlab.

サインインしてコメントする。

その他の回答 (1 件)

Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 8 日
Select upper point and then lower point using the code below:
line([0.1 0.2], [0.1 0.2]) % Should give a 45 degree line
[x y] = ginput(2)
atan2(x(1)-x(2), y(1)-y(2)) % In radians
180/pi*atan2(x(1)-x(2), y(1)-y(2)) % In degrees

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by