Nodes/ComfyUI-UniversalToolkit/Image Crop By Mask And Resize (UTK)
ComfyUI Node

Image Crop By Mask And Resize (UTK)

Crops images based on mask detection and resizes to target resolution with multiple methods. This node processes batches of images and masks, ensuring all outputs have consistent dimensions. It uses a three-stage approach: 1. **Analysis Stage**: Detect crop regions for each mask individually 2. **Unification Stage**: Calculate optimal unified dimensions 3. **Processing Stage**: Crop all images with unified dimensions and resize Resize Methods: - **fill**: Scale to completely fill target size (may crop edges) - **crop**: Scale to fit within target size, center and pad with black - **letterbox**: Scale to fit within target size, add black bars to maintain aspect ratio - **stretch**: Directly stretch to target size (may distort aspect ratio) Features: - **Batch Processing**: Handles multiple images and masks correctly - **16-pixel Alignment**: Ensures dimensions are divisible by 16 (AI-friendly) - **Multiple Resize Methods**: Choose the best method for your use case - **Quality Upscaling**: Support for nearest, bilinear, bicubic, and Lanczos - **Flexible Constraints**: Min/max crop resolution limits Parameters: - **base_resolution**: Target resolution for the longer side - **padding**: Extra padding around detected regions - **min/max_crop_resolution**: Constraints for crop region size - **resize_method**: How to handle aspect ratio when resizing - **upscale_method**: Interpolation method for high-quality scaling

By whmc76·Created about a year ago·Updated 24 days ago· 70
Image Crop By Mask And Resize (UTK)
  • image
  • mask
  • images
  • masks
  • bbox
base_resolution512
padding0
min_crop_resolution128
max_crop_resolution512
resize_methodfill
upscale_methodlanczos
CategoryUniversalToolkit/Image

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
maskMASK
base_resolutionINT51264–16384
paddingINT00–16384
min_crop_resolutionINT12864–16384
max_crop_resolutionINT51264–16384
resize_methodCOMBOfillMethod for resizing to target resolution
upscale_methodCOMBOlanczosInterpolation method for upscaling

Outputs (3)

NameTypeDescription
imagesIMAGE
masksMASK
bboxBBOX