[
  {
    "path": "README.md",
    "content": "# [Rembg](https://github.com/danielgatis/rembg) Background Removal Node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI)\n1. Clone to your `custom_nodes` folder in ComfyUI:\n\n```\ngit clone https://github.com/Jcd1230/rembg-comfyui-node.git\n```\n\n2. Install `rembg[gpu]` (recommended) or `rembg`, depending on GPU support, to your ComfyUI virtual environment. E.g.:\n\n```\npip install rembg[gpu]\n```\n\n\nTo use, just look for the *Image Remove Background (rembg)* node.\n\n![Demonstration of the rembg node](https://i.imgur.com/12NEuyx.png)\n\n\n## Acknowledgements\nThanks to [WASasquatch's Node Suite](https://github.com/WASasquatch/was-node-suite-comfyui) for great examples and a couple helper functions.\n"
  },
  {
    "path": "__init__.py",
    "content": "from rembg import remove\nfrom PIL import Image\nimport torch\nimport numpy as np\n\n# Tensor to PIL\ndef tensor2pil(image):\n    return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))\n\n# Convert PIL to Tensor\ndef pil2tensor(image):\n    return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)\n\nclass ImageRemoveBackgroundRembg:\n    def __init__(self):\n        pass\n    \n    @classmethod\n    def INPUT_TYPES(s):\n        return {\n            \"required\": {\n                \"image\": (\"IMAGE\",),\n            },\n        }\n\n    RETURN_TYPES = (\"IMAGE\",)\n    FUNCTION = \"remove_background\"\n    CATEGORY = \"image\"\n\n    def remove_background(self, image):\n        image = pil2tensor(remove(tensor2pil(image)))\n        return (image,)\n\n\n# A dictionary that contains all nodes you want to export with their names\n# NOTE: names should be globally unique\nNODE_CLASS_MAPPINGS = {\n    \"Image Remove Background (rembg)\": ImageRemoveBackgroundRembg\n}\n"
  },
  {
    "path": "requirements.txt",
    "content": "rembg\n"
  }
]