dgs.utils.image.CustomToAspect¶
- class dgs.utils.image.CustomToAspect(*args: Any, **kwargs: Any)[source]¶
Custom torchvision Transform that modifies the image, bboxes, and coordinates simultaneously to match a target aspect ratio.
Notes
It is expected that Resize() is called after this transform, to not only match the aspect ratio but also the overall size.
This transforms’ default mode is zero-padding.
The following modes are available for resizing:
- distort
Skips CustomToAspect entirely and therefore does not change the original aspect ratio at all. This will result in a distorted image when using Resize(), iff the aspect ratios of the old and new shape aren’t close.
- edge-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is edge.
- inside-crop
Uses the target aspect ratio to extract a sub-image out of the original. Basically is a center crop with one dimension being as large as possible while maintaining the aspect ratio.
- outside-crop
Is only available for the CustomCrop() model, but will be passed through. Instead of cropping at the exact bounding box, match the aspect ratio by widening one of the dimensions
- fill-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is constant and the fill value has to be provided within the kwargs.
- mean-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is constant with a fill value as the RGB mean of the image.
- reflect-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is reflect.
- symmetric-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is symmetric.
- zero-pad
Uses Pad() to extend the image to the correct aspect ratio. The value used for padding_mode of Pad() is constant with a value of zero.