DALI
DALI copied to clipboard
How to pad left or top to a image?
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!
Hi @DatCanCode,
There is no direct OpenCV copyMakeBorder
counterpart in DALI. What you can try is:
- check the paste operator
- write your own operator using this guide
Hello, we have similar needs, is this solved now?
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)
(the scale is not preserved in the above screenshot).
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