Nodes/AAA Metadata System/Smart Image Cropper
ComfyUI Node

Smart Image Cropper

Auto-crop the photo out of the photo

By EricRollei·Created 10 months ago·Updated 9 months ago· 13
Smart Image Cropper
  • image
  • cropped_image
crop_modeauto
multi_image_handlinglargest_only
min_crop_ratio0.05
debug_modefalse

You know the workflow: you photographed a framed painting on a museum wall, scanned a book page, or grabbed a screenshot of a magazine spread, and now the actual content - the artwork, the photo, the chart - is sitting in the middle of a sea of background. Cropping it by hand is five minutes of fiddling with a box. This node tries to do it for you, automatically.

Smart Image Cropper is one of the more practical tools buried in the AAA Metadata System pack. It's an OpenCV-based auto-cropper that detects rectangular content inside a larger image and returns just that content: scanned documents, book pages, framed art on a wall, photos embedded in a composite, images with ugly borders. It's not "AI magic" - it's classic computer vision doing a genuinely useful cleanup job.

How it works

Feed it an IMAGE and it runs a detection pipeline:

  1. Analyze the image characteristics - lighting, contrast, whether there's an obvious subject region.
  2. Decide if cropping is even needed. This is the smart part and the part people don't expect: if the content already fills the frame, it returns the image untouched instead of hacking a chunk off.
  3. Detect all candidate regions using adaptive parameters picked from step 1 - contours and edge analysis rather than one hardcoded threshold, since a white page on a dark desk needs different settings than a dark painting on a white wall.
  4. Score the candidates, exclude text captions, and return the best one.

crop_mode gives you three aggression levels: auto (adaptive, the default), conservative (when auto gets too aggressive), and aggressive (when auto is too cautious). The tooltips on the dropdowns are worth reading before you touch them - the author designed these as manual overrides for when auto misjudges, not as secret quality knobs.

multi_image_handling deals with the case where it finds several images in one frame: largest_only returns the biggest region (default, usually right), best_quality analyzes content richness, first_found just grabs the first hit and goes home. min_crop_ratio (default 0.05) sets the floor for how small a crop is allowed to be, so it won't zoom in on a spec of dust and call it the subject.

The one output

cropped_image - a single IMAGE tensor, ready to feed into whatever comes next. debug_mode (optional) prints the whole decision log to the console: detected image type, parameters chosen, before/after sizes and the percentage reduction. Turn it on the first couple of runs so you can see why it made the call it made.

Installing it

It ships in the AAA Metadata System pack, so you're installing the whole thing:

cd ComfyUI/custom_nodes
git clone https://github.com/EricRollei/AAA_Metadata_System.git
cd AAA_Metadata_System
pip install -r requirements.txt

Restart ComfyUI afterward (or search "AAA Metadata System" in ComfyUI Manager). Note that opencv-python is a core requirement of the pack - a big install, but it's the engine this node runs on. No model files needed. And yes, the pack is CC BY-NC licensed for non-commercial use; commercial use requires a license from the author.

Common issues

  • It crops too much or too little - that's what conservative and aggressive are for. Switch modes before you give up.
  • Dark-on-dark or busy backgrounds - detection genuinely struggles here. debug_mode will show you what it's seeing, and a higher min_crop_ratio can keep it from glomming onto background clutter.
  • It returned the image unchanged - that's the "does this need cropping at all?" check working as designed, not a failure.

Is it the one auto-crop node to rule them all? No - if you're auto-cropping product photos with controlled backgrounds you have better options. But for "I have a scan and I want just the page," it's genuinely good, and it's the rare crop node that knows when not to crop.

CategoryEric/Image Processing

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
crop_modeCOMBOautoAuto uses intelligent detection, others are manual overrides when needed
multi_image_handlingCOMBOlargest_onlyHow to handle multiple images: largest_only picks biggest area, best_quality analyzes content
min_crop_ratioFLOAT0.050.01–0.5Minimum crop size as ratio of original (prevents over-cropping)
debug_modeoptBOOLEANfalsePrint detailed analysis and decision information

Outputs (1)

NameTypeDescription
cropped_imageIMAGE