🐳图像边框移除
Strip black bars, white margins, and transparent-canvas borders
- image
- image
- mask
Simple Border Remover (🐳图像边框移除) exists to solve one annoying, recurring problem: your image has a border that isn't part of the actual content, and it's messing everything up. Letterbox bars from a video frame, white margins from a screenshot or a scan, or the transparent padding around a render that got exported on a larger canvas. The node finds the real content, cuts the dead space away, and hands you both the trimmed image and the mask of what it kept.
Here's how it decides what's "border" vs "content", because that's where the gotcha lives. The node scans the image and looks for the bounding box of non-empty pixels. For RGBA images it uses the alpha channel - anything with alpha above your threshold counts as content, so transparent padding gets trimmed correctly. For plain RGB images it does something dumber: it treats near-black pixels as empty (grayscale > threshold counts as content). That's a design choice worth internalizing - this node trims black borders and transparent borders out of the box, but if your image has a white border, it won't find it, because a white border is brighter than the threshold and reads as content. White-margin trimming is a job for a different tool (or flip the image and use the fill option).
The inputs map to that logic directly. crop_to_content (default on) is the actual trim. padding (0-100) re-adds a border of blank pixels around the crop - useful if the tight crop is too tight for whatever you're feeding next. fill_background + background_color (a hex string, default #FFFFFF) lets you composite the cropped content onto a solid background of your choosing. threshold (0-1, default 0.01) is how strict "empty" is - leave it low for clean alpha, raise it if your supposedly-transparent borders have noise or a faint edge you want folded into the background.
Outputs and wiring
Two outputs: image (the trimmed result) and mask (the content region as a MASK). That mask is the quietly useful part - you can wire it into an inpaint or detailer setup to restrict work to the content area, or into a composite to place the trimmed content somewhere else without re-detecting anything.
Where this earns its keep: cleaning up video frames before you run them through a video-to-image pipeline (letterbox bars are the single most common reason an i2v conditioning frame looks wrong), and tidying renders that came out of a compositor with canvas padding. It's a cheap deterministic operation - milliseconds, no model, no VRAM - which is exactly the sort of thing the KB's post-processing layer says you should do as a pixel op, not by re-rolling a generation.
Install
Part of Pond Nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/Pondowner857/comfy_Pond_Nodes
cd comfy_Pond_Nodes
pip install -r requirements.txt
Restart ComfyUI (or use Manager and search "comfy_Pond_Nodes"). The pack's requirements include opencv-python and friends; this node itself only really leans on numpy/Pillow/torch, so if you installed the pack for something else it'll work with no extra setup. And yes, the usual README caveat applies: the pack conflicts with comfyui_HiDream-Sampler and will spam your console if both are installed.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| crop_to_content | BOOLEAN | true | — |
| padding | INT | 00–100 | — |
| fill_background | BOOLEAN | false | — |
| background_color | STRING | #FFFFFF | — |
| threshold | FLOAT | 0.010–1 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |