Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 authored and ruchej committed Sep 30, 2024
1 parent 359472b commit bff9a98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
15 changes: 0 additions & 15 deletions modules/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,6 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s
if shared.opts.enable_console_prompts:
print(f"\nimg2img: {prompt}", file=shared.progress_print_out)

if mask:
p.extra_generation_params["Mask blur"] = mask_blur

if inpainting_mask_invert is not None:
p.extra_generation_params["Mask mode"] = inpainting_mask_invert

if inpainting_fill is not None:
p.extra_generation_params["Masked content"] = inpainting_fill

if inpaint_full_res is not None:
p.extra_generation_params["Inpaint area"] = inpaint_full_res

if inpaint_full_res_padding is not None:
p.extra_generation_params["Only masked padding, pixels"] = inpaint_full_res_padding

with closing(p):
if is_batch:
assert not shared.cmd_opts.hide_ui_dir_config, "Launched with --hide-ui-dir-config, batch img2img disabled"
Expand Down
12 changes: 12 additions & 0 deletions modules/infotext_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ def parse_generation_parameters(x: str):
if "Hires negative prompt" not in res:
res["Hires negative prompt"] = ""

if "Mask mode" not in res:
res["Mask mode"] = "Inpaint masked"

if "Masked content" not in res:
res["Masked content"] = 'original'

if "Inpaint area" not in res:
res["Inpaint area"] = "Whole picture"

if "Masked area padding" not in res:
res["Masked area padding"] = 32

restore_old_hires_fix_params(res)

# Missing RNG means the default was set, which is GPU RNG
Expand Down
13 changes: 13 additions & 0 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):

if self.inpainting_mask_invert:
image_mask = ImageOps.invert(image_mask)
self.extra_generation_params["Mask mode"] = "Inpaint not masked"

if self.mask_blur_x > 0:
np_mask = np.array(image_mask)
Expand All @@ -1553,6 +1554,9 @@ def init(self, all_prompts, all_seeds, all_subseeds):
np_mask = cv2.GaussianBlur(np_mask, (1, kernel_size), self.mask_blur_y)
image_mask = Image.fromarray(np_mask)

if self.mask_blur_x > 0 or self.mask_blur_y > 0:
self.extra_generation_params["Mask blur"] = self.mask_blur

if self.inpaint_full_res:
self.mask_for_overlay = image_mask
mask = image_mask.convert('L')
Expand All @@ -1563,6 +1567,9 @@ def init(self, all_prompts, all_seeds, all_subseeds):
mask = mask.crop(crop_region)
image_mask = images.resize_image(2, mask, self.width, self.height)
self.paste_to = (x1, y1, x2-x1, y2-y1)

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)
Expand Down Expand Up @@ -1604,6 +1611,9 @@ def init(self, all_prompts, all_seeds, all_subseeds):
if self.inpainting_fill != 1:
image = masking.fill(image, latent_mask)

if self.inpainting_fill == 0:
self.extra_generation_params["Masked content"] = 'fill'

if add_color_corrections:
self.color_corrections.append(setup_color_correction(image))

Expand Down Expand Up @@ -1653,8 +1663,11 @@ def init(self, all_prompts, all_seeds, all_subseeds):
# this needs to be fixed to be done in sample() using actual seeds for batches
if self.inpainting_fill == 2:
self.init_latent = self.init_latent * self.mask + create_random_tensors(self.init_latent.shape[1:], all_seeds[0:self.init_latent.shape[0]]) * self.nmask
self.extra_generation_params["Masked content"] = 'latent noise'

elif self.inpainting_fill == 3:
self.init_latent = self.init_latent * self.mask
self.extra_generation_params["Masked content"] = 'latent nothing'

self.image_conditioning = self.img2img_image_conditioning(image * 2 - 1, self.init_latent, image_mask, self.mask_round)

Expand Down

0 comments on commit bff9a98

Please sign in to comment.