How to rotate relative points in degrees?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have 4 points in range [0.0, 1.0] representing the top-left and bottom-right corners of a bounding box.
For example: [0.25 0.33 0.71 0.73]
In other words, the first pair (in (y, x)
format) means that the point is 25% down the top of the image, and 33% from the left. The second pair means that the bottom right point is located 71% from the top of the image and 73% from the left.
Question
If I now rotate the image by N degrees, how do I compute where those 4 points should be? To be more specific, I really only care to rotate the image 90, 180, 270 degrees.
Left: original image, not rotated. Right: image rotated 90 degrees.
linear-transformations transformation rotations
add a comment |Â
up vote
1
down vote
favorite
I have 4 points in range [0.0, 1.0] representing the top-left and bottom-right corners of a bounding box.
For example: [0.25 0.33 0.71 0.73]
In other words, the first pair (in (y, x)
format) means that the point is 25% down the top of the image, and 33% from the left. The second pair means that the bottom right point is located 71% from the top of the image and 73% from the left.
Question
If I now rotate the image by N degrees, how do I compute where those 4 points should be? To be more specific, I really only care to rotate the image 90, 180, 270 degrees.
Left: original image, not rotated. Right: image rotated 90 degrees.
linear-transformations transformation rotations
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have 4 points in range [0.0, 1.0] representing the top-left and bottom-right corners of a bounding box.
For example: [0.25 0.33 0.71 0.73]
In other words, the first pair (in (y, x)
format) means that the point is 25% down the top of the image, and 33% from the left. The second pair means that the bottom right point is located 71% from the top of the image and 73% from the left.
Question
If I now rotate the image by N degrees, how do I compute where those 4 points should be? To be more specific, I really only care to rotate the image 90, 180, 270 degrees.
Left: original image, not rotated. Right: image rotated 90 degrees.
linear-transformations transformation rotations
I have 4 points in range [0.0, 1.0] representing the top-left and bottom-right corners of a bounding box.
For example: [0.25 0.33 0.71 0.73]
In other words, the first pair (in (y, x)
format) means that the point is 25% down the top of the image, and 33% from the left. The second pair means that the bottom right point is located 71% from the top of the image and 73% from the left.
Question
If I now rotate the image by N degrees, how do I compute where those 4 points should be? To be more specific, I really only care to rotate the image 90, 180, 270 degrees.
Left: original image, not rotated. Right: image rotated 90 degrees.
linear-transformations transformation rotations
asked Jul 16 at 17:53
rodrigo-silveira
1397
1397
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19
add a comment |Â
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
The transformation you require is:
$$ yâ = y cos theta + x sin theta $$
$$xâ = -y sin theta+ x cos theta$$
Also donâÂÂt forget that when programming $ cos theta$ and $ sin theta$ needs to be in radians and not degrees. To convert from degrees to radians multiply by $pi/180$.
You will note that the above formula is greatly simplified if the rotation angles are multiples of $90 deg$.
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ; xâ = -y $
For 180 degrees,$ yâ = -y, ;xâ = - x $
For 270 degrees, $yâ = -x, ;xâ = y $
If the final coordinates all have to be positive, as is the case for many image processing contexts, this should be modified to
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ;xâ =1 -y $
For 180 degrees,$ yâ = 1-y, ;xâ =1 - x $
For 270 degrees, $yâ =1 -x, ; xâ = y$
Finally, I note that the order of $x$ and $y$ coordinates that you use (although used in image processing fairly often) are reversed to the standard math convention so be careful if you are searching for other solutions on the internet that you are reading the correctly!
Hope that helps!
add a comment |Â
up vote
1
down vote
Based off Martin Roberts answer, here's my complete solution:
// values in absolute pixels
box = [y_min, x_min, y_max, x_max];
// Make points relative to image
pct = [box[0] / height, box[1] / width, box[2] / height, box[3] / width];
//^
//|
//+--------+
// |
// v
rot90 = [pct[1], 1 - pct[2], pct[3], 1 - pct[0]];
// ^
// |
// +--------+
// |
// v
rot180 = [rot90[1], 1 - rot90[2], rot90[3], 1 - rot90[0]];
// ^
// |
// +--------+
// |
// v
rot270 = [rot180[1], 1 - rot180[2], rot180[3], 1 - rot180[0]];
- As a minor implementation detail, although not all images in my dataset were squares, they were deliberately reshaped to be squares because of the neural network model where they'll be used.
- The reason for the reversed (x, y) points, that's because TensorFlow's tf.image.draw_bounding_boxes expects the points in that order.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
The transformation you require is:
$$ yâ = y cos theta + x sin theta $$
$$xâ = -y sin theta+ x cos theta$$
Also donâÂÂt forget that when programming $ cos theta$ and $ sin theta$ needs to be in radians and not degrees. To convert from degrees to radians multiply by $pi/180$.
You will note that the above formula is greatly simplified if the rotation angles are multiples of $90 deg$.
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ; xâ = -y $
For 180 degrees,$ yâ = -y, ;xâ = - x $
For 270 degrees, $yâ = -x, ;xâ = y $
If the final coordinates all have to be positive, as is the case for many image processing contexts, this should be modified to
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ;xâ =1 -y $
For 180 degrees,$ yâ = 1-y, ;xâ =1 - x $
For 270 degrees, $yâ =1 -x, ; xâ = y$
Finally, I note that the order of $x$ and $y$ coordinates that you use (although used in image processing fairly often) are reversed to the standard math convention so be careful if you are searching for other solutions on the internet that you are reading the correctly!
Hope that helps!
add a comment |Â
up vote
3
down vote
accepted
The transformation you require is:
$$ yâ = y cos theta + x sin theta $$
$$xâ = -y sin theta+ x cos theta$$
Also donâÂÂt forget that when programming $ cos theta$ and $ sin theta$ needs to be in radians and not degrees. To convert from degrees to radians multiply by $pi/180$.
You will note that the above formula is greatly simplified if the rotation angles are multiples of $90 deg$.
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ; xâ = -y $
For 180 degrees,$ yâ = -y, ;xâ = - x $
For 270 degrees, $yâ = -x, ;xâ = y $
If the final coordinates all have to be positive, as is the case for many image processing contexts, this should be modified to
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ;xâ =1 -y $
For 180 degrees,$ yâ = 1-y, ;xâ =1 - x $
For 270 degrees, $yâ =1 -x, ; xâ = y$
Finally, I note that the order of $x$ and $y$ coordinates that you use (although used in image processing fairly often) are reversed to the standard math convention so be careful if you are searching for other solutions on the internet that you are reading the correctly!
Hope that helps!
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
The transformation you require is:
$$ yâ = y cos theta + x sin theta $$
$$xâ = -y sin theta+ x cos theta$$
Also donâÂÂt forget that when programming $ cos theta$ and $ sin theta$ needs to be in radians and not degrees. To convert from degrees to radians multiply by $pi/180$.
You will note that the above formula is greatly simplified if the rotation angles are multiples of $90 deg$.
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ; xâ = -y $
For 180 degrees,$ yâ = -y, ;xâ = - x $
For 270 degrees, $yâ = -x, ;xâ = y $
If the final coordinates all have to be positive, as is the case for many image processing contexts, this should be modified to
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ;xâ =1 -y $
For 180 degrees,$ yâ = 1-y, ;xâ =1 - x $
For 270 degrees, $yâ =1 -x, ; xâ = y$
Finally, I note that the order of $x$ and $y$ coordinates that you use (although used in image processing fairly often) are reversed to the standard math convention so be careful if you are searching for other solutions on the internet that you are reading the correctly!
Hope that helps!
The transformation you require is:
$$ yâ = y cos theta + x sin theta $$
$$xâ = -y sin theta+ x cos theta$$
Also donâÂÂt forget that when programming $ cos theta$ and $ sin theta$ needs to be in radians and not degrees. To convert from degrees to radians multiply by $pi/180$.
You will note that the above formula is greatly simplified if the rotation angles are multiples of $90 deg$.
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ; xâ = -y $
For 180 degrees,$ yâ = -y, ;xâ = - x $
For 270 degrees, $yâ = -x, ;xâ = y $
If the final coordinates all have to be positive, as is the case for many image processing contexts, this should be modified to
For 0 degrees, $yâ = y, ; xâ = x $
For 90 degrees, $ yâ = x, ;xâ =1 -y $
For 180 degrees,$ yâ = 1-y, ;xâ =1 - x $
For 270 degrees, $yâ =1 -x, ; xâ = y$
Finally, I note that the order of $x$ and $y$ coordinates that you use (although used in image processing fairly often) are reversed to the standard math convention so be careful if you are searching for other solutions on the internet that you are reading the correctly!
Hope that helps!
edited Jul 17 at 0:49
answered Jul 17 at 0:00
Martin Roberts
1,189318
1,189318
add a comment |Â
add a comment |Â
up vote
1
down vote
Based off Martin Roberts answer, here's my complete solution:
// values in absolute pixels
box = [y_min, x_min, y_max, x_max];
// Make points relative to image
pct = [box[0] / height, box[1] / width, box[2] / height, box[3] / width];
//^
//|
//+--------+
// |
// v
rot90 = [pct[1], 1 - pct[2], pct[3], 1 - pct[0]];
// ^
// |
// +--------+
// |
// v
rot180 = [rot90[1], 1 - rot90[2], rot90[3], 1 - rot90[0]];
// ^
// |
// +--------+
// |
// v
rot270 = [rot180[1], 1 - rot180[2], rot180[3], 1 - rot180[0]];
- As a minor implementation detail, although not all images in my dataset were squares, they were deliberately reshaped to be squares because of the neural network model where they'll be used.
- The reason for the reversed (x, y) points, that's because TensorFlow's tf.image.draw_bounding_boxes expects the points in that order.
add a comment |Â
up vote
1
down vote
Based off Martin Roberts answer, here's my complete solution:
// values in absolute pixels
box = [y_min, x_min, y_max, x_max];
// Make points relative to image
pct = [box[0] / height, box[1] / width, box[2] / height, box[3] / width];
//^
//|
//+--------+
// |
// v
rot90 = [pct[1], 1 - pct[2], pct[3], 1 - pct[0]];
// ^
// |
// +--------+
// |
// v
rot180 = [rot90[1], 1 - rot90[2], rot90[3], 1 - rot90[0]];
// ^
// |
// +--------+
// |
// v
rot270 = [rot180[1], 1 - rot180[2], rot180[3], 1 - rot180[0]];
- As a minor implementation detail, although not all images in my dataset were squares, they were deliberately reshaped to be squares because of the neural network model where they'll be used.
- The reason for the reversed (x, y) points, that's because TensorFlow's tf.image.draw_bounding_boxes expects the points in that order.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Based off Martin Roberts answer, here's my complete solution:
// values in absolute pixels
box = [y_min, x_min, y_max, x_max];
// Make points relative to image
pct = [box[0] / height, box[1] / width, box[2] / height, box[3] / width];
//^
//|
//+--------+
// |
// v
rot90 = [pct[1], 1 - pct[2], pct[3], 1 - pct[0]];
// ^
// |
// +--------+
// |
// v
rot180 = [rot90[1], 1 - rot90[2], rot90[3], 1 - rot90[0]];
// ^
// |
// +--------+
// |
// v
rot270 = [rot180[1], 1 - rot180[2], rot180[3], 1 - rot180[0]];
- As a minor implementation detail, although not all images in my dataset were squares, they were deliberately reshaped to be squares because of the neural network model where they'll be used.
- The reason for the reversed (x, y) points, that's because TensorFlow's tf.image.draw_bounding_boxes expects the points in that order.
Based off Martin Roberts answer, here's my complete solution:
// values in absolute pixels
box = [y_min, x_min, y_max, x_max];
// Make points relative to image
pct = [box[0] / height, box[1] / width, box[2] / height, box[3] / width];
//^
//|
//+--------+
// |
// v
rot90 = [pct[1], 1 - pct[2], pct[3], 1 - pct[0]];
// ^
// |
// +--------+
// |
// v
rot180 = [rot90[1], 1 - rot90[2], rot90[3], 1 - rot90[0]];
// ^
// |
// +--------+
// |
// v
rot270 = [rot180[1], 1 - rot180[2], rot180[3], 1 - rot180[0]];
- As a minor implementation detail, although not all images in my dataset were squares, they were deliberately reshaped to be squares because of the neural network model where they'll be used.
- The reason for the reversed (x, y) points, that's because TensorFlow's tf.image.draw_bounding_boxes expects the points in that order.
edited Jul 17 at 15:29
answered Jul 17 at 12:17
rodrigo-silveira
1397
1397
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2853667%2fhow-to-rotate-relative-points-in-degrees%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Which software are you using?
â Mostafa Ayaz
Jul 16 at 18:12
I'm wanting to do this by hand, using a pencil and paper.
â rodrigo-silveira
Jul 16 at 19:01
The point of having the box defined relative to the image sides is precisely that you dont need to rotate or scale the box. I.e., whatever rigid transform you do to the image should not affect the box since it is defined relative to the image.
â Mauricio Cele Lopez Belon
Jul 16 at 20:09
I think the relative points is so the box scales if the image scales. But if you rotate the image, the box would need to be rotated as well. Think of a tall, skinny box on the left side of the image, which bounds, say, a stop sign. If you rotate that image 90 degrees, the stop sign is now sideways across the top of the image, so you'd want the bounding box to likewise be rotated such that it is horizontal (wide and not tall) like the object it is bounding on the image.
â rodrigo-silveira
Jul 16 at 21:19