From 571ce2d36105492e9ab444c8936af3519f3058ca Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Thu, 25 Jan 2024 00:17:43 +0100 Subject: [PATCH] Make Fill Alpha output the alpha channel --- .../image_channel/misc/fill_alpha.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/src/packages/chaiNNer_standard/image_channel/misc/fill_alpha.py b/backend/src/packages/chaiNNer_standard/image_channel/misc/fill_alpha.py index 1808c224b..e7d9608e8 100644 --- a/backend/src/packages/chaiNNer_standard/image_channel/misc/fill_alpha.py +++ b/backend/src/packages/chaiNNer_standard/image_channel/misc/fill_alpha.py @@ -25,10 +25,10 @@ class AlphaFillMethod(Enum): @node_group.register( schema_id="chainner:image:fill_alpha", name="Fill Alpha", - description=("Fills the transparent pixels of an image with nearby colors."), + description="Splits the image into color and transparency, and fills the transparent pixels of an image with nearby colors.", icon="MdOutlineFormatColorFill", inputs=[ - ImageInput("RGBA", channels=4), + ImageInput(channels=4), EnumInput(AlphaFillMethod, label="Fill Method"), ], outputs=[ @@ -37,11 +37,20 @@ class AlphaFillMethod(Enum): image_type=navi.Image(size_as="Input0"), channels=3, ), + ImageOutput( + "Alpha", + image_type=navi.Image(size_as="Input0"), + channels=1, + ), ], ) -def fill_alpha_node(img: np.ndarray, method: AlphaFillMethod) -> np.ndarray: +def fill_alpha_node( + img: np.ndarray, method: AlphaFillMethod +) -> tuple[np.ndarray, np.ndarray]: """Fills transparent holes in the given image""" + alpha = img[:, :, 3] + if method == AlphaFillMethod.EXTEND_TEXTURE: img = fill_alpha_fragment_blur( img, @@ -62,4 +71,4 @@ def fill_alpha_node(img: np.ndarray, method: AlphaFillMethod) -> np.ndarray: else: raise AssertionError(f"Invalid alpha fill method {method}") - return img[:, :, :3] + return img[:, :, :3], alpha