Nodes/ComfyUI-seam-carving/Image Resize (seam carving)
ComfyUI Node

Image Resize (seam carving)

The ComfyUI resize that fixes aspect ratio by deleting boring pixels

By spinagon·Created 3 years ago·Updated about a year ago· 27
Image Resize (seam carving)
  • pixels
  • keep_mask
  • drop_mask
  • IMAGE
width512
height512

You've got a 16:9 render you need to squeeze into a 4:3 print, and you don't want to crop the composition or stretch everyone into funhouse-mirror proportions. Enter seam carving - the one resize tool in ComfyUI that changes your aspect ratio by deleting the boring pixels instead of distorting the interesting ones.

It's often lumped in with upscaling, but that's category confusion. Upscaling gives you more pixels or more detail; seam carving gives you the same pixels in a different shape. Think of it as a smarter crop - it finds the least-important strips of image, top to bottom or side to side, and either removes them (shrinking) or inserts copies (growing). The technique is from Avidan & Shamir's 2007 paper, and this node wraps li-plus/seam-carving, a fast, pure-CPU numpy implementation. No models, no VRAM, no API key. It's just math.

How it works

The node carves "seams": one-pixel-wide paths of lowest visual energy that cross the whole image. Remove a seam and the image shrinks by one pixel while the important content - faces, edges, buildings - stays put. The magic is that seams snake around high-detail regions rather than through them.

The pack's source hardcodes the good settings for you: energy_mode="forward" (the improved variant that avoids edge artifacts when two sides of a removed seam get welded together) and order="width-first" (it carves vertical seams to fix width before horizontal ones for height). It also steps at step_ratio=0.1, so large changes get applied in 10% increments with seam positions re-evaluated each pass. You don't get to tune any of that - it just works, and forward-energy + stepped carving is the version you'd pick anyway.

The inputs that matter

  • pixels - your IMAGE input.
  • width and height (INT, default 512 each) - the target size in pixels, not a multiplier. Same job as a plain Resize, different method.
  • keep_mask (optional MASK) - protect a region from being carved. Paint a mask over a face or logo and the seams route around it, so it survives the resize undistorted.
  • drop_mask (optional MASK) - the opposite: force seams through a region so it gets removed. That's classic seam-carving object removal - mark a tourist photobombing your shot and it gets carved away.

The output is a single IMAGE, wired to Save Image or fed into whatever comes next. It's batch-aware, and masks get auto-resized to match your image, so you can't really get the dimensions wrong there. One guard built in: if your drop mask would cover the entire image, it's ignored with a console warning instead of deleting everything.

Installing it

Easiest path is ComfyUI Manager - search "ComfyUI-seam-carving" and hit install, then restart. Or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/spinagon/ComfyUI-seam-carving

Its only dependency is pip install seam-carving, which Manager (or the pack's requirements.txt) handles automatically. There are no model downloads, so it's one of the lightest installs in the ecosystem.

Where people get burned

Seam carving is not free lunch, and the two pain points are real:

  • It's slow for big changes. Carving a seam is a full-image energy computation, thousands of times. The README's advice is the right advice: regular-resize (Lanczos is fine) to near your target first, then let seam carving handle the final stretch. Don't ask it to go from 1024 to 512.
  • Large aspect-ratio jumps warp. The one person on reddit who tried this node at 1024×1024 → 1280×720 reported it "warps pretty bad" - that's a ~36% pixel change plus a big shape shift, which is exactly the regime where seams run out of low-energy paths and start chewing real content. The thread's actual answer was outpainting with generative fill, which is the right tool for big shape changes. Keep seam carving for adjustments of tens of pixels, not ratios.

It also never invents content - if a subject genuinely needs filling in, that's an outpaint or img2img job, not this. For modest aspect-ratio fixes and photobomb removal without touching the parts you care about, it's genuinely the one to reach for.

Categoryimage

Inputs (5)

NameTypeDefaultDescription
pixelsIMAGE
widthINT512
heightINT512
keep_maskoptMASK
drop_maskoptMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE