ComfyUI Node

Remove Padding

Strip the letterbox and keep the crop coordinates

By Zar4X·Created about a year ago·Updated 14 days ago· 5
Remove Padding
  • image
  • mask
  • cropped_image
  • cropped_mask
  • crop_box
threshold5
use_maskfalse

Remove Padding is the inverse of this pack's padding nodes, and it answers a very specific complaint: "there's black (or near-black) border around my image and I want it gone, without me measuring it by hand." Give it an image with letterbox bars, thick black margins, or padding you added during an earlier step, and it finds the content's bounding box and crops to it - returning the crop, a mask, and the exact crop coordinates.

It's one of those nodes that reads as trivial until you've had to trim fifty screenshots by hand. If your pipeline pads to a standard ratio with black (SmartImageResize's standard_ratio does exactly that), or you're cleaning scraped assets and captured frames, this node is the automated version of the tedious job.

How it works

It scans the image row by row and column by column, and any pixel where any RGB channel is above threshold counts as content. The default threshold is 5, meaning "anything brighter than nearly-black is content." Then it crops to the tight bounding box of those pixels. Simple, deterministic, and - because it's a pure geometric pass - it never hallucinates or misjudges "interesting" areas. If it finds no content at all (a fully black frame), it returns the original image untouched rather than cropping to nothing.

The use_mask toggle switches the detection from the image to an optional mask input: pixels above the threshold in the mask define the content area instead. That's the escape hatch when the padding isn't dark - say your border is gray or white and you don't want it mistaken for content.

Outputs are cropped_image, cropped_mask (a mask matching the crop, or a full-white one if you didn't supply one), and crop_box - the box as ComfyUI's BOX type, so if you later want to record or reuse exactly where the content sat, you have it.

Where the edges hide

Two honest limitations. First, this works on RGB brightness - it cannot see transparent (alpha) padding, because alpha lives outside the RGB channels it's testing. If your padding is transparency rather than darkness, this isn't the node. Second, threshold is a blunt instrument by design: a dark scene with genuine shadow detail can look like "padding" and get trimmed if your threshold is too high. If you notice clipped shadow regions, drop the threshold toward 0 - pure black only - and see if that fixes it. The trade is between "leave a faint border" and "eat a dark scene," and you're the one who dials it in.

Install

Standard for the pack: ComfyUI Manager (search "ComfyUI-Image-Resizing") or:

cd ComfyUI/custom_nodes
git clone https://github.com/Zar4X/ComfyUI-Image-Resizing

Restart, and it's under Image Resizing/Resizing. No models, no downloads, just the usual torch/Pillow/numpy/OpenCV stack. It's a small node with a narrow job - but "trim the border, tell me where it was" is a job that comes up far more than you'd expect.

CategoryImage Resizing/Resizing

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
thresholdINT50–255
use_maskBOOLEANfalse
maskoptMASK

Outputs (3)

NameTypeDescription
cropped_imageIMAGE
cropped_maskMASK
crop_boxBOX