内置节点
简体中文
自动移除图像背景并生成透明Alpha通道的 Recraft API 节点
class RecraftRemoveBackgroundNode: """ Remove background from image, and return processed image and mask. """ RETURN_TYPES = (IO.IMAGE, IO.MASK) DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value FUNCTION = "api_call" API_NODE = True CATEGORY = "api node/image/Recraft" @classmethod def INPUT_TYPES(s): return { "required": { "image": (IO.IMAGE, ), }, "optional": { }, "hidden": { "auth_token": "AUTH_TOKEN_COMFY_ORG", }, } def api_call( self, image: torch.Tensor, auth_token=None, **kwargs, ): images = [] total = image.shape[0] pbar = ProgressBar(total) for i in range(total): sub_bytes = handle_recraft_file_request( image=image[i], path="/proxy/recraft/images/removeBackground", auth_token=auth_token, ) images.append(torch.cat([bytesio_to_image_tensor(x) for x in sub_bytes], dim=0)) pbar.update(1) images_tensor = torch.cat(images, dim=0) # use alpha channel as masks, in B,H,W format masks_tensor = images_tensor[:,:,:,-1:].squeeze(-1) return (images_tensor, masks_tensor)
此页面对您有帮助吗?