how to find the quadrant of the point in a image
4 views (last 30 days)
Show older comments
Say you have a point in a bounding box and have to calculate which quadrant it lies in, in order to find the orientation of the next connected component. I have the centroid of the bounding box as well as the centroid of the point. Thanks
I have tried to find the directional vector of the two points but i dont think matlab has that functionality to find the oritentation of the next connected component.
12 Comments
Accepted Answer
Ameer Hamza
on 9 Mar 2020
Edited: Ameer Hamza
on 9 Mar 2020
You can use atan2 to calculate the direction of the line connecting the center of the bounding box and dot.
center_bb = [0.1 0.3]; %
center_dot = [-0.5 0.5]; % 2nd quadrant with respect to center_bb
difference = center_dot - center_bb;
angle = atan2d(difference(2), difference(1)); % angles in degrees
Result
angle =
161.5651
This assumes that you are using rectangular coordinates. So angle 161 degrees lies in the 2nd coordinate as we initially assumed.
Note that in case of an image, the y-axis might be inverted if the pixel coordinates start from the top-left of the image. In that case, 1st coordinate will be swapped with 4th and 2nd with 3rd.
6 Comments
Guillaume
on 9 Mar 2020
I thought Ameer's explanation and drawing were very clear. I'd recommend you spend a bit of time drawing axes on a paper. This is really basic geometry.
_"what has to be changed to get the right angle?"
The sign of y or the sign of the angle... or nothing at all if you use the same coordinate system to define all your angles/coordinates.
More Answers (0)
See Also
Categories
Find more on Geographic Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



