Skip to content
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

Inpaint only mask switch to img2img if mask is blank #15579

Closed
wants to merge 1 commit into from

Conversation

w-e-w
Copy link
Collaborator

@w-e-w w-e-w commented Apr 20, 2024

Description

@storyicon

when performing Inpaint with only mask mode if the mask is blank (as in there's nothing to inpaint)
currently web UI would throw an error

ValueError: Coordinate 'right' is less than 'left'

Fundamentally there is no real issue during this error because there's nothing to do, but the message bit cryptic
they might even be a minor beneficial as in it stops unnecessary processing
but it could also be disrupted when you're doing a batch job scenario

so this is an alternative limitation that would instead perform normal img2img if the mask is blank

implemented using a try block as I think this makes the code more readable

if ValueError ever occurred performs img2img and shows a message

'Unable to perform "Inpaint Only mask" because mask is blank, switch to img2img mode.'

2024-04-20 23_54_29_542 chrome


in this PR I did not implement resizing of self.mask_for_overlay

unless my analysis is incorrect
that piece of code would only ever be triggered when performing Inpaint Only mask with a mask size different from the input image
if resizeing is peformed to the mask like in #15534, the resulting output would only be an inpaint with misaligned mask, the misalignment can vary from a little to a lot depending on the mask size difference
which in my viewpoint just makes the output erratic so the results will be erratic

if mask resizing is to be implementm for Inpaint Only mask, it should be performed before cropping of the mask
the issue is there is a certain quirk about the WebUI that makes making this a bit awkward

when using webui img2img vial API, it is possible to have multiple input images but only have ONE mask image

I personally would think that there is no reason that you would use the same mask for multiple images but that's how the code is written

I think if we would want to support resizing of the input mask for Inpaint Only mask, we should make it possible to also input multiple mask image as well to make things consistent

Checklist:

Co-Authored-By: storyicon <storyicon@foxmail.com>
@AUTOMATIC1111
Copy link
Owner

merged the other one because it had a more specific check for the situation instead of the general exception

@w-e-w
Copy link
Collaborator Author

w-e-w commented Apr 21, 2024

merged the other one because it had a more specific check for the situation instead of the general exception

I would argue that value error is very specific as this isthe behavior of PIL.Image.corp

https://github.com/python-pillow/Pillow/blob/5c89d88eee199ba53f64581ea39b6a1bc52feb1a/src/PIL/Image.py#L1219-L1240

        if box[2] < box[0]:
            msg = "Coordinate 'right' is less than 'left'"
            raise ValueError(msg)
        elif box[3] < box[1]:
            msg = "Coordinate 'lower' is less than 'upper'"
            raise ValueError(msg)

@w-e-w w-e-w mentioned this pull request Apr 21, 2024
4 tasks
@w-e-w w-e-w closed this Apr 21, 2024
@w-e-w w-e-w deleted the Inpaint-Only-masked-blank-mask branch June 28, 2024 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants