-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recomposite color correct improvements (broken out of Small Improvements) #597
Comments
First thing, I ported mcmonkey's original code from the discord into a test fork (https://github.com/willhsmit/SwarmUI) to test it out. Here's an example of it working well on an image where the fill boundary is mostly same color - you can see an ugly seam around the 'sample' text in Before, that more or less goes away with correction. Before: After: And an example of it working less well where the fill area has a mixture of white, purple, and black. Before: After: |
The original proposed solution to this was some version of using the gradient - modeling the diff not as a uniform value but as some kind of function over space to a diff, trying to blend in the values from different sides with a gradient. I think this could get hairy for a couple reasons:
One thing that occurs to me is that the VAE for flux fill might be producing mismatched colors in a consistent way. I did some spot checks around a boundary, and it looks like:
Particularly effect 1 made me wonder if instead modelling the diff as a uniform offset to HSV, we might get better results from modelling the diff as a linear function on the source pixel HSV. I did an experiment with a linear color correction in my fork. It's pretty similar to the uniform correction on the mask with a uniform boundary color (the dark letters in the center of the image are a little darker than uniform correction): On the mixed boundary color, it does a better job than uniform correction on the white and black areas of the image, although the seam is still pretty obvious on the purple part of the image. I think one issue to improve here might be for very dark pixels where V is low, H and S vary pretty wildly. Some approaches there might be:
It might also be the case that the way Flux VAE affects colors might be so consistent that instead of estimating the color correction function at runtime, the code could have a preset correction function; this would make correction less dependent on how much variation is in the masked area, would make it easier to have a more complicated than linear function, and would open the possibility of correcting non-inpainted images like pure t2i generations. |
The linear color correction method produced pretty strong modifications to Hue. I tried defaulting Hue to a flat linear correction, and then defaulting hue to no correction at all, and I think leaving hue out of the correction process produces the best results. I haven't tested 'Uniform correction to SV, no correction to H' but 'Linear correction to SV, no correction to H' looks pretty smooth: |
Some vague ideas for further experiments within the linear function include:
|
I made some tests where:
Uncorrected: (The mask region is from the neck down to a bit above the elbow) Linear:
Uncorrected: Linear: |
Yes for reference this is actually the original reason for this topic: Flux VAE does not color-match itself, it has global-inconsistency. If you drop mask blur to 0 you can see it much more clearly |
I did an experiment with trying to run hue through diff = (((diff + 0.5) % 1.0) - 0.5) to check for cases where, say, source is 0.01 and dest is 0.99. This did reduce the size of the hue correction, but it still looks worse in tests than leaving hue uncorrected. |
Yeah leaving hue uncorrected is probably the right move. It's mostly |
Pulled the current state of the PR. In a quick and dirty test, it seems to still not quite be good enough to fix Flux being silly. Tried Uncorrected linear uniform In all cases, there's a visible "dark circle" where the selection was made. Just letting Mask Blur run still is the best way to combat coloration mixups in inpaints :( (Note ftr my setup here is intentionally unoptimal, a hard manual mask with blur off is basically worst case scenario, a blur or a generated segment mask will hide the color mismatch a decent bit, I'm intentionally forcing the color mismatch to show to test if this code can do much to fix it) |
Yes. As a practical matter, I think mask shrink grow makes a big difference with or without blur, because the unchanged pixels it uses for reference are physically closer, and usually more similar, to the ones at the seam. But there are definitely cases where each of the correction methods doesn't help much, or makes one part of the seam better and another worse. When I do a similar test to yours, it looks like on linear the slope of both the S and V corrections are below 1 on the full image, which is a sign it's probably making things worse instead of better, and then go back above 1 for either a mask shrink grow tight on the face or one that's wider but still mainly foreground and not background. I guess one way the algorithm could try to adjust for this would be to not use all the thresholded pixels, but to use only thresholded pixels near unthresholded pixels, ie focusing on examples around the seam. The danger here is focusing too heavily on the seam could give a bad color correction for any new content that's not near the seam, like if the woman's head were completely surrounded by white and the algorithm matched the white boundary perfectly at the expense of removing a lot of contrast in the head. |
Feature Idea
Opening a separate feature thread for the 'Recomposite color correct' for flux fill feature mentioned in #550. Original description:
The discord link has code that compares the old and new pixels outside the mask, computes the average difference between them in HSV, and applies that uniformly to the pixels inside the mask. The discord also suggests some areas of improvement:
Other
No response
The text was updated successfully, but these errors were encountered: