Full Code of Jcd1230/rembg-comfyui-node for AI

master fac7df6c3f42 cached
3 files
1.7 KB
549 tokens
6 symbols
1 requests
Download .txt
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
Download .txt
gitextract_5n36fn9p/

├── README.md
├── __init__.py
└── requirements.txt
Download .txt
SYMBOL INDEX (6 symbols across 1 files)

FILE: __init__.py
  function tensor2pil (line 7) | def tensor2pil(image):
  function pil2tensor (line 11) | def pil2tensor(image):
  class ImageRemoveBackgroundRembg (line 14) | class ImageRemoveBackgroundRembg:
    method __init__ (line 15) | def __init__(self):
    method INPUT_TYPES (line 19) | def INPUT_TYPES(s):
    method remove_background (line 30) | def remove_background(self, image):
Condensed preview — 3 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (2K chars).
[
  {
    "path": "README.md",
    "chars": 702,
    "preview": "# [Rembg](https://github.com/danielgatis/rembg) Background Removal Node for [ComfyUI](https://github.com/comfyanonymous/"
  },
  {
    "path": "__init__.py",
    "chars": 991,
    "preview": "from rembg import remove\nfrom PIL import Image\nimport torch\nimport numpy as np\n\n# Tensor to PIL\ndef tensor2pil(image):\n "
  },
  {
    "path": "requirements.txt",
    "chars": 6,
    "preview": "rembg\n"
  }
]

About this extraction

This page contains the full source code of the Jcd1230/rembg-comfyui-node GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 3 files (1.7 KB), approximately 549 tokens, and a symbol index with 6 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!