albumentations icon indicating copy to clipboard operation
albumentations copied to clipboard

PadIfNeeded does not pad correclty when using additional targets

Open mikel-brostrom opened this issue 2 years ago • 2 comments

🐛 Bug

A.geometric.transforms.PadIfNeeded does not work for the additional images

To Reproduce

Steps to reproduce the behavior:

import cv2
import numpy as np
import albumentations as A


imgsz=640
image0 = cv2.imread('./images/train2017/000000000139.jpg')
image1 = cv2.imread('./images/train2017/000000000285.jpg')

print('image0', image0.shape)
print('image1', image1.shape)

transform1 = A.Compose(
    [
        A.geometric.transforms.PadIfNeeded(imgsz, imgsz, border_mode=0, value=(114, 114, 114)),
    ],
    additional_targets={
        'image1': 'image',
    },
)

transformed1 = transform1(
    image=image0,
    image1=image1,
)

image0_transformed = transformed1['image']
image1_transformed = transformed1['image1']

print('image0 transformed', image0_transformed.shape)
print('image1 transformed', image1_transformed.shape)

Output:

image0 (426, 640, 3)
image1 (640, 586, 3)
image0 transformed (640, 640, 3)
image1 transformed (854, 586, 3)

Expected behavior

Padding should work for the additional images as well

image0 (426, 640, 3)
image1 (640, 586, 3)
image0 transformed (640, 640, 3)
image1 transformed (640, 640, 3)

Environment

  • Albumentations version (e.g., 0.1.8): 1.3.0
  • Python version (e.g., 3.7): 3.8
  • OS (e.g., Linux): Linux
  • How you installed albumentations (conda, pip, source): pip

mikel-brostrom avatar Feb 22 '23 13:02 mikel-brostrom

This seems to be similar to https://github.com/albumentations-team/albumentations/issues/716

mikel-brostrom avatar Feb 22 '23 14:02 mikel-brostrom

This: https://github.com/albumentations-team/albumentations/issues/716#issuecomment-760723917 didn't fix it for me

mikel-brostrom avatar Feb 22 '23 14:02 mikel-brostrom