π¨ Pycht
Pycht is a lightweight Python tool that transforms images into colorful street art-style stencils using K-Means clustering.
It automatically reduces an imageβs color palette into distinct clusters and generates transparent PNG layers for each one β ideal for digital or physical stencil creation, creative coding projects, or simply exploring image segmentation.
β¨ Features
- π§ Simple image clustering using Scikit-Learnβs K-Means algorithm
- πΌοΈ Color separation with transparency masks
- π Input/output file handling with minimal setup
- π§° Modular architecture for easy extension
π How It Works
- Load an image.
- Process the pixels into a 2D format.
- Cluster colors using K-Means.
- Separate each color cluster into its own transparent stencil.
- Save the final image and each stencil layer as a
.png
.
π¦ Example Usage
import pycht
# Create a stencil with 5 color clusters
pycht.stencil("images/input.jpg", nb_colors=5)
This will generate: - stencil_final.png β final clustered image - stencil_1.png, stencil_2.png, etc. β one per color cluster, with transparency
π§ͺ Try It Out
Want to experiment? Just provide any image and see how it gets broken down into layers of color.
π Documentation
- Getting Started
- API Reference
π οΈ Technologies Used
- Python 3.12+
- OpenCV
- NumPy
- MkDocs (for this documentation!)
π Contributing
Pull requests are welcome! Feel free to open an issue or suggest improvements.
π License
MIT License Β© Thomas Lentali