keras-team / keras-preprocessing

Utilities for working with image data, text data, and sequence data.
Other
1.02k stars 444 forks source link

apply_affine_transform() confuses between X and Y #315

Closed eli-osherovich closed 3 years ago

eli-osherovich commented 3 years ago

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or on the Keras Slack channel instead of opening a GitHub issue.

Thank you!

It seems that apply_affine_transform() confuses the axes X and Y. X should be horizontal, whereas Y - vertical. However, current implementation treats X as the first dimension (height), and Y as the second dimension (width) which not only contradicts the common sense but also the documentation.

A very simple example: the image moves vertically (rather than horizontally) even though ty=0 and tx !=0

import numpy as np
from keras_preprocessing.image import apply_affine_transform

x = np.array([
    [1, 1, 1],
    [2, 2, 2],
    [3, 3, 3],
])
np.squeeze(apply_affine_transform(np.expand_dims(x, -1), tx=1))

array([[2, 2, 2],
       [3, 3, 3],
       [3, 3, 3]])
eli-osherovich commented 3 years ago

This confusion is not specific to translation -- it happens in all transformations.