MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / apply_overlay

Method apply_overlay

src/diffusers/image_processor.py:612–645  ·  view source on GitHub ↗

overlay the inpaint output to the original image

(
        self,
        mask: PIL.Image.Image,
        init_image: PIL.Image.Image,
        image: PIL.Image.Image,
        crop_coords: Optional[Tuple[int, int, int, int]] = None,
    )

Source from the content-addressed store, hash-verified

610 return self.numpy_to_pil(image)
611
612 def apply_overlay(
613 self,
614 mask: PIL.Image.Image,
615 init_image: PIL.Image.Image,
616 image: PIL.Image.Image,
617 crop_coords: Optional[Tuple[int, int, int, int]] = None,
618 ) -> PIL.Image.Image:
619 """
620 overlay the inpaint output to the original image
621 """
622
623 width, height = image.width, image.height
624
625 init_image = self.resize(init_image, width=width, height=height)
626 mask = self.resize(mask, width=width, height=height)
627
628 init_image_masked = PIL.Image.new("RGBa", (width, height))
629 init_image_masked.paste(init_image.convert("RGBA").convert("RGBa"), mask=ImageOps.invert(mask.convert("L")))
630 init_image_masked = init_image_masked.convert("RGBA")
631
632 if crop_coords is not None:
633 x, y, x2, y2 = crop_coords
634 w = x2 - x
635 h = y2 - y
636 base_image = PIL.Image.new("RGBA", (width, height))
637 image = self.resize(image, height=h, width=w, resize_mode="crop")
638 base_image.paste(image, (x, y))
639 image = base_image.convert("RGB")
640
641 image = image.convert("RGBA")
642 image.alpha_composite(init_image_masked)
643 image = image.convert("RGB")
644
645 return image
646
647
648class VaeImageProcessorLDM3D(VaeImageProcessor):

Callers 4

__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80

Calls 2

resizeMethod · 0.95
invertMethod · 0.45

Tested by

no test coverage detected