Skip to content

rotate an image for data augmentation #781

Closed

Description

@benstaf

Activity

  1. bhack commented on Jan 15, 2016

    @bhack
    Contributor

    I will extend this request to more transformation like BVLC/caffe#2252

  2. bhack commented on Jan 15, 2016

    @bhack
    Contributor

    /cc @ducha-aiki if interested to follow this.

  3. ducha-aiki commented on Jan 15, 2016

    @ducha-aiki

    @bhack thanks! Actually, I could think about implementing it...but need to get time for at least installing TF.

  4. jkschin commented on Jan 15, 2016

    @jkschin

    @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.

  5. ducha-aiki commented on Jan 15, 2016

    @ducha-aiki

    @jkschin not now, so you can try first :)

    Should I implement it first then send a pull request?

    Yes, usually it is done like this.

  6. jkschin commented on Jan 15, 2016

    @jkschin

    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.

  7. ducha-aiki commented on Jan 15, 2016

    @ducha-aiki

    @jkschin There is a little discussion about it in BVLC/caffe#2252
    The following ones are implemented in different libraries:

    • pad with zeros
    • pad with random noise
    • pad with mean pixel (nice for images)
    • pad with border mirroring.
  8. jkschin commented on Jan 15, 2016

    @jkschin

    @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?

  9. ducha-aiki commented on Jan 15, 2016

    @ducha-aiki

    @jkschin TensorFlow is very flexible instrument, so rectangular as well.

  10. bhack commented on Jan 15, 2016

    @bhack
    Contributor

    Probably we'll need also GPU ops version at some point like #588

  11. cesarsalgado commented on Jan 18, 2016

    @cesarsalgado
    Contributor

    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.

  12. sdemyanov commented on Jun 9, 2016

    @sdemyanov

    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.

  13. 57 remaining items

  14. ringw commented on Feb 2, 2018

    @ringw
    Contributor

    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_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]
    
  15. aselle commented on Feb 7, 2018

    @aselle
    Contributor

    Closing since this issue appears to be resolved with tf.contrib.rotate() and the matrix conversion routines. Thanks @ringw.

  16. S-aiueo32 commented on Mar 6, 2019

    @S-aiueo32

    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.

  17. ringw commented on Mar 15, 2019

    @ringw
    Contributor
  18. richriley commented on Jul 2, 2019

    @richriley

    I want TF to contain native rotate() or random_rotate() under tf.image.

    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.

  19. JasonMts commented on Jul 9, 2019

    @JasonMts

    This should be added natively to tf 2.0.

  20. ahundt commented on Jul 9, 2019

    @ahundt
    Contributor

    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

  21. added a commit that references this issue on Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions