Skip to content

Web application enabling compression of images using unsupervised machine learning algorithm.

Notifications You must be signed in to change notification settings

Manik2000/unsupervised-ml-image-compression

Repository files navigation

Images compression using unsupervised ML

This project is focused on applying PCA and clustering methods (mini batch K-means) to image compression problem.

scikit-learn implementations of both algorithms are used. More on how these methods can be used to compress images can be found in the notebooks directory.

Note: Python >= 3.10 is required!

Web application

Web application is deployed on Streamlit Community Cloud. You can experiment and have fun on your own here 🔥.

Results

Below you can see an examplary output of using clustering for image compression.

Original image Compressed image with K = 10 Compressed image with K = 50

Project structure

.
├── Dockerfile <- Dockerfile for building the image
├── Main_page.py <- main Python file defining Streamlit app
├── README.md
├── images <- directory with sample images
├── notebooks 
│   ├── clustering.ipynb <- notebook showcasing clustering compression
│   └── pca.ipynb <- notebook showcasing PCA compression
├── pages
│   ├── Clustering_compression.py <- sybpage with clustering compression
│   └── PCA_compression.py <- subpage with PCA compression
├── requirements.txt <- required packages
└── scripts
    ├── __init__.py <- makes scripts a module
    ├── cluster_compression.py <- ClusterCompressor class
    ├── pca_compression.py <- PCACompressor class
    └── utils.py <- uitilty functions for image to array and array to image conversion

Running the application

Clone this repository and navigate to the root directory of the project.

  • Python virtual environment

    1. Create a virtual environment (below named env) and activate it
    python3 -m venv env
    source env/Scripts/activate # bash
    env\Scripts\activate # on Windows
    1. Install required packages
    pip install -r requirements.txt
    1. Run the application
    streamlit run Main_page.py

Alternatilvely, if you have Make installed, you can use use command make streamlit.

  • Docker

    1. Build docker image (named my_app_image)
    docker build -t my_app_image .
    1. Run the container
    docker run -p 8501:8501 my_app_image

Alternatilvely, if you have Make installed, you can use use command make docker-all.

About

Web application enabling compression of images using unsupervised machine learning algorithm.

Topics

Resources

Stars

Watchers

Forks

Languages