albumentations-team / albumentations

Fast and flexible image augmentation library. Paper about the library: https://www.mdpi.com/2078-2489/11/2/125
https://albumentations.ai
MIT License
14.17k stars 1.64k forks source link

[Bug] Reflection padding does not reflect bounding boxes and keypoints #1904

Open ternaus opened 2 months ago

ternaus commented 2 months ago
saerojw commented 13 hours ago

I found this bug related to reflection border mode (cv2.BORDER_REFLECT, cv2.BORDER_REFLECT_101) in A.Rotate. In the issue I found, there is also a problem with the output shape.

Example:

import numpy as np
import albumentations as A
image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
transform = A.Compose([A.Rotate(limit=45, p=1.0)], keypoint_params=A.KeypointParams(format='xy', remove_invisible=False))
keypoints = np.random.randint(0, 100, (30, 2)).astype(dtype=np.float32)
result = transform(image=image, keypoints=keypoints)
rotated_image, rotated_keypoints = result['image'], result['keypoints']

rotated_keypoints.shape is not (30, 2) but (270, 2). As far as I checked, the size increases by 9x.

I see you were already tracking this issue, thanks for your work.

ternaus commented 6 hours ago

When you use reflection padding, you may expect that the number of keypoints will go up, as new points are added in the padded regions.