keras-team/keras-preprocessing

apply_affine_transform() confuses between X and Y

eli-osherovich opened this issue · 1 comments

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!

  • Check that you are up-to-date with the master branch of keras-preprocessing. You can update with:
    pip install git+git://github.com/keras-team/keras-preprocessing.git --upgrade --no-deps

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

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]])

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