Nodes/ComfyUI-QING/图像裁剪丨原点
ComfyUI Node

图像裁剪丨原点

Crop by exact pixel coordinates — and get a mask for free

By sheengoa·Created about a year ago·Updated 20 days ago· 16
图像裁剪丨原点
  • image
  • image
  • range_mask
  • crop_info
left_top0,0
right_top0,0
left_bottom0,0
right_bottom0,0

If you've ever had a detector hand you a bounding box and thought "great, now I need to cut exactly that region out," this is the node. ImageCropByOrigin crops an image using four corner coordinates measured in pixels from the top-left origin - and, unlike the stock ComfyUI crop, it also hands you a mask of the region you just cut, which is the part that makes it useful in real workflows.

It comes from ComfyUI-QING, a Chinese-authored utility pack (79 nodes covering image, mask, data, SVG and API plumbing - display names are bilingual, so you'll see it as "图像裁剪丨原点"). The pack has essentially no English community footprint yet, which is a shame, because the crop/mask pairing here is genuinely handy.

How it works

The four inputs - left_top, right_top, left_bottom, right_bottom - are strings that each hold a pixel coordinate. The author's parser is forgiving: it just pulls the first two numbers out of each string, so "243,92", "243 92", "243/92" and "243-92" all work. Type them, or wire in a computed string if something upstream is generating coordinates.

It then takes the min and max of all four X values and all four Y values to get a bounding box, clamps it to the image edges, and slices. That min/max behavior is worth knowing: your four points don't need to be in perfect corner order, and if one point is off the image, the box just gets clamped instead of exploding.

The inputs and outputs that matter

  • image - the tensor to crop. That's it for required stuff, plus the four coordinate strings.
  • image (out) - the cropped tensor.
  • range_mask - a MASK the same size as the source image, white where the crop box fell, black elsewhere. This is the killer feature. Feed it to an inpaint or a detailer and you've turned a crop into a region-aware operation.
  • crop_info - a STRING like crop_box=(243,92)-(768,600); size=525x508; source_size=1024x1024. Wire it into a LetMeSee or LogPrinter (same pack) if you want it in the console.

Where this actually fits

The stock Crop Image cuts and forgets. This node cuts and remembers - so the classic move is: run a face/object detector upstream, wire the box in here, and pipe both the crop and the range_mask into a detail pass or an inpaint. That's the detect-crop-mask-refine loop the community runs on auto-pilot (masking-detection-detailing.md walks through it), and this node covers two steps of it at once.

One honest caveat: all four fields are strings, so if you're feeding it numbers from a detector node you'll need a number→string conversion in between. The pixel and percent crop siblings in the same pack don't have that quirk - but they also don't take explicit corner coordinates. Trade-offs everywhere.

Installing

It ships in the ComfyUI-QING pack, so installing once gets you all 79 nodes. Via ComfyUI Manager, search "ComfyUI-QING". Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py   # or: pip install -r requirements.txt

Then restart ComfyUI. Requirements are Pillow, opencv-python, scipy, scikit-image and cairosvg (plus openai for the API nodes) - all pure pip, no model downloads. If you're in China, the author ships a mirror flag: python install_dependencies.py --mirror --auto. Python ≥ 3.9 and a recent ComfyUI.

Gotchas

If a coordinate string has no two numbers in it, the node throws a ValueError into the console instead of failing gracefully - so "0,0" defaults everywhere are there for a reason. And if left/top ends up right/bottom (a degenerate box), you get the original image back plus a 裁剪失败 message in crop_info. No crash, just a no-op you'll notice when your output looks uncropped. Watch the info string and you'll never be confused.

CategoryQING/图像处理

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
left_topSTRING0,0左上角坐标,例如:243,92
right_topSTRING0,0右上角坐标,例如:768 92
left_bottomSTRING0,0左下角坐标,例如:243/600
right_bottomSTRING0,0右下角坐标,例如:768-600

Outputs (3)

NameTypeDescription
imageIMAGE
range_maskMASK
crop_infoSTRING