Scaling
Downscale
Downscale images based on edge length constraints. The node supports two mutually exclusive modes:
- max_edge: Downscales images only if their largest edge exceeds the specified value
- min_edge: Downscales images so their smallest edge equals exactly the specified value
Images that don't meet the criteria for downscaling are left unchanged.
DownscaleMethod.PIL uses the LANCZOS resampling filter.
Parameters
method(default=DownscaleMethod.PIL): The method to use for downscaling (currently onlyDownscaleMethod.PILis supported)max_edge(optional): The maximum edge length - scales down only if image's largest edge is largermin_edge(optional): The minimum edge length - scales down to make smallest edge exactly this sizeformat(default='PNG'): The format to save the downscaled images in (e.g.,'PNG','JPEG','WEBP')
Note: You must specify exactly one of max_edge or min_edge. They are mutually exclusive.
Output properties
image.width: The width of the image after downscalingimage.height: The height of the image after downscalingimage.format: The format of the image after downscalingimage.objectid: The object ID of the image after downscalingimage.downscale_info: Dictionary containing scaling information:method: The scaling method usedmax_edgeormin_edge: The edge constraint valueoriginal_width: Width before scalingoriginal_height: Height before scalingscaled_width: Width after scalingscaled_height: Height after scaling
Examples
# Downscale images so that the max edge of any image is 1024px
dataset >> Downscale(max_edge=1024)
# Downscale images so that the minimum edge is exactly 512px
dataset >> Downscale(min_edge=512)
# Downscale to minimum edge of 768px and save as JPEG
dataset >> Downscale(min_edge=768, format='JPEG')
Behavior Details
With max_edge:
- If the largest dimension is already ≤ max_edge, the image is unchanged
- Otherwise, scales down proportionally so the largest dimension equals max_edge
With min_edge:
- If the smallest dimension is already ≤ min_edge, the image is unchanged
- Otherwise, scales down proportionally so the smallest dimension equals min_edge
- Useful for ensuring consistent minimum resolutions after cropping
Upscale
Upsample images where their longest edge is less than min_edge. Images that are already large enough are not modified.
UpscaleMethod.PIL uses the LANCZOS resampling filter.
UpscaleMethod.SWINIR uses the SwinIR neural network model for high-quality upscaling.
NOTE: ESRGAN is partially implemented, but it requires hacks to work because of bugs in basicsr. There is a plan to work around this on our side, but it is not done yet.
Parameters
method(default=UpscaleMethod.PIL): The method to use for upscaling:UpscaleMethod.PIL: Fast CPU-based upscaling using LANCZOS filterUpscaleMethod.SWINIR: High-quality GPU-based upscaling using SwinIR neural networkmin_edge(default=1024): The minimum edge length for the upscalingformat(default='PNG'): The format to save the upscaled images in (e.g.,'PNG','JPEG','WEBP')
Output properties
image.width: The width of the image after upscalingimage.height: The height of the image after upscalingimage.format: The format of the image after upscalingimage.objectid: The object ID of the image after upscaling
Example
# Upscale images so that the min edge of any image is 1024px
dataset >> Upscale(min_edge=1024)