Image-to-Image
Diffusers
lora
flux

How to use in ComfyUI

#1
by janzwrt - opened

Hi, thanks for sharing your Lora! It works really well imo. I was just wondering how you utilize or make the box in ComfyUI ?
Do you just have to create the box in say photoshop and then use that as the first image ?

Yes, you just have to draw the red box on the image. We use Pillow for this, it is probably possible to create a ComfyUI component to do it - maybe there is one already - but I don't know ComfyUI at all. In the meantime using Photoshop or that Python snippet should work.

Something important to keep in mind is that the red box must have the ratio of the reference image. If you have a human-drawn bbox like this space you can use this function to compute this actual bbox.

hmmm ... one 10 works(not that much ^^) ... with comfy iam not shure how best parameters for image support.

so an image lets say sunglass must be the right size or only right aspect ratio to match the red box, i can deliver both option so that both images same size or that the real size match.
most often real size better so a small sunglass left side match the size of the face on the right side.
what you suggest for red box border size ? 1024 pix image and 3 pix border?

so an image lets say sunglass must be the right size or only right aspect ratio to match the red box

Only the aspect ratio matters.

As mentioned above, if a user draws a target box in the UI like this:

Screenshot 2025-09-19 at 21.37.02.png

You can then use get_actual_bbox to compute the final box. This ensures the subject (sunglasses, etc) keeps its aspect ratio, fits inside the target box, and is positioned correctly.

That gives you the red box you should draw (see below for details):

Screenshot 2025-09-19 at 21.44.15.png

most often real size better so a small sunglass left side match the size of the face on the right side.

We provide some examples in the Space to illustrate how this works:

Screenshot 2025-09-19 at 21.46.58.png

You can find the corresponding assets here: https://huggingface.co/spaces/finegrain/finegrain-product-placement-lora/tree/main/examples

what you suggest for red box border size ? 1024 pix image and 3 pix border?

Short answer: 1024px image with a 6px border.

Long answer: the scene is resized the same way as in the Space here. The corresponding preprocessing code is in the finegrain-toolbox repo: see process:

Steps:

  1. Compute the low-res scene dimensions with rescale_mod
  2. Process the user-drawn box with get_actual_bbox and rescale it via project_bbox so it fits the low-res scene.
  3. Downscale the input scene image with resize (Pillow).
  4. Draw the red box on the downscaled scene image with draw_bbox.

Reference image preparation:

For the input reference image, please make sure to provide a version with the background removed (a cutout), with no extra borders, like this:

Screenshot 2025-09-19 at 22.13.20.png

(original image: link)

Then it gets processed by cutout_to_reference_image before being used by the model.

You can use the Finegrain Object Cutter Space to create such cutouts.

Hope this helps! Let us know if anything is unclear or if you have other questions.

Sign up or log in to comment