Nodes/comfyui-panels/Image Relative Crop
ComfyUI Node

Image Relative Crop

Crop a crop, using the original page's coordinates

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
Image Relative Crop
  • image
  • original_crop
  • target_crop
  • IMAGE

Image Relative Crop solves a deceptively annoying problem that comic workflows run into constantly: you cropped a panel out of a page, resized it (or generated into it, or upscaled it), and now you want a sub-crop - but the coordinates you care about are in the original page's space, and the image in front of you is a different size. This node does the coordinate math so you can think in the original page and never worry about the resize.

Concretely: you have an image that is already a crop of something bigger. You know the bounding box of that original crop in the parent image's coordinates, and you have a target bbox - also in the parent's coordinates - that you want to extract from your current (possibly resized) image. The node maps the target box through the current image's scale factors and crops it out. The author's description makes the one useful promise explicit: "the image and original_crop dimensions do not have to match." That's the whole feature.

Three inputs, all required:

  • image - the cropped image you're cutting into.
  • original_crop - the BBOX of the original crop in the parent image's coordinates (i.e. how this image was cut from the page).
  • target_crop - the BBOX of the new crop you want, also in the parent image's coordinates.

One IMAGE comes out. If the target crop falls completely outside the image or inverts to zero width/height, it safely returns the input unchanged rather than erroring - a small robustness touch you'll appreciate mid-workflow.

Where this earns its keep: the classic case is the "panel-within-a-panel" or "tighten up a shot" edit. You generated a panel at, say, 1024×1024 but the bbox on your page says the panel is actually 800×1200. Rather than computing scale factors by hand or cropping blind, you keep a bbox from Polygon.bounds around, and this node does the mapping. It's also the natural complement to the crop/slice nodes in this pack when you want to operate on a sub-region of a panel before pasting it back with Paste Crops with Masks.

One habit to build: keep your bboxes in the page coordinate space from the start. This pack's polygon nodes produce bounds in the coordinates you built the canvas in, so as long as you don't manually mix coordinate systems, the values you feed in here are the same ones PolygonBounds gave you. The moment you start hand-typing bbox numbers, that's when they drift out of sync - let the nodes carry them.

Installing

Part of comfyui-panels by bmad4ever. Via ComfyUI Manager (search "comfyui-panels") and restart, or:

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

Deps: shapely, matplotlib, opencv-python - no models, no GPU. Shapely is pinned exactly, so a version clash with another pack is the realistic import failure.

CategoryBmad/Panels

Inputs (3)

NameTypeDefaultDescription
imageIMAGECropped image.
original_cropBBOXOriginal crop bounding box.
target_cropBBOXNew crop bounding box in the old image's coordinates.

Outputs (1)

NameTypeDescription
IMAGEIMAGE