BK Image Aspect Filter
Keep only the aspect ratios you want from an image batch
- images
- default_image
- IMAGE
You've generated a batch of images at mixed resolutions and now you only want the ones shaped like a portrait, or the ones near 16:9. BK Image Aspect Filter does exactly that - pass in an IMAGE batch, it keeps every frame whose width÷height ratio falls inside the range you set, and drops the rest.
It's from the ComfyUI_BaiKong_Node pack, the lightweight no-model toolkit for color and layout. Nothing here touches a GPU or downloads a file; it's pure tensor inspection, so it slots into any workflow as a cheap pre-filter.
How it works
For each image in the batch, the node computes aspect_ratio = width / height and tests whether it falls inside [min_aspect_ratio, max_aspect_ratio]. Accepted images are stacked back into a batch; rejected ones are discarded. The real saving grace is the default_image input: if nothing in the batch passes the filter, the node returns your default image instead of an empty tensor - which would otherwise poison every downstream node. It also logs per-image aspect ratios to the console, so you can see exactly what got rejected and why.
Two practical notes on the math. First, ratios under 1 mean "taller than wide" - a portrait. So a range of 0.5 → 0.8 keeps portraits, 1.77 → 1.78 is a tight 16:9 slice, and 1.0 → 1.0 (or thereabouts) keeps near-squares. Second, the filter tests the current dimensions of each image in the batch - if everything in the batch is the same size because it came out of one sampler, the filter is a yes/no gate on that one ratio, not a selector. It shines when the batch genuinely contains mixed aspect ratios, e.g. after an upscaler or a crop step that produced varying frames.
Inputs
- images - the
IMAGEbatch to filter. - min_aspect_ratio / max_aspect_ratio - the window, 0.1 to 10.0 (default 1.0 → 1.2).
- default_image - the fallback if no image survives.
Output is a single IMAGE - either the filtered batch or the default image. One thing to note: unlike the other nodes in this pack, there's no fancy inline UI here; the schema is a plain IMAGE in, IMAGE out. The console log is where the detail lives.
Install
Same as the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/JayLyu/ComfyUI_BaiKong_Node
cd ComfyUI_BaiKong_Node
pip install -r requirements.txt
Restart ComfyUI, or grab "ComfyUI_BaiKong_Node" from ComfyUI Manager. Dependencies are scikit-learn, scipy, opencv-python, scikit-image, and matplotlib - all CPU-side, no models.
Gotchas
The error you'll actually hit is a ValueError if the input isn't a 4D tensor (batch, height, width, channels) - which happens if you feed it a single unbatched image, so make sure your image is coming from a node that outputs a proper batch. And remember the fallback is a hard requirement: default_image is a required input, so you have to wire something there or the node won't even instantiate.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| min_aspect_ratio | FLOAT | 1.000.1–10 | — |
| max_aspect_ratio | FLOAT | 1.200.1–10 | — |
| default_image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |