Skip to content

🎨 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

  1. Load an image.
  2. Process the pixels into a 2D format.
  3. Cluster colors using K-Means.
  4. Separate each color cluster into its own transparent stencil.
  5. 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


πŸ› οΈ 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