Repository: Jcd1230/rembg-comfyui-node Branch: master Commit: fac7df6c3f42 Files: 3 Total size: 1.7 KB Directory structure: gitextract_5n36fn9p/ ├── README.md ├── __init__.py └── requirements.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # [Rembg](https://github.com/danielgatis/rembg) Background Removal Node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) 1. Clone to your `custom_nodes` folder in ComfyUI: ``` git clone https://github.com/Jcd1230/rembg-comfyui-node.git ``` 2. Install `rembg[gpu]` (recommended) or `rembg`, depending on GPU support, to your ComfyUI virtual environment. E.g.: ``` pip install rembg[gpu] ``` To use, just look for the *Image Remove Background (rembg)* node. ![Demonstration of the rembg node](https://i.imgur.com/12NEuyx.png) ## Acknowledgements Thanks to [WASasquatch's Node Suite](https://github.com/WASasquatch/was-node-suite-comfyui) for great examples and a couple helper functions. ================================================ FILE: __init__.py ================================================ from rembg import remove from PIL import Image import torch import numpy as np # Tensor to PIL def tensor2pil(image): return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)) # Convert PIL to Tensor def pil2tensor(image): return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0) class ImageRemoveBackgroundRembg: def __init__(self): pass @classmethod def INPUT_TYPES(s): return { "required": { "image": ("IMAGE",), }, } RETURN_TYPES = ("IMAGE",) FUNCTION = "remove_background" CATEGORY = "image" def remove_background(self, image): image = pil2tensor(remove(tensor2pil(image))) return (image,) # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "Image Remove Background (rembg)": ImageRemoveBackgroundRembg } ================================================ FILE: requirements.txt ================================================ rembg