Preprocess Image (CraftsMan)
Clean the photo before CraftsMan looks at it
- image
- pipeline
- image_tensor
- image_pil
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 needsonnxruntimeand downloads a segmentation model on first use. - Either way, it finds the alpha's bounding box, scales the subject so it fills
foreground_ratioof 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- theIMAGEsocket. 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 aLoad CraftsMan Pipelineupstream.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-runrembgeven 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 aPreviewImageto 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 thingSample CraftsMan Latentswill accept. Note it's a custom pack type; a plainIMAGEwon'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 -
rembgis downloading its segmentation model from HuggingFace. Give it a minute and an internet connection. - Subject clipped or floating -
foreground_ratiois too aggressive, or the original image had no alpha andrembgguessed 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| pipeline | CRAFTSMAN_PIPELINE | — | |
| foreground_ratioopt | FLOAT | 0.950.5–1 | — |
| force_remove_bgopt | BOOLEAN | false | — |
| bg_redopt | INT | 2550–255 | — |
| bg_greenopt | INT | 2550–255 | — |
| bg_blueopt | INT | 2550–255 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image_tensor | IMAGE | — |
| image_pil | IMAGE_PIL | — |