stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

Auto re-render black images

Open kelvinz opened this issue 2 years ago • 11 comments

Is your feature request related to a problem? Please describe. I'm running the ui on a Mac and am still getting around 5-10% of the generations as blank black images.

Describe the solution you'd like Hoping it's possible to auto detect after rendering that it is a black image and re-render instead of moving on to the next image. This would help greatly when doing grid generations to test stuff and having black spots dotted all over.

kelvinz avatar Oct 18 '22 14:10 kelvinz

When an output is a black image, running with the exact same parameters always results in a black image in my experience. Have you had a different experience?

asaucedev avatar Oct 18 '22 16:10 asaucedev

Does your model uses a .VAE file?

chekaaa avatar Oct 18 '22 20:10 chekaaa

@asaucedev re-running the same parameters work for me

kelvin-zhao avatar Oct 19 '22 05:10 kelvin-zhao

This would not work as a feature because if this WebUi is ever used by more than one person or ran in an automated fashion it would have a chance of generating forever.

e.g.

render -> 100 successes, 1 black picture -> rerender black picture

infinite loop.

AlphaJuliettOmega avatar Oct 19 '22 08:10 AlphaJuliettOmega

@AlphaJuliettOmega Not too sure why it would be an infinite loop as re-rendering with the same parameters and even seed managed to render the image properly for me. If there was an issue, perhaps it would include an option to re-try black images X number of times perhaps?

kelvin-zhao avatar Oct 19 '22 08:10 kelvin-zhao

@kelvin-zhao that seems quite sensible then, the next problem to solve is this:

How do you detect a black image, is is rgb(0,0,0) on every pixel 100% of the time?

Wouldn't want to accidentally cull views of starry skies or nighttime/dark scenes

AlphaJuliettOmega avatar Oct 19 '22 09:10 AlphaJuliettOmega

@kelvin-zhao that seems quite sensible then, the next problem to solve is this:

How do you detect a black image, is is rgb(0,0,0) on every pixel 100% of the time?

Wouldn't want to accidentally cull views of starry skies or nighttime/dark scenes

As an idea, you can estimate if a PNG is all a single color by file size compared to resolution Or in this kind of case, if there is an error causing the black generation, catching that would also work

asaucedev avatar Oct 19 '22 20:10 asaucedev

@kelvin-zhao I would imagine adding all the rgb of every pixel and if the total is less than perhaps 100, we can determine that the image is black.

kelvin-zhao avatar Oct 19 '22 23:10 kelvin-zhao

Ok, so now try put together a little python script that does that calculation, and if the image is 100% black pixels you're in luck

If there's any amount of noise, it will be harder to 'detect' / would need some slider/setting for a 'tolerance'

On Thu, 20 Oct 2022, 01:39 kelvin-zhao, @.***> wrote:

@kelvin-zhao https://github.com/kelvin-zhao I would imagine adding all the rgb of every pixel and if the total is less than perhaps 100, we can determine that the image is black.

— Reply to this email directly, view it on GitHub https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/3074#issuecomment-1284705210, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETJR6UO4BHKWQLO7FEFWITWECBCTANCNFSM6AAAAAARIFHUXE . You are receiving this because you were mentioned.Message ID: @.***>

AlphaJuliettOmega avatar Oct 19 '22 23:10 AlphaJuliettOmega

Ah I don't have any python experience though, I did try something similar in JavaScript before, would anyone be able to help convert that into python that can be implemented?

kelvin-zhao avatar Oct 20 '22 13:10 kelvin-zhao

I know how to detect black reliably, but I am not familiar with this repo's code enough to implement the re-rendering.

for i in response['images']:
  image = PIL.Image.open(io.BytesIO(base64.b64decode(i)))
  all_black = all([sum(image.getextrema()[channel]) == 0 for channel in range(3)])

aliencaocao avatar Nov 01 '22 05:11 aliencaocao

https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/23c947ab0374220c39ac54fc00afcb74e809dd95

catboxanon avatar Aug 03 '23 17:08 catboxanon