You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ducha-aiki are you going to implement it? I'm interested to contribute this functionality.
Should I implement it first then send a pull request? Or is someone going to be assigned this. Sorry for the questions. I'm new to how contributions work.
Alright. What I intend to do would be to first implement some form of smart padding, so not much information is lost. If we look at python PIL, when we rotate the image, some parts are left black. We just have to pad the image by a scale of sqrt(2), do a rotation, find the center and extract the same sized square.
This is how I intend to do it, suggestions and improvements are welcome!
EDIT: Or should I just implement a no-frills rotate first? Parts will be blacked out.
What about the case when we get, for example, an 256x256 image and we want to extract a random rotated 224x224 crop from WITHIN the image? In this case we don't need padding. Should we have in mind this use case?
Off course, not all rotation angles will be available depending on the original images size and on the target rotated crop size, and also depending where the center of the crop was randomly chosen.
It would be reasonable to allow to specify the size of rotated image, extracted from the original one, and throw an error if the some parts of it lie outside the original image. Additionally a user can specify the default pixel value to fill in the outside areas. In this case an error is not thrown. I had an implementation of a Transform function, that performed all flipping, translation, rotation and scaling in a single function. Maybe some code from there still can be useful.
Yes, the identity in our representation is [1, 0, 0, 0, 1, 0, 0, 0] which corresponds to the 3x3 identity matrix. Makes sense to add an identity_projective_transform helper!
I think we can make _flat_transforms_to_matrices, etc, public too. The catch is that the matrix transforms output coordinates to input coordinates, because at each output pixel, we compute the input pixel to read from. So you would probably need to call tf.linalg.inv on the projection matrix.
I think tf.transpose doesn't do anything to 1D tensors, and * does elementwise multiplication, so I would recommend:
# transform_matrix is an
# 8 element projective transform matrix
t = transform_matrix
# Always creates batches of matrices
reverse_transform = tf.contrib.image.flat_transforms_to_matrices(t)[0, :, :]
forward_transform = tf.linalg.inv(reverse_transform)
coordinate = tf.transpose([[coordinate[0], coordinate[1], 1]])
output_coordinate = tf.matmul(forward_transform, coordinate)
output_coordinate = coordinate[:2, 0]
After removal of tf.contrib on TF2.0, this issue will rise again.
What is the recommended way for random rotation on TF2.0? tf.keras.preprocessing.image.random_rotation doesn't work under @tf.function without users' effort.
I want TF to contain native rotate() or random_rotate() under tf.image.
Reacted by Mazharul Hossain, doantientai, Radek Svoboda, Rich, Iason Myttas, Drew Arad Hudson, [email protected], Frank Lin, iszotic, Maciej (MJ) Mikulski and 12 more
Activity
bhack commentedon Jan 15, 2016
I will extend this request to more transformation like BVLC/caffe#2252
bhack commentedon Jan 15, 2016
/cc @ducha-aiki if interested to follow this.
ducha-aiki commentedon Jan 15, 2016
@bhack thanks! Actually, I could think about implementing it...but need to get time for at least installing TF.
jkschin commentedon Jan 15, 2016
@ducha-aiki are you going to implement it? I'm interested to contribute this functionality.
Should I implement it first then send a pull request? Or is someone going to be assigned this. Sorry for the questions. I'm new to how contributions work.
ducha-aiki commentedon Jan 15, 2016
@jkschin not now, so you can try first :)
Yes, usually it is done like this.
jkschin commentedon Jan 15, 2016
Alright. What I intend to do would be to first implement some form of smart padding, so not much information is lost. If we look at python PIL, when we rotate the image, some parts are left black. We just have to pad the image by a scale of sqrt(2), do a rotation, find the center and extract the same sized square.
This is how I intend to do it, suggestions and improvements are welcome!
EDIT: Or should I just implement a no-frills rotate first? Parts will be blacked out.
ducha-aiki commentedon Jan 15, 2016
@jkschin There is a little discussion about it in BVLC/caffe#2252
The following ones are implemented in different libraries:
jkschin commentedon Jan 15, 2016
@ducha-aiki thanks!
Another question. Is it practice to assume a square image? Or do we have to factor in rectangular use cases as well?
ducha-aiki commentedon Jan 15, 2016
@jkschin TensorFlow is very flexible instrument, so rectangular as well.
bhack commentedon Jan 15, 2016
Probably we'll need also GPU ops version at some point like #588
cesarsalgado commentedon Jan 18, 2016
What about the case when we get, for example, an 256x256 image and we want to extract a random rotated 224x224 crop from WITHIN the image? In this case we don't need padding. Should we have in mind this use case?
Off course, not all rotation angles will be available depending on the original images size and on the target rotated crop size, and also depending where the center of the crop was randomly chosen.
sdemyanov commentedon Jun 9, 2016
It would be reasonable to allow to specify the size of rotated image, extracted from the original one, and throw an error if the some parts of it lie outside the original image. Additionally a user can specify the default pixel value to fill in the outside areas. In this case an error is not thrown. I had an implementation of a Transform function, that performed all flipping, translation, rotation and scaling in a single function. Maybe some code from there still can be useful.
57 remaining items
ringw commentedon Feb 2, 2018
Thanks Andrew!
Yes, the identity in our representation is [1, 0, 0, 0, 1, 0, 0, 0] which corresponds to the 3x3 identity matrix. Makes sense to add an
identity_projective_transformhelper!I think we can make
_flat_transforms_to_matrices, etc, public too. The catch is that the matrix transforms output coordinates to input coordinates, because at each output pixel, we compute the input pixel to read from. So you would probably need to calltf.linalg.invon theprojectionmatrix.I think tf.transpose doesn't do anything to 1D tensors, and
*does elementwise multiplication, so I would recommend:Make flat_transforms_to_matrices and matrices_to_flat_transforms publ…
aselle commentedon Feb 7, 2018
Closing since this issue appears to be resolved with tf.contrib.rotate() and the matrix conversion routines. Thanks @ringw.
S-aiueo32 commentedon Mar 6, 2019
After removal of
tf.contribon TF2.0, this issue will rise again.What is the recommended way for random rotation on TF2.0?
tf.keras.preprocessing.image.random_rotationdoesn't work under@tf.functionwithout users' effort.I want TF to contain native
rotate()orrandom_rotate()undertf.image.ringw commentedon Mar 15, 2019
Image transformations have moved to tensorflow_addons (https://github.com/tensorflow/addons/tree/master/tensorflow_addons/image).
richriley commentedon Jul 2, 2019
I agree. It doesn't seem right to me that something so basic as being able to rotate an image isn't included natively within TensorFlow.
JasonMts commentedon Jul 9, 2019
This should be added natively to tf 2.0.
ahundt commentedon Jul 9, 2019
Just a reference note for those that come across this, be sure to check if this is fixed or if it matters for your application:
https://hackernoon.com/how-tensorflows-tf-image-resize-stole-60-days-of-my-life-aba5eb093f35
Merge pull request tensorflow#781 from ROCmSoftwarePlatform/develop-u…
Update XNNPACK in tensorflow/xla
Update XNNPACK in tensorflow/xla
Update XNNPACK in tensorflow/xla
Update XNNPACK in tensorflow/xla
Update XNNPACK in tensorflow/xla