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

Fix images do not match / Coordinate 'right' is less than 'left' #15534

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def get_crop_region(mask, pad=0):
if box:
x1, y1, x2, y2 = box
else: # when no box is found
x1, y1 = mask_img.size
x2 = y2 = 0
x1 = y1 = 0
x2, y2 = mask_img.size
Copy link
Collaborator

@w-e-w w-e-w Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some context

I specifically keep odd behavior exactly the same as before
even though it would cause an error if the box is not found in paint pipeline

in a way this function is a method of detecting if there's any non 0 (black) pixel in a image
the reason being that this function is also used by extensions
so it is possible that the extension is expecting the value to be invalid region (x1 > x2, y1> y2) as an indication that the image is all 0 and perform different actions based on it the this result

my priority at that point was compatibility, even though I don't know if any extension is relying on this behavior

if we want to play it safe it is better that in only masked inpaint mask region pipeline add a chack of invalid regions as opposed to changing the behavior of the function

but when performing only masked inpaint mask region, if you supply a mask is complete black, it essentially means that nothing needs to be changed, so functionally it doesn't matter if it errors or not
that's why I didn't add the check back then

Copy link
Contributor Author

@storyicon storyicon Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had noticed this work (#14709) of yours when I submitted this PR but hadn't thought of it as a compatibility consideration, thanks for the tip, it's really interesting and I'll edit the submission here.

return max(x1 - pad, 0), max(y1 - pad, 0), min(x2 + pad, mask_img.size[0]), min(y2 + pad, mask_img.size[1])


Expand Down
4 changes: 3 additions & 1 deletion modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,9 @@ def init(self, all_prompts, all_seeds, all_subseeds):
if self.mask_blur_x > 0 or self.mask_blur_y > 0:
self.extra_generation_params["Mask blur"] = self.mask_blur

if image_mask.size != (self.width, self.height):
image_mask = images.resize_image(self.resize_mode, image_mask, self.width, self.height)

if self.inpaint_full_res:
self.mask_for_overlay = image_mask
mask = image_mask.convert('L')
Expand All @@ -1551,7 +1554,6 @@ def init(self, all_prompts, all_seeds, all_subseeds):
self.extra_generation_params["Inpaint area"] = "Only masked"
self.extra_generation_params["Masked area padding"] = self.inpaint_full_res_padding
else:
image_mask = images.resize_image(self.resize_mode, image_mask, self.width, self.height)
np_mask = np.array(image_mask)
np_mask = np.clip((np_mask.astype(np.float32)) * 2, 0, 255).astype(np.uint8)
self.mask_for_overlay = Image.fromarray(np_mask)
Expand Down
Loading