Enterprise-grade Image Restoration & Enhancement API
Restore, denoise, and enhance images with production-ready Flask API and modern web interface.
Quick Start β’ Installation β’ API Docs β’ Examples β’ Deployment β’ Contributing
- Overview
- Features
- Quick Start
- Installation
- API Documentation
- Usage Examples
- Deployment
- Architecture
- Performance
- Development
- Contributing
- License
- Support
NAFNet Image Restoration API is a professional-grade, production-ready REST API for image restoration and enhancement. Built with Flask and optimized for high performance, it combines advanced image processing techniques with a modern, intuitive web interface.
- Photo Restoration: Restore old or degraded photographs
- Noise Reduction: Remove noise from low-light or high-ISO images
- Quality Enhancement: Improve overall image clarity and sharpness
- Batch Processing: Process multiple images efficiently
- Integration: Embed in larger applications via REST API
- Enterprise Deployment: Run on Docker with health checks and monitoring
- Drag-and-drop upload with validation
- Real-time preview showing before/after comparison
- Automatic download of processed images
- Responsive design for desktop, tablet, and mobile
- Modern UI with smooth animations and feedback
- Single endpoint for restoration:
POST /api/fix - Info endpoint for API details:
GET /api/info - JSON error responses with descriptive messages
- Content negotiation and proper HTTP status codes
- File size limits (50MB) for security
- Denoise - Median filtering to remove noise while preserving edges
- Smooth - Gaussian blur for artifact reduction
- Enhance Contrast - 1.3x multiplier for visual impact
- Sharpen - 1.2x multiplier for edge definition
- Saturate Colors - 1.1x multiplier for color vibrancy
- Error handling with validation on all inputs
- Security - File size limits, input validation, safe file operations
- Performance - Optimized image processing, efficient memory usage
- Monitoring - Docker health checks, structured logging
- Documentation - Comprehensive API docs and examples
- Docker multi-stage build with optimization
- CI/CD GitHub Actions workflows for automated testing and linting
- Versioning semantic versioning (SemVer)
- Packaging proper Python package metadata (pyproject.toml)
- Code Quality PEP 8 compliance tools configured
- Python 3.8 or higher
- pip package manager
# 1. Clone repository
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
# 2. Install dependencies
pip install -r requirements.txt
# 3. Run application
python app.py
# 4. Open browser
# Navigate to http://localhost:5000# Build image
docker build -t nafnet-api:latest .
# Run container
docker run -p 5000:5000 nafnet-api:latest
# Access at http://localhost:5000| Component | Minimum | Recommended |
|---|---|---|
| Python | 3.8 | 3.11 |
| RAM | 512MB | 2GB |
| Disk | 500MB | 2GB |
| CPU | 1 Core | 2+ Cores |
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API# Linux/macOS
python -m venv venv
source venv/bin/activate
# Windows
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtDependency Details:
Flask 3.1.2- Web frameworkPillow 12.0.0- Image processingNumPy 2.3.5- Numerical computationsSciPy 1.16.3- Scientific computingWerkzeug 3.1.4- WSGI utilities
python app.pyExpected Output:
==================================================
π NAFNet Image Restoration API
==================================================
π Running on http://0.0.0.0:5000
π Open in browser: http://localhost:5000
==================================================
# In another terminal
curl http://localhost:5000/api/infoExpected Response:
{
"name": "NAFNet Image Restoration API",
"version": "1.0",
"endpoints": {
"GET /": "Web interface",
"GET /api/info": "Get API info",
"POST /api/fix": "Upload image for restoration"
}
}http://localhost:5000
Currently no authentication required. For production, implement OAuth 2.0 or API keys.
Restore and enhance a single image.
Request:
curl -X POST \
-F "file=@image.jpg" \
http://localhost:5000/api/fix \
-o restored.pngParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
file |
File | Yes | Image file (JPG, PNG, WebP, GIF) |
Response:
- Status:
200 OK - Content-Type:
image/png - Body: PNG image file (binary)
Error Responses:
| Code | Message | Reason |
|---|---|---|
400 |
"Upload an image as 'file'" | Missing file parameter |
400 |
"No file selected" | Empty filename |
500 |
"Error message" | Processing error |
Retrieve API information and available endpoints.
Request:
curl http://localhost:5000/api/infoResponse: 200 OK
{
"name": "NAFNet Image Restoration API",
"version": "1.0",
"endpoints": {
"GET /": "Web interface",
"GET /api/info": "Get API info",
"POST /api/fix": "Upload image for restoration"
}
}Access web interface for interactive image restoration.
Response: 200 OK - HTML page with drag-and-drop upload
# Basic restoration
curl -X POST \
-F "file=@photo.jpg" \
http://localhost:5000/api/fix \
-o restored.png
# With verbose output
curl -v -X POST \
-F "file=@photo.jpg" \
http://localhost:5000/api/fix \
-o restored.pngimport requests
# Single image
with open('image.jpg', 'rb') as f:
response = requests.post(
'http://localhost:5000/api/fix',
files={'file': f}
)
if response.status_code == 200:
with open('restored.png', 'wb') as out:
out.write(response.content)
print('β Image restored successfully')
else:
print(f'β Error: {response.status_code}')const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const formData = new FormData();
formData.append('file', file);
fetch('/api/fix', {
method: 'POST',
body: formData
})
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'restored.png';
a.click();
})
.catch(error => console.error('Error:', error));from api_examples import NAFNetClient
client = NAFNetClient()
# Get API info
info = client.get_info()
# Restore single image
client.restore_image('input.jpg', 'output.png')
# Batch process
client.batch_restore('./images', './restored')python app.pypip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 app:app# Build image
docker build -t nafnet-api:latest .
# Run with resource limits
docker run \
-p 5000:5000 \
--memory=1g \
--cpus=1 \
nafnet-api:latest
# With health checks
docker run \
-p 5000:5000 \
--health-cmd='curl localhost:5000/api/info' \
--health-interval=30s \
nafnet-api:latestversion: '3.8'
services:
api:
build: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=production
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/api/info"]
interval: 30s
timeout: 10s
retries: 3sudo apt-get update
sudo apt-get install python3-pip python3-venv
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
gunicorn -w 4 -b 0.0.0.0:5000 app:app# Create Procfile
echo "web: gunicorn app:app" > Procfile
# Deploy
git push heroku mainSimply run the project - Replit handles deployment automatically.
βββββββββββββββββββββββββββββββββββββββββββ
β Web Interface (HTML/JS) β
βββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββ
β Flask Application (app.py) β
β β’ Request validation β
β β’ Route handling β
β β’ Error handling β
βββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββ
β Image Processing Pipeline β
β β’ Image loading (PIL) β
β β’ Denoising (SciPy) β
β β’ Enhancement (PIL) β
β β’ Saving (PIL) β
βββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββ
β Output (PNG Image) β
βββββββββββββββββββββββββββββββββββββββββββ
- Load - Read image with PIL, convert to RGB
- Denoise - Apply median filter via SciPy
- Smooth - Apply Gaussian blur
- Enhance - Adjust contrast (1.3x), sharpness (1.2x), saturation (1.1x)
- Save - Output as PNG (lossless)
| Metric | Value |
|---|---|
| Avg Processing Time | 1-2 seconds |
| Memory Usage | ~200MB |
| CPU Usage | 50-70% |
| Max Concurrency | 4 workers |
| Throughput | ~30 images/min (single worker) |
| Format | Max Size |
|---|---|
| Input | 50MB |
| Output | 30MB (PNG) |
| Format | Input | Output |
|---|---|---|
| JPEG | β | β |
| PNG | β | β |
| WebP | β | β |
| GIF | β | β |
See DEVELOPMENT.md for comprehensive development guide including:
- Code style (PEP 8)
- Testing strategies
- Profiling and benchmarking
- Debugging techniques
- Release process
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python app.pyWe welcome contributions! See CONTRIBUTING.md for guidelines.
- Fork repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push branch:
git push origin feature/amazing-feature - Open Pull Request
- Follow PEP 8
- Add docstrings to functions
- Write tests for new features
- Update documentation
This project is licensed under the MIT License - see LICENSE file for details.
MIT License allows:
- β Commercial use
- β Modification
- β Distribution
- β Private use
With conditions:
β οΈ Include license and copyrightβ οΈ State changes
- Documentation: Check README.md, INSTALLATION.md, DEVELOPMENT.md
- Examples: See api_examples.py for usage patterns
- Issues: GitHub Issues
- Email: ffjisan804@gmail.com
- Port already in use: Change port in app.py or use
lsof -i :5000 - Module not found: Run
pip install -r requirements.txt - Image processing error: Ensure file is valid image format
Report security vulnerabilities to ffjisan804@gmail.com instead of GitHub Issues.
NAFNet Image Restoration API by Gtajisan
- Email: ffjisan804@gmail.com
- GitHub: @Gtajisan
β If you find this useful, please give it a star on GitHub! β