- Find a bounding box, where the box can be rotated, not a box that is aligned with the axes.
- Find the orientation (angle of inclination) of the long sides of the bounding box. atan2 will help you there.
- Nothing more needed, since atan2 did all the work.
How to calculate the rotation of this egg?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashfaq Ahmed
am 9 Aug. 2022
Kommentiert: Matt J
am 9 Aug. 2022
Hi all!
Suppose I have this egg in figure1, standing still. But when it rotates a bit in figure 2, how can I calculate the rotation angle using MATLAB coding? Can anyone please give an idea on it?
I have attached the images in the question. (egg1, and egg2). Any suggestion from you will be much appreciated ^_^
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 9 Aug. 2022
2 Kommentare
John D'Errico
am 9 Aug. 2022
Bearbeitet: John D'Errico
am 9 Aug. 2022
I'm sure the Image processing toolbox has a bounding box utility. (I'll find it in a minute or so, and post the link too.) But you can also extract the points as a set of pixel locations, and then use my minboundrect utility.
Ok. A quick search tells me the tool is regionprops. It looks like you need to do something like:
regionprops(egg2,'boundingbox')
Lacking the IPT, I've never used it, but one of those tools will get you there.
Weitere Antworten (2)
Matt J
am 9 Aug. 2022
Bearbeitet: Matt J
am 9 Aug. 2022
First, crop the black corders from your image fiels. Then, use ellipticalFit() from,
getEgg=@(file) imbinarize(im2gray(imread(file)));
[Y1,X1]=find(edge(getEgg('egg1.png')));
[Y2,X2]=find(edge(getEgg('egg2.png')));
fobj1=ellipticalFit([X1(:),Y1(:)]');
fobj2=ellipticalFit([X2(:),Y2(:)]');
rotation = fobj2.angle-fobj1.angle
rotation =
137.9371
function out=getEgg(file)
out=imbinarize(im2gray(imread(file)));
end
3 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!