AI ADAPTIVE IMAGE COMPRESSION
Content-aware compression: a neural network decides which parts of an image matter, so text stays sharp while everything else is compressed hard.
OVERVIEW
Standard compression treats every pixel the same, so a screenshot or a scanned document loses legibility in exactly the places people need to read. This project splits an image into tiles, predicts how important each tile is, and spends quality only where it matters.
THE PIPELINE
THE MODEL
HOW THE TRAINING DATA WAS LABELED
Labeling a whole image dataset by hand was not realistic, so labels are produced automatically. A preprocessing script runs OCR on each image and measures the share of its area covered by text: 1% or more is labeled “important”, anything less “not important”. The CNN then learns to generalize that signal from the pixels plus the mask.
INTERACTIVE APP
- Tunable in real time: sliders for the importance threshold (default 0.6), the scale for important and unimportant tiles, and the final JPEG quality (default 85).
- Side-by-side comparison of the original and compressed image, with both file sizes and the percentage saved.
- Heatmap overlay showing which tiles the model considered important.
- One-click download of the compressed result.
File size drops by up to 60–80%, measured against the same image saved as a quality-100 JPEG, while text stays readable.
LIMITATIONS
- “Important” currently means “contains text”, because that is what the labels encode. Faces and other objects are the next target.
- Importance is binary per tile, not a continuous quality level.
- OCR quality limits the labels: blurry or stylized text can be missed.
RUN IT
git clone https://github.com/AAFLY99/ai-adaptive-image-compression.git cd ai-adaptive-image-compression pip install -r requirements.txt # also install Tesseract OCR on your system python classify.py # label the dataset with OCR python train.py # train the tile classifier streamlit run app.py
The dataset and trained models are excluded from the repository because of their size.