lllyasviel / lllyasviel/ControlNet

[Scribble] How to catch the color in input image?

Open
#436 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
34.1k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

Hi, Thanks for sharing this library for using Image Generation.
There is one questions I want to ask.

I want to catch the color in input image.
For example.. In this image,
![image](https://github.com/lllyasviel/ControlNet/assets/28581778/8c889ef5-16c0-40c3-87c6-796dd2e7009b)
I want to depict character's various colors in output image. (yellow, red, blue, green, etc..)
But, output image is not depicted the color.

I use this code in generating output image.
```Python
with torch.no_grad():
img = resize_image(HWC3(input_image), image_resolution)
H, W, C = img.shape

detected_map = np.zeros_like(img, dtype=np.uint8)
detected_map[np.min(img, axis=2) < 127] = 255

control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
control = torch.stack([control for _ in range(num_samples)], dim=0)
control = einops.rearrange(control, 'b h w c -> b c h w').clone()

if seed == -1:
seed = random.randint(0, 999999999)
seed_everything(seed)

if config.save_memory:
model.low_vram_shift(is_diffusing=False)

cond = {"c_concat": [control], "c_crossattn": [model.get_learned_conditioning([extra_prompt + prompt] * num_samples)]}
un_cond = {"c_concat": None if guess_mode else [control], "c_crossattn": [model.get_learned_conditioning([negative_prompt] * num_samples)]}
shape = (4, H // 8, W // 8)

if config.save_memory:
model.low_vram_shift(is_diffusing=True)

model.control_scales = [strength * (0.825 ** float(12 - i)) for i in range(13)] if guess_mode else ([strength] * 13) # Magic number. IDK why. Perhaps because 0.825**12<0.01 but 0.826**12>0.01
samples, intermediates = ddim_sampler.sample(ddim_steps, num_samples,
shape, cond, verbose=False, eta=eta,
unconditional_guidance_scale=scale,
unconditional_conditioning=un_cond)

if config.save_memory:
model.low_vram_shift(is_diffusing=False)

x_samples = model.decode_first_stage(samples)
x_samples = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)

results = [x_samples[i] for i in range(num_samples)]
```
How to catch the color in input image and depict in output image?
I think that I will fix this question by modifying the code that detects the boundary. right?
I'll be waiting for your good opinions.

Thank you.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the boundary-detection block that builds detected_map, then trace how control is passed through the ControlNet conditioning path. Compare the input colors with generated outputs and determine whether changing the boundary map can preserve color information. Done would require a documented, reproducible approach that depicts the requested colors in the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python, pytorch
Domain
computer-vision, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.