@@ -740,7 +740,6 @@ def __init__(self, init_images: list=None, resize_mode: int=0, denoising_strengt
740
740
self .denoising_strength : float = denoising_strength
741
741
self .init_latent = None
742
742
self .image_mask = mask
743
- #self.image_unblurred_mask = None
744
743
self .latent_mask = None
745
744
self .mask_for_overlay = None
746
745
self .mask_blur = mask_blur
@@ -756,36 +755,36 @@ def init(self, all_prompts, all_seeds, all_subseeds):
756
755
self .sampler = sd_samplers .create_sampler (self .sampler_name , self .sd_model )
757
756
crop_region = None
758
757
759
- if self .image_mask is not None :
760
- self .image_mask = self .image_mask .convert ('L' )
758
+ image_mask = self .image_mask
761
759
762
- if self . inpainting_mask_invert :
763
- self . image_mask = ImageOps . invert ( self . image_mask )
760
+ if image_mask is not None :
761
+ image_mask = image_mask . convert ( 'L' )
764
762
765
- #self.image_unblurred_mask = self.image_mask
763
+ if self .inpainting_mask_invert :
764
+ image_mask = ImageOps .invert (image_mask )
766
765
767
766
if self .mask_blur > 0 :
768
- self . image_mask = self . image_mask .filter (ImageFilter .GaussianBlur (self .mask_blur ))
767
+ image_mask = image_mask .filter (ImageFilter .GaussianBlur (self .mask_blur ))
769
768
770
769
if self .inpaint_full_res :
771
- self .mask_for_overlay = self . image_mask
772
- mask = self . image_mask .convert ('L' )
770
+ self .mask_for_overlay = image_mask
771
+ mask = image_mask .convert ('L' )
773
772
crop_region = masking .get_crop_region (np .array (mask ), self .inpaint_full_res_padding )
774
773
crop_region = masking .expand_crop_region (crop_region , self .width , self .height , mask .width , mask .height )
775
774
x1 , y1 , x2 , y2 = crop_region
776
775
777
776
mask = mask .crop (crop_region )
778
- self . image_mask = images .resize_image (2 , mask , self .width , self .height )
777
+ image_mask = images .resize_image (2 , mask , self .width , self .height )
779
778
self .paste_to = (x1 , y1 , x2 - x1 , y2 - y1 )
780
779
else :
781
- self . image_mask = images .resize_image (self .resize_mode , self . image_mask , self .width , self .height )
782
- np_mask = np .array (self . image_mask )
780
+ image_mask = images .resize_image (self .resize_mode , image_mask , self .width , self .height )
781
+ np_mask = np .array (image_mask )
783
782
np_mask = np .clip ((np_mask .astype (np .float32 )) * 2 , 0 , 255 ).astype (np .uint8 )
784
783
self .mask_for_overlay = Image .fromarray (np_mask )
785
784
786
785
self .overlay_images = []
787
786
788
- latent_mask = self .latent_mask if self .latent_mask is not None else self . image_mask
787
+ latent_mask = self .latent_mask if self .latent_mask is not None else image_mask
789
788
790
789
add_color_corrections = opts .img2img_color_correction and self .color_corrections is None
791
790
if add_color_corrections :
@@ -797,7 +796,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
797
796
if crop_region is None :
798
797
image = images .resize_image (self .resize_mode , image , self .width , self .height )
799
798
800
- if self . image_mask is not None :
799
+ if image_mask is not None :
801
800
image_masked = Image .new ('RGBa' , (image .width , image .height ))
802
801
image_masked .paste (image .convert ("RGBA" ).convert ("RGBa" ), mask = ImageOps .invert (self .mask_for_overlay .convert ('L' )))
803
802
@@ -807,7 +806,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
807
806
image = image .crop (crop_region )
808
807
image = images .resize_image (2 , image , self .width , self .height )
809
808
810
- if self . image_mask is not None :
809
+ if image_mask is not None :
811
810
if self .inpainting_fill != 1 :
812
811
image = masking .fill (image , latent_mask )
813
812
@@ -839,7 +838,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
839
838
840
839
self .init_latent = self .sd_model .get_first_stage_encoding (self .sd_model .encode_first_stage (image ))
841
840
842
- if self . image_mask is not None :
841
+ if image_mask is not None :
843
842
init_mask = latent_mask
844
843
latmask = init_mask .convert ('RGB' ).resize ((self .init_latent .shape [3 ], self .init_latent .shape [2 ]))
845
844
latmask = np .moveaxis (np .array (latmask , dtype = np .float32 ), 2 , 0 ) / 255
@@ -856,7 +855,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
856
855
elif self .inpainting_fill == 3 :
857
856
self .init_latent = self .init_latent * self .mask
858
857
859
- self .image_conditioning = self .img2img_image_conditioning (image , self .init_latent , self . image_mask )
858
+ self .image_conditioning = self .img2img_image_conditioning (image , self .init_latent , image_mask )
860
859
861
860
def sample (self , conditioning , unconditional_conditioning , seeds , subseeds , subseed_strength , prompts ):
862
861
x = create_random_tensors ([opt_C , self .height // opt_f , self .width // opt_f ], seeds = seeds , subseeds = subseeds , subseed_strength = self .subseed_strength , seed_resize_from_h = self .seed_resize_from_h , seed_resize_from_w = self .seed_resize_from_w , p = self )
0 commit comments