r""" Applies an overlay of the mask and the inpainted image on the original image. Args: mask (`PIL.Image.Image`): The mask image that highlights regions to overlay. init_image (`PIL.Image.Image`): The original image to which t
(
self,
mask: PIL.Image.Image,
init_image: PIL.Image.Image,
image: PIL.Image.Image,
crop_coords: tuple[int, int, int, int] | None = None,
)
| 786 | return self.numpy_to_pil(image) |
| 787 | |
| 788 | def apply_overlay( |
| 789 | self, |
| 790 | mask: PIL.Image.Image, |
| 791 | init_image: PIL.Image.Image, |
| 792 | image: PIL.Image.Image, |
| 793 | crop_coords: tuple[int, int, int, int] | None = None, |
| 794 | ) -> PIL.Image.Image: |
| 795 | r""" |
| 796 | Applies an overlay of the mask and the inpainted image on the original image. |
| 797 | |
| 798 | Args: |
| 799 | mask (`PIL.Image.Image`): |
| 800 | The mask image that highlights regions to overlay. |
| 801 | init_image (`PIL.Image.Image`): |
| 802 | The original image to which the overlay is applied. |
| 803 | image (`PIL.Image.Image`): |
| 804 | The image to overlay onto the original. |
| 805 | crop_coords (`tuple[int, int, int, int]`, *optional*): |
| 806 | Coordinates to crop the image. If provided, the image will be cropped accordingly. |
| 807 | |
| 808 | Returns: |
| 809 | `PIL.Image.Image`: |
| 810 | The final image with the overlay applied. |
| 811 | """ |
| 812 | |
| 813 | width, height = init_image.width, init_image.height |
| 814 | |
| 815 | init_image_masked = PIL.Image.new("RGBa", (width, height)) |
| 816 | init_image_masked.paste(init_image.convert("RGBA").convert("RGBa"), mask=ImageOps.invert(mask.convert("L"))) |
| 817 | |
| 818 | init_image_masked = init_image_masked.convert("RGBA") |
| 819 | |
| 820 | if crop_coords is not None: |
| 821 | x, y, x2, y2 = crop_coords |
| 822 | w = x2 - x |
| 823 | h = y2 - y |
| 824 | base_image = PIL.Image.new("RGBA", (width, height)) |
| 825 | image = self.resize(image, height=h, width=w, resize_mode="crop") |
| 826 | base_image.paste(image, (x, y)) |
| 827 | image = base_image.convert("RGB") |
| 828 | |
| 829 | image = image.convert("RGBA") |
| 830 | image.alpha_composite(init_image_masked) |
| 831 | image = image.convert("RGB") |
| 832 | |
| 833 | return image |
| 834 | |
| 835 | |
| 836 | class InpaintProcessor(ConfigMixin): |
no test coverage detected