MCPcopy Create free account
hub / github.com/Chen-Yang-Liu/Text2Earth / apply_overlay

Method apply_overlay

src/diffusers/image_processor.py:651–684  ·  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

649 return self.numpy_to_pil(image)
650
651 def apply_overlay(
652 self,
653 mask: PIL.Image.Image,
654 init_image: PIL.Image.Image,
655 image: PIL.Image.Image,
656 crop_coords: Optional[Tuple[int, int, int, int]] = None,
657 ) -> PIL.Image.Image:
658 """
659 overlay the inpaint output to the original image
660 """
661
662 width, height = image.width, image.height
663
664 init_image = self.resize(init_image, width=width, height=height)
665 mask = self.resize(mask, width=width, height=height)
666
667 init_image_masked = PIL.Image.new("RGBa", (width, height))
668 init_image_masked.paste(init_image.convert("RGBA").convert("RGBa"), mask=ImageOps.invert(mask.convert("L")))
669 init_image_masked = init_image_masked.convert("RGBA")
670
671 if crop_coords is not None:
672 x, y, x2, y2 = crop_coords
673 w = x2 - x
674 h = y2 - y
675 base_image = PIL.Image.new("RGBA", (width, height))
676 image = self.resize(image, height=h, width=w, resize_mode="crop")
677 base_image.paste(image, (x, y))
678 image = base_image.convert("RGB")
679
680 image = image.convert("RGBA")
681 image.alpha_composite(init_image_masked)
682 image = image.convert("RGB")
683
684 return image
685
686
687class VaeImageProcessorLDM3D(VaeImageProcessor):

Callers 5

__call__Method · 0.80
__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