mdbloice / Augmentor

Image augmentation library in Python for machine learning.
https://augmentor.readthedocs.io/en/stable
MIT License
5.08k stars 866 forks source link

Reproducible issue: black image (all pixels are zero) after rotate #31

Open yunqing opened 7 years ago

yunqing commented 7 years ago
from skimage import io
import Augmentor.Operations as ops
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt

sample = io.imread('train.jpg')
rotate = ops.RotateRange(probability=1, max_left_rotation=50, max_right_rotation=10)

for i in range(6):
  img_ro = np.array(rotate.perform_operation(Image.fromarray(sample)))
  plt.imshow(img_ro)
  plt.show()

Sometimes, you can get a black image after rotate the image.

mdbloice commented 7 years ago

Hi, thanks for opening the issue, I think the problem there is that you are applying a max_left_rotation of 50 and that may well result in a malformed image due to the way Augmentor performs cropping on the rotated images by default.

This is because Augmentor rotates and then extracts the maximum crop possible of the same dimensions as the input image, and depending on the dimensions of this input image and the rotation applied, you may not get valid images as output.

Take a look at http://augmentor.readthedocs.io/en/master/code.html#Augmentor.Pipeline.Pipeline.rotate.