Nodes/ComfyUI-BrainDead/BD Crop To Mask
ComfyUI Node

BD Crop To Mask

Crop an image to the bounding box of its active region, add proportional padding, optionally enforce a square crop, then resize to a target resolution. Use channel='R' to center/size the crop on lips only (not teeth/tongue). Use fixed_size_px to force the same crop size across all visemes for consistent UV atlas framing — lips always appear at the same scale and center position.

By BizaNator·Created 7 months ago·Updated 16 days ago· 14
BD Crop To Mask
  • image
  • mask
  • cropped
  • crop_box
  • status
channelR
threshold0.05
padding_pct0.15
fixed_size_px0
squaretrue
output_size512
resize_modefit
fallbackfull_image
Category🧠BrainDead/Segmentation

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
maskoptMASK
channeloptCOMBORWhich image channel drives the bounding box detection. all — union of R/G/B (lips+teeth+tongue) R — lips only (recommended for consistent atlas framing) G — teeth only B — tongue only A — alpha/depth channel
thresholdoptFLOAT0.050–1Pixel value above which a pixel counts as active.
padding_pctoptFLOAT0.150–0.5Padding on each side as a fraction of the larger bbox dimension. 0.15 = 15%% per side. Used when fixed_size_px=0.
fixed_size_pxoptINT00–4096When >0, force the crop to exactly this square size (in source pixels) centered on the detected channel centroid. Use the SAME value across all 7 visemes for a consistent atlas — every cell covers the same mouth region at the same scale. Tip: run once with fixed_size_px=0 to see crop sizes in the status output, then set fixed_size_px to the largest bbox+padding size.
squareoptBOOLEANtrueEnforce a square crop. Ignored when fixed_size_px>0 (already square).
output_sizeoptINT51264–4096Output resolution (square).
resize_modeoptCOMBOfitfit — scale to fill output_size preserving aspect ratio, then pad edges with black. Lips keep their natural shape; horizontal visemes get top/bottom bars, vertical visemes get left/right bars. stretch — squash to exact output_size (may distort lip shape).
fallbackoptCOMBOfull_image2 options: full_image, center_crop

Outputs (3)

NameTypeDescription
croppedIMAGE
crop_boxSTRING
statusSTRING