feat(float): 新增 Float Mask Area Ratio,输出遮罩覆盖整幅图像的面积比例(0–1 浮点数):软值按权重计算、批次取平均、越界先钳制,None / 空张量 / 非遮罩输入返回 0.0,round(0–10,默认 2)控制小数位,前端在 float 输出上直接显示数值。 feat(text): 新增 Text System Prompt,把 utils/system_prompt/ 下的每个 .txt 作为 <模型>/[<语言>] <名称> 下拉项并原样输出正文;键表启动时扫描一次、正文按 mtime 热更新、_ / . 前缀跳过,目录为空或键不存在返回 ""。内置 Qwen-Image-2.1 t2i / edit 提示词改编自 benjiyaya/ComfyUI-Qwen-Image-2.1-Prompt-Enhancer(MIT)。 feat(image): Image Crop With BBox Mask 的 auto 预设改为自适应构图:先忽略稀疏噪点,比例与最近标准比例线性偏差 ≤30% 时才吸附,对齐后的框必然放进原图;scale_strength 改为取景权重,0 贴遮罩、1 近似全图,宽高各自按对数过渡。 feat(util): Range Mapping 的小数位输入 rounding 更名为 round(范围 0–10、默认 3 不变),与新浮点节点统一,旧工作流该参数回落到默认值。 refactor(shared): 把成对像素颜色估计迁到 utils/_color_fit.py 并由 Image Align Change Mask 复用,结构采样、增益/偏置上限与留出验证收敛到一处,校正幅度保持原包络。 refactor(pad): 统一 Image Pad By BBox Mask、Image Edge Crop/Pad、Multi Image Batch、Multi Image Stitch、Multi Video Stitch、Image Main Stitch、Image Edit Stitch、Image Resize Universal / Area 与 Image Minimum Area 的 pad_color 空值语义:留空或 transparent 一律输出 RGBA(3 通道扩为 4 通道,原内容不透明、补边 (0,0,0,0);resize 系列 crop / stretch 不补边仍为 RGB),resize 系列空值底色不再回落黑色。 test: 新增颜色拟合内核、Float Mask Area Ratio、Text System Prompt、auto 取景链路(噪点、长条图、比例吸附、divisible_by、scale_strength 过渡、贴边主体平移、批次)以及空值 / transparent 补边的回归测试。 docs: 新增两个新节点的中英文文档,更新 Image Crop With BBox Mask / Range Mapping 等 21 份文档,README 节点列表新增「浮点节点」分区并在致谢标注内置提示词来源。 chore(release): 版本号升至 4.4.0。
5.2 KiB
5.2 KiB
Image Crop With BBox Mask
Node Purpose: Intelligently crops images based on the mask's bounding box. Supports various aspect ratio controls, size constraints, and batch processing. Outputs the cropped image, corresponding mask, and the bounding box mask of the original position for easy restoration.
Inputs
| Name | Port | Type | Default | Range | Description |
|---|---|---|---|---|---|
image |
Required | IMAGE | - | - | Original image to be cropped |
mask |
Required | MASK | - | - | Mask defining the subject to crop |
preset_ratio |
- | COMBO | mask |
mask / image / auto / 9:16 / 2:3 / 3:4 / 4:5 / 1:1 / 5:4 / 4:3 / 3:2 / 16:9 / 21:9 |
Target aspect ratio preset. mask follows mask; image follows original; auto frames from the mask itself (ignores stray specks, scale_strength goes from mask-tight to almost the whole image) |
get_crop_ratio |
Optional | IMAGE | - | - | Optional reference image. If connected, auto-matches its aspect ratio, overriding preset_ratio |
scale_strength |
- | FLOAT | 0.0 | 0.0-1.0 | Scale strength. Under auto, 0 just contains the mask and 1 is the whole image, blending geometrically in between; the other modes step through their size ladder; ignored when crop_to_side is not None |
crop_to_side |
- | COMBO | None |
None / longest / shortest / width / height |
Target side control mode |
crop_to_length |
- | INT | 1024 | 8-8192 | Target side length value |
divisible_by |
- | INT | 8 | 1-1024 | Output size divisor constraint (often for model alignment) |
Outputs
| Name | Type | Description |
|---|---|---|
cropped_image |
IMAGE | Cropped and resized image |
bbox_mask |
MASK | Mask in original image dimensions, white area indicating where the crop occurred |
cropped_mask |
MASK | Mask corresponding to the cropped image |
Features
- Smart Ratio Control:
mask: Fits the subject mask ratio as closely as possible.auto: Frames from the mask, so long strips and dirty masks still work —- sparse outliers are ignored first: only edges 10x lighter than the densest row/column and within 1% of the total mass are dropped, so a solid subject's edges are never shaved;
- the de-speckled bbox ratio is the base: it snaps to the nearest standard ratio only when the linear mismatch is within 30% (giving tidy 4:3 / 16:9 frames), otherwise the mask ratio is kept, so a thin subject is not letterboxed into a 16:9 sliver;
- the smallest crop box just contains the bbox (aligned to
divisible_by) and always fits inside the image, unlike a fixed ratio that silently returns the whole frame when it cannot fit; scale_strengthis a framing weight:0just contains the mask (mask ratio, subject fills the frame),1is the largest aligned box the image can provide (≈ the whole image, image ratio); in between it zooms geometrically (every 0.1 is a fixed multiplier) with width and height interpolated separately, so the ratio blends smoothly from the mask ratio to the image ratio. Example: a 431px circle in a 1663×521 frame withdivisible_by=32gives 448×448, 864×480 and 1632×512 at0/0.5/1;- the crop is centred on the mask bbox and shifted back inside the image, so a subject near an edge automatically gains context on the empty side;
crop_to_side/crop_to_lengthtake over the size whenever they are notNone(still using the auto ratio ladder), andscale_strengthis then ignored.
get_crop_ratio: Dynamically sets target ratio via input image.
- Size Constraints & Adjustment:
scale_strength: underauto,0→1goes from a mask-tight crop to (almost) the whole image while the ratio blends along; the other modes keep their ratio and only expand outwards.crop_to_side/crop_to_length: Directly controls physical output resolution (e.g., fix long side to 1024).divisible_by: Ensures output dimensions are multiples of a specific value (e.g., 8 for SDXL).
- Batch Processing: Supports batch inputs for Image and Mask, automatically broadcasting if batch sizes differ.
Typical Usage
- Inpainting Preprocessing: Crop subject using mask for local upscaling or repainting, then use
bbox_maskto paste back. - Dataset Preparation: Batch crop subjects from large images and unify them to specific sizes (e.g., 512x512 or 1024x1024).
Notes & Tips
- When
get_crop_ratiois connected,preset_ratio(includingauto) is ignored. - Specks dropped by
autoare not cropped in and are not covered bybbox_mask, so pasting back leaves them untouched; usemaskor an explicit ratio if those pixels are real content. autoat1.0is bounded bydivisible_byand is therefore a few pixels smaller than the image (1632×512 for 1663×521 with 32), keeping model input alignment intact.- The old
auto(image ratio snapped to a standard ratio) is now folded into this mode: the currentautoframes from the mask and only reaches the image ratio atscale_strength=1. Workflows saved with the oldautowill render differently after reload; that change is expected. - If the mask is empty or invalid, the node returns default black/white images to prevent errors.