This project implements K-Means Clustering for image quantization using CUDA acceleration to significantly improve performance. The application is built with PyTorch (CUDA), NumPy, OpenCV, and Tkinter for an interactive GUI.
- GPU-Accelerated K-Means Clustering using PyTorch CUDA tensors.
- Tkinter GUI for easy image selection and quantization.
- Adjustable Number of Colors to control the level of quantization.
- Performance Timer to display execution time.
- Supports Various Image Formats including JPG, PNG, and BMP.
- Programming Language: Python 3
- Libraries: PyTorch, NumPy, OpenCV, Tkinter, PIL (Pillow)
- CUDA Support: GPU acceleration for fast clustering
Ensure you have the following installed:
- Python 3.10+
- CUDA-compatible GPU
- PyTorch with CUDA
- Required Python libraries
- Clone the repository:
git clone https://github.com/The-Silly-Glitch/Color-Quantization-Using-Cuda.git cd Color-Quantization-Using-Cuda
- Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
To start the application, run:
python gui.py
- Click Browse Image and select an image.
- Enter the desired number of colors (clusters).
- Click Quantize Image to process the image.
- View execution time and preview the quantized image.
- Click Save Quantized Image to save the output.
Image Size | CPU Execution Time | CUDA Execution Time |
---|---|---|
512×512 | ~5s | ~0.8s |
1024×768 | ~12s | ~1.5s |
1920×1080 | ~30s | ~3.5s |
├── src
│ ├── gui.py # GUI application
│ ├── kmeans_clustering.py # CUDA-accelerated K-Means
│ ├── image_processor.py # Image loading and processing
├── requirements.txt # Required dependencies
├── README.md # Project documentation
- Implement Mini-Batch K-Means for further speedup.
- Add support for custom distance metrics.
- Improve color accuracy with alternative initialization techniques.