Nodes/ComfyUI-XJNodes/Image to Seed
ComfyUI Node

Image to Seed

Make the seed follow the picture, not the other way around

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Image to Seed
  • image
  • seed
offset0

Seeds are the unglamorous foundation of reproducible generation - the KB's troubleshooting notes literally open with "don't use randomized seed, set it fixed" as the first rule of debugging. But sometimes you want the opposite relationship: a seed that depends on the input image. That's Image to Seed. You feed it an image, it hashes the pixels, and out comes an integer seed. Same image, same seed, every time. Change a pixel, get a different seed.

Why would you want that? Batch img2img is the classic case. You're processing a folder of reference images and you want each one to get a stable but distinct seed - stable so re-running gives you the same starting point per image, distinct so they don't all share one seed and drift together. Instead of writing a node or threading counters, you just wire each source image into this node and its seed is born from its own content. Same input, same output, no state to track.

How it works

The mechanism is brutally simple: it takes the raw image tensor, flattens it to bytes, runs MD5 over it, converts the digest to an integer, and takes it modulo 2^32. The offset input adds to the result (mod 2^32) so you can nudge the derived seed without changing the source. That's the whole thing - there's no neural network, no "perceptual hash," just a deterministic checksum of the pixel data.

The word pixel data is doing a lot of work there. MD5 over the exact float32 tensor means the hash reflects the precise values in memory. Load the same JPEG two different ways - one through ComfyUI's Load Image, one through a path that strips EXIF or converts color space first - and the tensors can differ enough that the seeds diverge completely. It's deterministic per exact image state, not per picture you recognize.

Inputs and outputs

Only three inputs exist:

  • image - the IMAGE whose pixels get hashed
  • offset - INT, 0 to 4,294,967,295, default 0. Additive shift on top of the hash

The single output is seed, an INT in the 0..2^32-1 range that KSampler will accept directly. Wire it into the seed input of your sampler (or a seed node that feeds one) and you're done.

Installing it

It's one node in the XJNodes pack. ComfyUI Manager: search "ComfyUI-XJNodes", install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes
# restart ComfyUI

No dependencies beyond what ComfyUI already has - the hash runs on the CPU from the tensor bytes. It shows up under XJNodes/image.

Gotchas worth knowing

First, it only produces a consistent seed, not a meaningful one. Two different photos will hash to different values, sure, but nothing about the seed encodes anything about the image's content - it's a random-looking number tied to a specific tensor. Second, MD5 over the raw bytes means anything upstream that touches the image changes the seed: a resize, a different loader, even a VAE encode if you feed it a latent-derived tensor rather than a decoded image. Keep the input pipeline stable if you want the seed stable. And third, offset is capped at 2^32−1, same as the seed space, so it wraps - that's fine, just don't expect to be able to derive the pre-offset seed from the output.

CategoryXJNodes/image

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
offsetINT00–4294967295

Outputs (1)

NameTypeDescription
seedINT