Rotate an image around centroid without deformation

6 ビュー (過去 30 日間)
Jack
Jack 2022 年 9 月 15 日
コメント済み: Rik 2022 年 9 月 15 日
Hey everyone. I am trying to create an image of a rectangle and rotate it 360* and save all of those images to do a comparison later. However the cell expands with imrotate and I need them to all to be the same size to do cell operations later. When I perform the crop in the last line it cuts the extra pixels from right to left, then distorting the positon of rectangle I have drawn.
Does anyone have an easy method to rotate just the rectangle 360* around its centroid but maintaining a 101*101 pixel canvas. Reference image to see how it moves off centre.
Thanks. :)
image=zeros(101,101);
image(29:78,43:60)=1; %Create a rectangular image (0 is white and 1 will be black)
for i=1:1:360
rotated{i}=imrotate(image,i); %roate the image 360 degrees
rotated{i}=rotated{1,i}(1:101,1:101); %Crop the image back down to 101x101 so cell operations can be conducted later

採用された回答

Rik
Rik 2022 年 9 月 15 日
I'm not a fan of using i as a variable name, nor do I like shadowing the image primitive with a variable.
Other than that, reading the documentation helps, as it provides the option to crop the resulting image instead of extending it.
base_image=zeros(101,101);
base_image(29:78,43:60)=1; %Create a rectangular image (0 is white and 1 will be black)
for deg=20 % only 1 value for this example
rotated{deg}=imrotate(base_image,deg,'nearest','crop'); %rotate the image 360 degrees
end
imshow(rotated{deg})
  2 件のコメント
Jack
Jack 2022 年 9 月 15 日
Unreal. Total begginer here trying to use Matlab to track particles for my thesis. Thanks so much for your help :)
Rik
Rik 2022 年 9 月 15 日
You're welcome. I consider the Matlab documentation one of the main advantages over competitors/alternatives. I would strongly urge you to try to learn to use them. A Google search will generally bring up the documentation as well.
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). That should get you up to speed with the basics, leveling you up from total beginner to beginner.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by