A picture from a picture
Lesson "img2img", in the group Pictures: techniques of the lesson list. Steps: 9.
What you will be able to do
A picture you already have becomes a new one: the same composition, drawn again by the model as the prompt says.
What you need
- It goes on from A first picture from text. The card says so; it is a hint, not a lock.
- Nodes: Load Checkpoint, CLIP Text Encode (Prompt), KSampler, VAE Decode, Save Image / Preview Image, Load Image, Scale Image to Total Pixels, VAE Encode.
- The app downloads and installs nothing. The step texts below say which files and folders, and which ComfyUI template names them.
The steps
The words of each step, as the lesson shows them. Node names are in bold.
What image-to-image is (reading)
Image-to-image starts not from empty noise but from your picture. The picture is turned into the compressed form the model works in, the latent; some noise is added to it, and the sampler removes that noise by your prompt.
How much noise is added is set by
denoise. At 1 nothing of your picture is left. At 0.3 only fine detail changes. In between, the composition stays and the rest is drawn again.The lesson adds three nodes to the graph of "A first picture from text".
A picture graph is needed
This lesson goes on from the graph of "A first picture from text". The canvas must have Load Checkpoint, the two texts CLIP Text Encode (Prompt) and CLIP Text Encode (Prompt), KSampler, VAE Decode and Save Image with the links between them.
If they are not there, do that lesson first.
Load your picture
Add a Load Image node and choose the picture in its
imagefield. ComfyUI takes pictures from itsinputfolder; the button on the node uploads one there.The composition, the colours and the light of the result come from this picture.
Bring the picture to a size the model knows
Add a Scale Image to Total Pixels node and connect the
IMAGEoutput of Load Image to itsimageinput. Setmegapixelsto 1.A model draws best at the size it was trained at. One megapixel is about 1024 × 1024, right for SDXL and newer models. For an SD 1.5 model set 0.25, that is 512 × 512. A photo from a phone is many times larger, and the model would repeat parts of it.
Turn the picture into a latent
Add a VAE Encode node. Connect the output of Scale Image to Total Pixels to its
pixelsinput and theVAEoutput of Load Checkpoint to itsvaeinput.The sampler works not with pixels but with their compressed form. This node compresses the picture with the VAE of the same model that will draw.
Give the sampler your picture
Connect the output of VAE Encode to the
latent_imageinput of KSampler. The link from the empty latent is replaced: an input takes one link.The empty latent is not needed any more. Leave it or delete it: ComfyUI does not run a node whose output goes nowhere.
Set how much to draw again
Set
denoiseof KSampler to 0.6.At 0.6 the composition and the large shapes stay, while textures, faces and the style follow the prompt. Lower it to 0.4 when the result must stay close to the original. Raise it to 0.8 when only the layout matters.
Describe what should be in the picture, not what to change: the model does not compare, it draws.
Compare variants fairly (reading)
To see what one setting does, change only that setting. Under
seedof KSampler set "control after generate" tofixed: the noise then stays the same from run to run, and only what you changed makes the difference. Withrandomizeevery run starts from new noise, and you compare luck, not settings.Several variants in one run: in a graph from text,
batch_sizeof the empty latent; here, a Repeat Latent Batch node between VAE Encode and KSampler. Each picture of a batch gets its own noise from the sameseed.The graph is ready (reading)
Save the graph with "File ▸ Save workflow for ComfyUI…", open the file in ComfyUI and run it there. This app runs nothing in ComfyUI itself.
What to try:
denoise0.4 and 0.8 on the sameseed; a drawing or a sketch as the picture, with a prompt of a photo.Save Image writes the whole graph, prompts included, into the PNG it saves: the picture dragged into ComfyUI opens the graph again. Before you share a picture whose graph must stay private, convert it to another format or start ComfyUI with the
--disable-metadataoption, which writes no graph into the files.
What the lesson checks
A reading step is done when you press Got it, next. A doing step ticks itself off when the canvas holds:
- Step 2, A picture graph is needed:
- a Load Checkpoint node.
- a CLIP Text Encode (Prompt) node.
- a CLIP Text Encode (Prompt) node.
- a KSampler node.
- a VAE Decode node.
- a Save Image or Preview Image node.
CLIPof Load Checkpoint intoclipof CLIP Text Encode (Prompt) (prompt) (a Load LoRA or CLIP Set Last Layer in between is accepted).CLIPof Load Checkpoint intoclipof CLIP Text Encode (Prompt) (negative prompt) (a Load LoRA or CLIP Set Last Layer in between is accepted).MODELof Load Checkpoint intomodelof KSampler (a Load LoRA or LoraLoaderModelOnly or DifferentialDiffusion or ModelSamplingAuraFlow or ModelSamplingFlux or CFGNorm or IPAdapter Unified Loader or IPAdapter or IPAdapterAdvanced or IPAdapterStyleComposition in between is accepted).CONDITIONINGof CLIP Text Encode (Prompt) (prompt) intopositiveof KSampler (a Apply ControlNet or InpaintModelConditioning or Conditioning (Combine) or ConditioningSetArea or ConditioningSetAreaPercentage or ConditioningSetMask or Apply Style Model or FluxGuidance or ConditioningZeroOut or FluxKontextMultiReferenceLatentMethod in between is accepted).CONDITIONINGof CLIP Text Encode (Prompt) (negative prompt) intonegativeof KSampler (a Apply ControlNet or InpaintModelConditioning or Conditioning (Combine) or ConditioningSetArea or ConditioningSetAreaPercentage or ConditioningSetMask or Apply Style Model or FluxGuidance or ConditioningZeroOut or FluxKontextMultiReferenceLatentMethod in between is accepted).LATENTof KSampler intosamplesof VAE Decode.VAEof Load Checkpoint intovaeof VAE Decode.IMAGEof VAE Decode intoimagesof Save Image or Preview Image.
- Step 3, Load your picture:
- a Load Image node.
imageof Load Image: a value is chosen.
- Step 4, Bring the picture to a size the model knows:
- a Scale Image to Total Pixels node.
IMAGEof Load Image intoimageof Scale Image to Total Pixels.megapixelsof Scale Image to Total Pixels is from 0.2 to 2; Do this for me sets 1.
- Step 5, Turn the picture into a latent:
- a VAE Encode node.
IMAGEof Scale Image to Total Pixels intopixelsof VAE Encode.VAEof Load Checkpoint intovaeof VAE Encode.
- Step 6, Give the sampler your picture:
LATENTof VAE Encode intolatent_imageof KSampler.
- Step 7, Set how much to draw again:
denoiseof KSampler is from 0.3 to 0.9; Do this for me sets 0.6.
What next
These lessons go on from this one: Inpainting: redraw part of a picture.