Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical Shearing #361

Closed
pigubaoza opened this issue Jul 17, 2019 · 1 comment · Fixed by #482
Closed

Vertical Shearing #361

pigubaoza opened this issue Jul 17, 2019 · 1 comment · Fixed by #482

Comments

@pigubaoza
Copy link

Right now the affine shear function does a horizontal shear. Are there plans to add shearing in the vertical direction? Or is there another way of doing it?

@aleju
Copy link
Owner

aleju commented Jul 18, 2019

That is currently not in the library.
You could hack it by subclassing imgaug.augmenters.geometric.Affine. Assuming that you use the cv2 backend in Affine, you would have to overwrite the method Affine._warp_cv2(...). Most of the code would be completely identical with the current code of the method, but the generation of the affine transformation matrix

matrix_to_topleft = tf.SimilarityTransform(translation=[-shift_x, -shift_y])
matrix_transforms = tf.AffineTransform(
    scale=(scale_x, scale_y),
    translation=(translate_x_px, translate_y_px),
    rotation=math.radians(rotate),
    shear=math.radians(shear)
)
matrix_to_center = tf.SimilarityTransform(translation=[shift_x, shift_y])
matrix = (matrix_to_topleft + matrix_transforms + matrix_to_center)

would have to be changed.

scikit-image's transform.AffineTransform (documentation) only supports shearing in horizontal direction, but I think you could get vertical direction by computing

  1. the affine transformation matrix to rotate by -90°
  2. the affine transformation matrix to apply the desired shearing in degrees (in horizontal direction)
  3. the affine transformation matrix to rotate by +90°
  4. the affine transformation matrix to apply the remaining parameters (same as in the code block above, but without shearing)

These matrices could then be multiplied to get the final affine transformation matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants