albumentations icon indicating copy to clipboard operation
albumentations copied to clipboard

`CropAndPad` interpolation doesn't default to `INTER_NEAREST` for masks

Open NickLucche opened this issue 2 years ago • 1 comments

🐛 Bug

Interpolation mode for masks should default to INTER_NEAREST when CropAndPad is applied to masks.

To Reproduce

t = A.CropAndPad(percent=(-0.25, 0.25), p=1)
x = np.random.randn(80, 80).astype(np.uint8)
x[x>0] = 255
xx = t(image=x, mask=x)['mask']
np.unique(xx) # 0 1 2 .. 255

Expected behavior

t = A.CropAndPad(percent=(-0.25, 0.25), interpolation=cv2.INTER_NEAREST)
xx = t(image=x, mask=x)['mask']
np.unique(xx) # 0, 255

Environment

  • Albumentations version: 1.1.0
  • Python version (e.g., 3.7): 3.9.5
  • OS (e.g., Linux): Ubuntu 21.04
  • How you installed albumentations (conda, pip, source): pip install -U albumentations
  • Any other relevant information:

NickLucche avatar Mar 14 '22 13:03 NickLucche

Related with #850

johnnv1 avatar Mar 18 '22 16:03 johnnv1