ComfyUI Extension: painting-by-colors-generator
Create a painting by colors image from an image
Custom Nodes (0)
README
ComfyUI-PaintingByColors
Create a painting-by-colors image from an image
[!NOTE] This projected was created with a cookiecutter template. It helps you start writing custom nodes without worrying about the Python setup.
Quickstart
- Install ComfyUI.
- Install ComfyUI-Manager
- Look up this extension in ComfyUI-Manager. If you are installing manually, clone this repository under
ComfyUI/custom_nodes
. - Restart ComfyUI.
Or manually by:
# Inside your ComfyUI root directory
cd custom_nodes
git clone https://github.com/your-name/comfyui-paint-by-numbers
pip install torch numpy pillow scikit-learn opencv-python scipy
Features
- Use arbitrary #RRGGBB values of colors you have lying around at home, so you don't have to go buy new colors.
- Paint by Numbers Preprocessor: K-Mean flattens colours with K-Means, optional bilateral smoothing, noise removal, and tiny-blob cleanup
- Paint by Numbers: Calculate numbers extracts regions, merges near-identical shades, picks centroids, and prints crisp numbers plus a printer-friendly palette sheet.
- Paint by Numbers: overlay Numbers: paste calculated numbers on a lineart.
Usage
- Load Image.
- Resize Image. Too big images will take too long to compute. I reccommend up to 3000px for the longest side
- (optional) fill in the "Hex Color Stack" with the colors you have lying around at home.
- "Paint by Numbers Preprocessor: K-Mean" will then reduce the amount of colors to either the specified amount or the amount of colors present in the Hex Stacker. I recommend putting white in the Stacker too (since most paper is white).
- Put the preprocessed image into a LineArt converter. Any converter is fine. Like the Controlnet ones. And invert it. I am using the AnyLineart Lineart.
- Put the preprocessed image into the "Paint by Numbers: Calculate numbers" node. This will then calculate where to place each number. It will output an image "numbers_image" where all numbers are placed on the image.
- Then combine the lineart and the numbers_image with the "Paint by Numbers: overlay Numbers". This write all black pixels from numbers_image onto input_image.
Example Workflow (with embedded workflow):
Example
- Original Image:
- Paint by Numbers Preprocessor: K-Mean
- Lineart:
- Numbers Image:
- numbers overlayed onto the lineart:
- numbers overlayed onto the k-mean:
Develop
To install the dev dependencies and pre-commit (will run the ruff hook), do:
cd paintingbycolors
pip install -e .[dev]
pre-commit install
The -e
flag above will result in a "live" install, in the sense that any changes you make to your node extension will
automatically be picked up the next time you run ComfyUI.
Tests
This repo contains unit tests written by Claude.AI in Pytest in the tests/
directory.
Something is wrong with the config right now. I might fix them if I find the time for it...
Publishing to Registry
If you wish to share this custom node with others in the community, you can publish it to the registry. We've already
auto-populated some fields in pyproject.toml
under tool.comfy
, but please double-check that they are correct.
You need to make an account on https://registry.comfy.org and create an API key token.
- [ ] Go to the registry. Login and create a publisher id (everything after the
@
sign on your registry profile). - [ ] Add the publisher id into the pyproject.toml file.
- [ ] Create an api key on the Registry for publishing from Github. Instructions.
- [ ] Add it to your Github Repository Secrets as
REGISTRY_ACCESS_TOKEN
.
A Github action will run on every git push. You can also run the Github action manually. Full instructions here. Join our discord if you have any questions!