Nodes/PortraitUtils/Intelligent AutoCrop (GPU)
ComfyUI Node

Intelligent AutoCrop (GPU)

Snipe off the letterboxing and banners with your GPU

By heyburns·Created 11 months ago·Updated 4 months ago· 1
Intelligent AutoCrop (GPU)
  • image
  • image
  • trim_left
  • trim_top
  • trim_right
  • trim_bottom
  • detected
strip_bottom_bannertrue
detect_borderstrue
fuzz_tolerance0.04
edge_uniformity0.95
pad_px0

Ripped images have a signature: black bars top and bottom from the letterbox, a banner strip along the edge, a solid border from a bad crop. Diffusion doesn't know those are garbage - it happily diffuses into them, and suddenly your output has a gradient smear where the bar was. IntelligentAutoCrop is the pack's border-sniper: it detects and removes solid, uniform edges (letterboxing, banners, borders) using your graphics card, and reports exactly what it trimmed so you know it didn't eat real content.

The mechanism is honest and simple, which is why it's trustworthy. It converts the image to luma, then scans each edge region looking for uniformity: it computes how uniform the border pixels are (a mean absolute deviation against the local edge) and compares that against edge_uniformity (default 0.95). A perfectly solid black bar scores ~1.0 and gets trimmed; a sky that happens to be at the top of the frame fails the uniformity test and survives. fuzz_tolerance (default 0.04) sets how much variance is allowed before an edge stops counting as "border" - raise it for slightly noisy borders, keep it low so it doesn't chew into a real gradient. strip_bottom_banner (default on) specifically targets the bottom strip, which is the classic video-capture banner location. detect_borders (default on) is the master switch for the four-sided border scan. pad_px re-adds pixels around the detected content, handy when the trim lands right on the subject's edge.

Outputs: the cropped image, the four trim_left/trim_top/trim_right/trim_bottom integers (how many pixels each side lost), and detected - a boolean saying whether anything was trimmed at all. The trim outputs are the part people sleep on: wire them into a debug log and you can QA the whole batch without eyeballing every frame. It runs on torch tensors, so it uses the GPU when one's available (hence the name) but works fine on CPU too.

The name oversells it a little - "intelligent" here means "uses statistics instead of a fixed threshold," not "understands the image." It will not distinguish a solid red curtain from a solid red border; it only knows the border is uniform. Use it on content with genuinely clean edges and it's a fantastic batch cleaner.

Install

Manager → search "PortraitUtils", or:

cd ComfyUI/custom_nodes
git clone https://github.com/heyburns/PortraitUtils

Restart. No extra downloads - it's torch/numpy math.

Common issues

  • It trimmed the top of a real photo - the top edge was too uniform (flat sky, white wall). Lower edge_uniformity or disable detect_borders and crop manually.
  • Black bars survive - strip_bottom_banner handles the bottom specifically; the top/sides are covered by detect_borders. Make sure both are on, and lower fuzz_tolerance if the bars have subtle noise.
  • detected: false but there are clearly bars - the border variance exceeded your tolerance. Nudge edge_uniformity up (toward 0.99) and fuzz_tolerance down.

For batches of captured or scanned frames with dead space, this is the node that turns "crop 100 files by hand" into a log read.

CategoryPortraitUtils/Transform

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
strip_bottom_bannerBOOLEANtrue
detect_bordersBOOLEANtrue
fuzz_toleranceFLOAT0.040–0.5
edge_uniformityFLOAT0.950.3–0.99
pad_pxINT00–256

Outputs (6)

NameTypeDescription
imageIMAGE
trim_leftINT
trim_topINT
trim_rightINT
trim_bottomINT
detectedBOOLEAN