SmallestMaxSize
Rescale an image so that minimum side is equal to max_size or sides meet max_size_hw constraints, keeping the aspect ratio.
max_sizeMaximum size of smallest side of the image after the transformation. When using a list, max size will be randomly selected from the values in the list. Default: None.
max_size_hwMaximum (height, width) constraints. Supports:
- (height, width): Both dimensions must be at least these values
- (height, None): Only height is constrained, width scales proportionally
- (None, width): Only width is constrained, height scales proportionally If specified, max_size must be None. Default: None.
interpolationFlag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.
mask_interpolationflag that is used to specify the interpolation algorithm for mask. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_NEAREST.
area_for_downscaleControls automatic use of INTER_AREA interpolation for downscaling. Options:
- None: No automatic interpolation selection, always use the specified interpolation method
- "image": Use INTER_AREA when downscaling images, retain specified interpolation for upscaling and masks
- "image_mask": Use INTER_AREA when downscaling both images and masks Default: None.
pProbability of applying the transform. Default: 1.
>>> import numpy as np
>>> import albumentations as A
>>> # Using max_size
>>> transform1 = A.SmallestMaxSize(max_size=120, area_for_downscale="image")
>>> # Input image (100, 150) -> Output (120, 180)
>>>
>>> # Using max_size_hw with both dimensions
>>> transform2 = A.SmallestMaxSize(max_size_hw=(100, 200), area_for_downscale="image_mask")
>>> # Input (80, 160) -> Output (100, 200)
>>> # Input (160, 80) -> Output (400, 200)
>>>
>>> # Using max_size_hw with only height
>>> transform3 = A.SmallestMaxSize(max_size_hw=(100, None))
>>> # Input (80, 160) -> Output (100, 200)- This transform scales images based on their smallest side:
- If the smallest side is smaller than max_size: the image will be upscaled (scale > 1.0)
- If the smallest side is equal to max_size: the image will not be resized (scale = 1.0)
- If the smallest side is larger than max_size: the image will be downscaled (scale < 1.0)
- This transform will not crop the image. The resulting image may be larger than specified in both dimensions.
- For non-square images, both sides will be scaled proportionally to maintain the aspect ratio.
- Bounding boxes and keypoints are scaled accordingly.
- When area_for_downscale is set, INTER_AREA will be used for downscaling, providing better quality.