Nodes/comfyui-panels/Crop Image By BBox
ComfyUI Node

Crop Image By BBox

Crop with a bounding box object instead of raw numbers

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
Crop Image By BBox
  • image
  • bbox
  • IMAGE

Cropping an image in ComfyUI is usually a matter of feeding numbers into a crop node. Crop Image By BBox is the same idea with a different currency: instead of separate x/y/width/height integers, it takes a single BBOX object - a (xmin, ymin, xmax, ymax) tuple in the pack's coordinates - and crops the image to it. It's the crop node that speaks this pack's language.

Where does a BBOX come from? The pack produces them in a few places: Crop Mask Holes emits crop boxes for every region it cut, BBox From Ints builds one from raw numbers, and polygon nodes like Polygon.bounds can hand you a box around a panel. That's the real use case here: you've got geometry from the pack's polygon world, and you want to extract exactly that rectangle of pixels from your image - for per-panel upscaling, per-panel regeneration, or feeding a region to a detailer.

How it works

Simple and honest: it rounds the bbox coordinates to integers, clamps them into the image's bounds (so an out-of-range box can't crash it), and slices the tensor - image[:, ymin:ymax, xmin:xmax, :]. Output is a single IMAGE of the cropped region. There's no padding logic here; if the box extends past the edge, the clamp just cuts it short.

The inputs that matter

  • image - the image to crop.
  • bbox - the (xmin, ymin, xmax, ymax) box. Convention matters: x is the width axis, y is the height axis, matching how the pack's canvas polygons are laid out.

One IMAGE output.

Installing it

Part of comfyui-panels - Manager, search "comfyui-panels", or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels

Restart, install deps (shapely, matplotlib, opencv-python), no models.

Where people get burned

The most common mistake is coordinate mismatch: a bbox produced against one canvas size, applied to an image of a different size, crops the wrong region. Keep the source of the bbox and the target image in the same coordinate space. Also worth knowing: this is a plain crop, no resizing - if you crop a small region and want to generate at native resolution, you'll need to upscale the crop yourself (the crop-then-upscale pattern is exactly what panel pipelines do before regeneration). And if you came from Crop Mask Holes, note its crop_boxes output is a list - you'll need to index or iterate to feed individual boxes here.

CategoryBmad/Panels

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
bboxBBOX

Outputs (1)

NameTypeDescription
IMAGEIMAGE