aleju / imgaug

Image augmentation for machine learning experiments.
http://imgaug.readthedocs.io
MIT License
14.42k stars 2.44k forks source link

Incorrect rotation of segmentation map when mode="symmetric" #815

Open gui-miotto opened 2 years ago

gui-miotto commented 2 years ago

When applying a rotation with symmetric mode (i.e. padding mode) the segmentation map is not mirrored accordingly. The rotation of the map is fine, just its padding is missing.

Reproduction I modified one of your examples to demonstrate the problem:

import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
from imgaug.augmentables.segmaps import SegmentationMapsOnImage
import matplotlib.pyplot as plt

# Load an example image (uint8, 128x128x3).
image = ia.quokka(size=(128, 128), extract="square")

# Define an example segmentation map (int32, 128x128).
# Here, we arbitrarily place some squares on the image.
# Class 0 is our intended background class.
segmap = np.zeros((128, 128, 1), dtype=np.int32)
segmap[28:71, 35:85, 0] = 1
segmap[10:25, 30:45, 0] = 2
segmap[10:25, 70:85, 0] = 3
segmap[10:110, 5:10, 0] = 4
segmap[118:123, 10:110, 0] = 5
segmap = SegmentationMapsOnImage(segmap, shape=image.shape)

# Define our augmentation pipeline.
seq = iaa.Sequential([
    iaa.Affine(rotate=-45, mode="symmetric"),  # if we don't use mode="symmetric", the final result is correct.
])

image_aug, segmaps_aug = seq(image=image, segmentation_maps=segmap)

overlay = segmaps_aug.draw_on_image(image_aug)[0]
plt.imshow(overlay)
plt.show()

Result seg_problem

Expected result seg_problem_correct