hityzy1122 / opencv_transforms_torchvision

opencv reimplement for transforms in torchvision
MIT License
193 stars 29 forks source link

padding: channel of image is 3 but length of fill is 1 #3

Open Domibor opened 5 years ago

Domibor commented 5 years ago

Problem: Padding does not work when fill is a scalar, but the image is RGB.

What happens: Using a scalar for fill in combination with an RGB image crashes. cvfunctional.pad() assumes a fill of length 3 for an RGB image, but the default value of cvtransforms.Pad() is 0 (length 1).

What should happen: If fill is a scaler, it should be used for all 3 channels.

hityzy1122 commented 5 years ago

Problem: Padding does not work when fill is a scalar, but the image is RGB.

What happens: Using a scalar for fill in combination with an RGB image crashes. cvfunctional.pad() assumes a fill of length 3 for an RGB image, but the default value of cvtransforms.Pad() is 0 (length 1).

What should happen: If fill is a scaler, it should be used for all 3 channels.

I think I have fixed some bugs as your suggestion. Thanks a lot!

buptlj commented 5 years ago

here is a bug: `

if isinstance(fill, numbers.Number): fill = fill, if isinstance(fill, numbers.Number) and len(img.shape) == 3: fill = (fill,) * 3

` the type of fill is changed in line 2.

第二行改变了fill的类型,变成tuple了,即使img.shape是3,第四行也不会执行了。

hityzy1122 commented 5 years ago

here is a bug: `

if isinstance(fill, numbers.Number): fill = fill, if isinstance(fill, numbers.Number) and len(img.shape) == 3: fill = (fill,) * 3

` the type of fill is changed in line 2.

第二行改变了fill的类型,变成tuple了,即使img.shape是3,第四行也不会执行了。

Thanks ! I hope I have fixed this bug properly ^^. 谢谢,我希望我已经修改好了这个问题^^