Nodes/ComfyUI_pytorch360convert/Crop Image with Coords
ComfyUI Node

Crop Image with Coords

Crop a region, remember where it came from, and never lose your place

By ProGamerGov·Created 2 years ago·Updated 11 months ago· 37
Crop Image with Coords
  • image
  • Cropped Image
  • Coords
crop_h0
crop_w0
crop_h2-1
crop_w2-1

Every inpainting tutorial tells you the same thing: crop tight, inpaint small, paste back. The reason is simple - a small crop gets the model's full resolution budget instead of being squeezed, and you're not wasting VRAM generating pixels you'll throw away. Crop Image with Coords is the "crop" half of that, with one feature that makes it actually usable in a graph: it hands you the exact coordinates it used, so Paste Image with Coords can put the crop back precisely where it came from.

You could crop with a plain image-crop node, sure. But then you'd have to track the coordinates yourself, by hand, every time you change the crop. This node packages them up so the paste is always correct even when you tweak the numbers.

How it works

It slices the IMAGE tensor and reports the slice indices. The two modes:

  • Default (center crop): give it crop_h and crop_w, and it crops that many pixels from the center of the image. This is the mode for "crop a 512×512 square out of the middle of this pano."
  • Explicit (corner-to-corner): set crop_h2 and crop_w2 to values ≥ 1 and it crops [crop_h:crop_h2, crop_w:crop_w2] instead - i.e. crop_h/crop_w become the top-left corner and crop_h2/crop_w2 the bottom-right. This is how you grab an off-center region, like a face sitting to one side of a panorama.

Both crop_h2 and crop_w2 default to -1, which means "use center-crop mode."

Outputs are Cropped Image and Coords. The Coords output is a LIST of four ints - [start_h, end_h, start_w, end_w] - which plugs directly into Paste Image with Coords. The intended graph is: Crop → (inpaint / upscale / edit the crop) → Paste, with Coords wired straight across. The crop node is from Ben Egan's ComfyUI_pytorch360convert pack, but it's not 360-specific - it works on any image, and it's arguably the most generally useful node in the pack.

Gotchas

The crop is a plain slice, so a crop_h larger than the image height will give you an empty tensor rather than an error - double-check your numbers if the pasted result looks wrong. And it operates on BHWC tensors like all ComfyUI images, so batch images get cropped per-frame, which is fine for video-ish workflows too.

Install

Install the pack via ComfyUI Manager (search "ComfyUI_pytorch360convert") or git clone https://github.com/ProGamerGov/ComfyUI_pytorch360convert into ComfyUI/custom_nodes and restart. Its requirements.txt is empty, so you may need python -m pip install pytorch360convert for the pack to import. No models, no downloads - this node is pure slicing.

Categorypytorch360convert/miscellaneous

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
crop_hINT0
crop_wINT0
crop_h2INT-1
crop_w2INT-1

Outputs (2)

NameTypeDescription
Cropped ImageIMAGE
CoordsLIST