sila0/image-enhancement
๐ผ๏ธ Image Enhancement API
A FastAPI-powered image enhancement application that processes images in LAB color space using classical computer vision techniques โ no deep learning required.
โ ๏ธ Warning: This app is designed for desktop / computer use only. The UI is not optimized for mobile devices โ please open it on a computer for the best experience.
Live demo: https://sila0-image-enhancement.hf.space
Overview
This application exposes a REST API and a browser-based UI for enhancing low-quality images. It applies advanced image processing algorithms in the LAB color space, operating only on the L (luminance) channel to preserve natural colors while improving brightness, contrast, and sharpness.
Three enhancement modes are available, ranging from quick contrast correction to a full 6-stage professional pipeline.
Enhancement Modes
clahe โ Contrast Limited Adaptive Histogram Equalization
Divides the image into small tiles and equalizes the histogram of each tile independently. The clipLimit parameter prevents over-amplification of noise. Ideal for images with uneven lighting.
bilateral โ Bilateral Filtering
A non-linear smoothing filter that preserves edges while reducing noise. Unlike Gaussian blur, it considers both spatial proximity and pixel intensity similarity โ producing a "clean" look without losing structure.
combined โ Face-Focused Enhancement Pipeline
Designed for blurry / low-light face crops. Four stages:
The FSRCNN weights are downloaded on first use to models/FSRCNN_x2.pb.
API Endpoints
POST /enhance
Upload an image and download the enhanced version.
Parameters:
fileโ JPG or PNG imagemodeโclahe|bilateral|combined(default:clahe)
Response: Enhanced image as JPEG download.
POST /enhance/metrics
Upload an image and receive the enhanced image + quality metrics in JSON.
Response:
{
"mode": "clahe",
"original_size": { "width": 1920, "height": 1080 },
"metrics": {
"ssim": 0.874,
"psnr": 32.5
},
"enhanced_image": "<base64 encoded JPEG>"
}Metrics explained:
- SSIM (Structural Similarity Index) โ measures perceptual similarity between original and enhanced image. Range: 0โ1, higher = more similar structure preserved.
- PSNR (Peak Signal-to-Noise Ratio) โ measures reconstruction quality in dB. Higher values indicate less distortion introduced by enhancement.
POST /chat
Chat with the Image Enhancement Assistant โ an AI guide that explains techniques (CLAHE, MSRCR, FFT, LAB color space), interprets metrics, and recommends the best mode for a given image.
Request body (JSON):
{
"messages": [
{ "role": "user", "content": "Why is my SSIM so low?" }
],
"context": "Mode used: combined | PSNR: 28.4 dB | SSIM: 0.71"
}messagesโ chat history, alternatinguser/assistantcontextโ optional session context (current mode, metrics) so the assistant can answer with concrete numbers
Response: plain-text streamed response (text/plain; charset=utf-8). The assistant runs on Anthropic's Claude API. Set ANTHROPIC_API_KEY either in a .env file (recommended โ see .env.example) or as a shell environment variable.
The browser UI exposes this as a floating speech-bubble button in the bottom-right corner โ click it to open the chat panel. After enhancing an image, the panel automatically receives session context (current mode + metrics) so the assistant can answer with concrete numbers.
LAB Color Space
All processing is performed in CIE LAB color space:
BGR โ LAB โ [ enhance L channel only ] โ BGR- L โ Lightness (0 = black, 255 = white) โ this is what we modify
- A โ Green โ Red color axis
- B โ Blue โ Yellow color axis
By isolating the L channel, enhancements affect only brightness and contrast โ color hues remain untouched, preventing the color distortion common in naive histogram equalization.
Project Structure
my ai proje/
โโโ main.py # FastAPI app โ routes and endpoint logic
โโโ lab_processing.py # All image processing algorithms
โโโ metrics.py # SSIM / PSNR computation
โโโ chat.py # Claude-powered Image Enhancement Assistant
โโโ requirements.txt # Python dependencies
โโโ start.bat # One-click launcher (Windows)
โโโ static/
โโโ index.html # Browser UI (incl. chat panel)
โโโ script.js # Frontend logic
โโโ style.css # StylingTech Stack
How to Run
# 1. Clone the repository
git clone https://github.com/slasert/image-enhancement.git
cd image-enhancement
# 2. Install dependencies
pip install -r requirements.txt
# 3. Set your Anthropic API key (required for /chat โ the AI assistant)
# Easiest: copy .env.example to .env and put your key in it.
cp .env.example .env
# Then edit .env and replace the placeholder. python-dotenv loads it
# automatically at server startup.
#
# Or export it as a shell env var instead:
# macOS / Linux: export ANTHROPIC_API_KEY=sk-ant-...
# Windows (cmd): set ANTHROPIC_API_KEY=sk-ant-...
# Windows (PS): $env:ANTHROPIC_API_KEY = "sk-ant-..."
# 4. Start the server
uvicorn main:app --reload
# 5. Open in browser
# โ http://localhost:8000
# โ http://localhost:8000/docs (interactive API docs)Or on Windows, simply double-click `start.bat`. (The /chat endpoint will return an error message until ANTHROPIC_API_KEY is set; the rest of the app works without it.)
Interactive API Docs
FastAPI automatically generates interactive documentation at:
- Swagger UI โ
http://localhost:8000/docs - ReDoc โ
http://localhost:8000/redoc
You can test all endpoints directly from the browser without any additional tools.
Built with OpenCV and FastAPI โ classical computer vision, no deep learning required.
