CGA_BlackBorderCrop
Cheap black-border cleanup for img2img, letterboxed frames, and tiled upscaling
- image
- IMAGE
This node exists for the moments you look at an image and go "why is there a black bar on the left." Video frames come out letterboxed, img2img sources come in with dead borders, and tiled upscalers leave black seams where tiles didn't overlap. CGA_BlackBorderCrop finds the black margins and cuts them off in one step.
It's about as simple as a node gets. Feed it an image, it converts to grayscale, builds a mask of everything brighter than a threshold, finds the bounding box of that mask, and crops to it. You get back a tighter image. No models, no sliders beyond the one that matters, no surprises.
The inputs that matter
- image (IMAGE) - the thing to crop.
- threshold (INT, default 10, range 0–255) - how bright a pixel has to be before it stops counting as "black." At the default of 10, anything darker than a very dark gray is treated as border. If your content has near-black shadows, edges, or film grain right up against the frame, raise this so the crop doesn't bite into real image. If you're cropping pure-black letterboxing, the default is fine.
Output is a single IMAGE, one per input image, cropped to the content's bounding box.
The catches, straight from the source
Two things are worth knowing before you wire this into a big graph.
First, it's a single-image node. The code does image.squeeze().numpy() and hands the result to PIL, which means feeding it a batch of several images at once will throw instead of cropping each one. Loop over your batch or feed frames one at a time.
Second, the crop is aggressive - it trims to the tightest bounding box, so anything black at the edge goes, including black you might have meant to keep. And because the output size changes, whatever comes next needs to cope with a dynamic resolution. If you're feeding this into a fixed-size latent, throw a resize node after it.
Where it fits
The classic use is the video pipeline: extract frames, strip the letterboxing, then run them through img2img or an upscaler without the black bars showing up in the result. It also cleans up images that come back from sampling with a border artifact. It's the kind of node you won't reach for every day, but when a workflow keeps producing edge artifacts it's a two-minute fix that beats hand-cropping in an editor.
Install
The whole pack installs the same way, and it's refreshingly light - requirements.txt is just torch, numpy, pathlib, all of which ComfyUI already ships. No model downloads, no conflicts waiting to happen.
ComfyUI Manager: search ComfyUI_CGAnimittaTools (or "CGAnimitta") in the Custom Nodes Manager, install, restart.
Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cganimitta/ComfyUI_CGAnimittaTools
Restart ComfyUI and the node shows up under CGAnimittaTools in the menu. One pack-level quirk to keep in mind: a couple of nodes in this pack have class names with trailing junk in them, so if you ever reference them by class name in API calls, copy the names exactly.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| threshold | INT | 100–255 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |