AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
136.48k stars 26k forks source link

Integrate Color Correction to prevent color distortion #363

Closed Kim2091 closed 1 year ago

Kim2091 commented 1 year ago

Is your feature request related to a problem? Please describe. While using img2img, images frequently come out with blue-magenta color distortion on objects.

Describe the solution you'd like Pyrocube has fixed this with this commit: https://github.com/Pyr-000/YetAnotherStableDiffusion/commit/b8751862de557edd0cad2d9f7e4b4e46c3f3042c

Additional context Here's an example: unknown

cvar66 commented 1 year ago

This would be a nice improvement. When looping img2img images I have to keep desaturating them because of this.

Goldenkoron commented 1 year ago

This sounds related to my issue here https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/220

Sounds great if someone found a way to fix this.

AUTOMATIC1111 commented 1 year ago

This is already enabled for loopback, just not for normal img2img.

AUTOMATIC1111 commented 1 year ago

Provide a concrete example of full generation parameters and initial image for me to reproduce it and clearly see the color distortion.

Goldenkoron commented 1 year ago

This is already enabled for loopback, just not for normal img2img.

Oh that makes sense now, is there a problem with enabling it for normal img2img?

AUTOMATIC1111 commented 1 year ago

i need to be able to reproduce it to make sure that whatever I'm enabling works.

Goldenkoron commented 1 year ago

Here's an image that works well for testing it. 1

This one is after 5 manual loopbacks, denoise strength set to 0 to show that it's not just natural color change as a result of changing the image. 00003-2081638904-

AUTOMATIC1111 commented 1 year ago

denoising strength of 0 is not really something that is meant to work as then you only get 1 sampling step and it is waht causes the distortion

Goldenkoron commented 1 year ago

denoising strength of 0 is not really something that is meant to work as then you only get 1 sampling step and it is waht causes the distortion

I see that makes sense. I did test with 100 steps 0.05 denoise and the same anomalies still appear, the red turns toward magenta and parts of skin turn purple. This happens to me on most of my img2img projects where I regenerate the full image more than a few times.

AUTOMATIC1111 commented 1 year ago

100 steps 0.05 is still one sampler step... This kind of operation just does not make sense. You are meant to get weird results from it. What I'd like to see is normal img2img operation that produces those distortions the issue is about.

Goldenkoron commented 1 year ago

This is one img2img project that it stood out the most to me. Images with blues and the slightly red tinted background will progressive become worse toward this no matter what I do 1

Second image after 5 manual loopbacks at 0.25 denoise and 150 steps 00004-2772551460-Myne  Rozemyne  Ascendence of a Bookworm  Frilly dress  Sitting on wooden window sill  Ufotable  Kyoto Animation  A-1 Pictures

Another example in an actual project where I was stuck, see the mask abberation from my inpainting right above the book 00005-4277650002-Myne  Rozemyne  Ascendence of a Bookworm  Frilly dress  Sitting on wooden window sill  Ufotable  Kyoto Animation  A-1 Pictures

First attempt to fix with inpainting (original) at 0.25 denoise and 150 steps just makes it worse 00005-4277650002-Myne  Rozemyne  Ascendence of a Bookworm  Frilly dress  Sitting on wooden window sill  Ufotable  Kyoto Animation  A-1 Pictures

Second attempt to fix by regenerating whole image at 0.15 denoise and 150 steps, the entire image instead turns to that stronger red tint 00006-3615661732-Myne  Rozemyne  Ascendence of a Bookworm  Frilly dress  Sitting on wooden window sill  Ufotable  Kyoto Animation  A-1 Pictures

Same result happens on loopback mode too with same settings. I don't understand why the entire background needs to have such a dramatic change to its color tint.

As for purple abberations on some images, that might be a separate problem with Stable Diffusion, here's some examples.

Notice the purple on the arm 16

I covered over the arm in MS paint 17

After regenerating the image at 150 steps 0.15 denoise (effectively 23 steps) 00009-2850267362-A girl sitting in a tree  Detailed art  Ufotable  Madhouse  3Hz  Kyoto Animation  MAPPA  Wit Studio  Bones  Studio Bind  Aniplex

I call it the purple cancer, once it shows up anywhere in an image, no amount of inpainting or full img2img will get rid of it and it will only get severe from the point it appears and the only option is to manually photo edit it when you're done.

Goldenkoron commented 1 year ago

Another take on above example I gave, I tried increasing my max steps to 500 and did a 0.05 denoise img2img (51 steps)

11

00009-3922954293-Myne  Rozemyne  Ascendence of a Bookworm  Frilly dress  Sitting on wooden window sill  Ufotable  Kyoto Animation  A-1 Pictures

Much improved image but once again if you look at them side by side the whole background turned a more red/purple than before.

EDIT: All the examples I've given were taken at cfg 9 and same results happened with or without a prompt. I've manually tested before at different cfg levels and prompts and they never affected the color shift problem.

Mozoloa commented 1 year ago

I'm getting the exact same problem, was working on a sunset prompt yesterday and even 1 generation later I could see a pretty significant magenta-ish shift. I might try to do this with some color chart to see what correction is needed

AUTOMATIC1111 commented 1 year ago

explorer_iG1psZbDAS

I added an option to settings where you can choose to apply color correction to all img2img results. Top row is without it, bottom is with.

Goldenkoron commented 1 year ago

explorer_iG1psZbDAS

I added an option to settings where you can choose to apply color correction to all img2img results. Top row is without it, bottom is with.

Thank you! This solved color shift problem for me. I did test to see if it had any effect on the purple cancer creeping issue but I guess it must be another problem. I also had it on the hlky GUI fork so I think it's an abberation related to SD in general.

That issue was not as big for me as the color correction you just implemented fixed though.

Mozoloa commented 1 year ago

Apparently people are having weird results with the colours and the fix still doesn't fix exposure from what I can see, so I carefully created a lut that offsets the shift in #410, if someone knows how to code a lut post processing option that'd be nifty

Kim2091 commented 1 year ago

I'm still running into the issue even after the update, so I agree it's not quite fixed. It is better though

Mozoloa commented 1 year ago

If you have a recent update then it's been disabled by default, maybe that's it, otherwise yes it's a quick fix, I think it's just trying to match the histogram from what I've seen in the code

Kim2091 commented 1 year ago

image Is it this setting?

Mozoloa commented 1 year ago

Yep, it should be off by default now

SirProdigle commented 1 year ago

Agree that it's better but not a complete fix. Used to get to a purple/blue mush after 10 or so iterations, the color shift is very visible now around iteration 40

Mozoloa commented 1 year ago

If you guys use photoshop want to try out my lut, check out #410

hardkur commented 1 year ago

pls make these switchable , image2image is desaturating the crap out of my pictures at the moment :/

Mozoloa commented 1 year ago

pls make these switchable , image2image is desaturating the crap out of my pictures at the moment :/

It already is, look, like, 4 messages above

hardkur commented 1 year ago

pls make these switchable , image2image is desaturating the crap out of my pictures at the moment :/

It already is, look, like, 4 messages above

lol it grow so fast :D i didnt even noticed . thx