Nodes/Comfyui-CraftsMan3DWrapper/Preprocess Image (CraftsMan)
ComfyUI Node

Preprocess Image (CraftsMan)

Clean the photo before CraftsMan looks at it

By hunzmusic·Created about a year ago·Updated about a year ago· 15
Preprocess Image (CraftsMan)
  • image
  • pipeline
  • image_tensor
  • image_pil
foreground_ratio0.95
force_remove_bgfalse
bg_red255
bg_green255
bg_blue255

Image-to-3D models are unforgiving about what you feed them. CraftsMan wants a subject cropped tight, sitting centered on a plain background, roughly square. If you hand it a photo with a cluttered scene, the geometry it hallucinates will include the clutter. Preprocess Image (CraftsMan) is the pack's answer: a dedicated gate that strips the background, crops to the subject, and pads everything into the square format the model expects.

This is where "garbage in, garbage out" gets enforced, and it's genuinely the difference between a usable mesh and a blob with a chair leg attached.

How it works

The node calls the pipeline's own preprocess_image method, and the logic is worth knowing because it changes what you should feed it:

  • If your image already has a real alpha channel (RGBA with non-opaque pixels), the alpha is the mask - the node skips background removal entirely and uses your cutout directly. The pack's example workflow is explicit that this works better than letting the node do it, and the author of the underlying model agrees. Supply a clean transparent PNG and you're already ahead.
  • Otherwise it runs rembg.remove() - the background-removal library - which needs onnxruntime and downloads a segmentation model on first use.
  • Either way, it finds the alpha's bounding box, scales the subject so it fills foreground_ratio of the frame, composites it onto a solid background color, and center-pads to a perfect square.

One reassuring detail from the example workflow: you can throw 4K images at this. The DINOv2 condition encoder internally resizes everything to its 518×518 input, so the preprocessor doesn't need you to pre-downscale - it just wants a clean subject.

Inputs that matter

  • image - the IMAGE socket. Transparent background = best results.
  • pipeline - required, because the preprocessing parameters (square size, background behavior) live in the loaded pipeline's config. You can't run this without a Load CraftsMan Pipeline upstream.
  • foreground_ratio (0.95, 0.5–1.0) - how much of the frame the subject should occupy after cropping. 1.0 makes it fill the frame; lower values give it breathing room. 0.95 is a safe default; drop it if the model keeps clipping parts of the subject.
  • force_remove_bg (false) - re-run rembg even when the image has an alpha channel.
  • bg_red / bg_green / bg_blue (all 255) - the pad color behind the subject. Defaults to white, which the model handles fine.

Outputs

Two of them, and they're deliberately different socket types:

  • image_tensor (IMAGE) - the processed image as a standard tensor. Wire this to a PreviewImage to see what you're about to generate from. This is the sanity check: if the subject looks mangled here, the mesh will be worse.
  • image_pil (IMAGE_PIL) - the same image as a PIL object, and the only thing Sample CraftsMan Latents will accept. Note it's a custom pack type; a plain IMAGE won't connect to the sampler.

Install

Same pack install as everything else here - Manager (search "CraftsMan3D") or:

cd ComfyUI/custom_nodes
git clone https://github.com/hunzmusic/Comfyui-CraftsMan3DWrapper
cd ComfyUI-CraftsMan3DWrapper
pip install -r requirements.txt   # portable: ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt

rembg and onnxruntime are in that requirements file, so the background removal comes along for free.

Common issues

  • First run hangs - rembg is downloading its segmentation model from HuggingFace. Give it a minute and an internet connection.
  • Subject clipped or floating - foreground_ratio is too aggressive, or the original image had no alpha and rembg guessed wrong. Supply a real cutout.
  • "alpha channel not empty, skip remove background" in the console - that's the node working as designed, using your mask.

It's one of those utility nodes that looks boring and quietly decides half your output quality. Preview image_tensor once before you blame the sampler.

Categorygeneration/3d/craftsman

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
pipelineCRAFTSMAN_PIPELINE
foreground_ratiooptFLOAT0.950.5–1
force_remove_bgoptBOOLEANfalse
bg_redoptINT2550–255
bg_greenoptINT2550–255
bg_blueoptINT2550–255

Outputs (2)

NameTypeDescription
image_tensorIMAGE
image_pilIMAGE_PIL