DALI icon indicating copy to clipboard operation
DALI copied to clipboard

How to pad left or top to a image?

Open DatCanCode opened this issue 3 years ago • 4 comments

In opencv there's a function call copyMakeBorder that can pad solid color to 4 sides around an image:

cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)

but in DALI I found that nvidia.dali.fn.pad function only pad to right/bottom. I want to pad to 4 sides around an image with out padding, then flip, then pad and flip back. How can I do that in DALI. Thank you!

DatCanCode avatar Aug 05 '21 03:08 DatCanCode

Hi @DatCanCode,

There is no direct OpenCV copyMakeBorder counterpart in DALI. What you can try is:

JanuszL avatar Aug 05 '21 07:08 JanuszL

Hello, we have similar needs, is this solved now?

wangchengdng avatar Jun 08 '22 09:06 wangchengdng

Hi @wangchengdng,

If the constant border is what you are looking for you can use the slice operator for it:

images_pad = fn.slice(images, (-0.3, -0.3), (1.6, 1.6), out_of_bounds_policy="pad", normalized_shape=True, normalized_anchor=True)

image (the scale is not preserved in the above screenshot).

JanuszL avatar Jun 08 '22 10:06 JanuszL

I'd add that you can also control the value used for padding with fill_value, and that you can use absolute coordinates for slice arguments as well. You can see the full documentation here: https://docs.nvidia.com/deeplearning/dali/user-guide/docs/operations/nvidia.dali.fn.slice.html

jantonguirao avatar Jun 08 '22 11:06 jantonguirao