Imgenhance / README.md
Death fuck
Restore
ce83c64
metadata
title: AI Image Processing
emoji: 🖼️
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit

AI Image Processing API

A comprehensive image processing API with multiple AI-powered features including super-resolution, background removal, noise reduction, and document scanning.

Features

  • Image Enhancement: Upscale images 2x or 4x using Real-ESRGAN
  • Background Removal: Remove backgrounds using BiRefNet AI model via rembg
  • Noise Reduction: Reduce image noise using OpenCV Non-Local Means Denoising
  • Document Scanning: Auto-crop, align, and enhance document photos with AI
  • RESTful API: Full API with automatic OpenAPI/Swagger documentation
  • Web Interface: Simple drag-and-drop interface for testing

API Endpoints

Image Enhancement

POST /enhance

Upscale and enhance image quality using Real-ESRGAN.

Parameters:

  • file: Image file (PNG, JPG, JPEG, WebP, BMP)
  • scale: Upscale factor (2 or 4, default: 4)

Background Removal

POST /remove-background

Remove background from an image using BiRefNet AI model.

Parameters:

  • file: Image file
  • bgcolor: Background color - 'transparent', 'white', 'black', or hex color like '#FF0000'

Noise Reduction

POST /denoise

Reduce image noise using Non-Local Means Denoising.

Parameters:

  • file: Image file
  • strength: Denoising strength (1-30, default: 10)

Document Scanning

POST /docscan

Scan and enhance document images with AI-powered processing.

Features:

  • Auto-detection of document edges
  • Auto-crop and perspective correction
  • Alignment and straightening
  • CLAHE contrast enhancement
  • Bilateral noise reduction (preserves edges)
  • Unsharp mask sharpening
  • Optional HD upscaling with Real-ESRGAN

Parameters:

  • file: Document image (PNG, JPG, JPEG, WebP, BMP)
  • enhance_hd: Enable AI HD enhancement (default: true)
  • scale: Upscale factor 1-4 (default: 2)

Other Endpoints

  • GET /docs - Interactive Swagger UI documentation
  • GET /redoc - ReDoc documentation
  • GET /model-info - Get information about loaded AI models
  • GET /health - Health check endpoint

Models Used

Feature Model Description
Super Resolution Real-ESRGAN x4plus State-of-the-art image upscaling
Background Removal BiRefNet-general High-accuracy segmentation via rembg
Noise Reduction OpenCV NLM Non-Local Means Denoising
Document Scanning OpenCV + Real-ESRGAN Edge detection, perspective correction, HD enhancement

Local Development

# Install dependencies
pip install -r requirements.txt

# Run the server
python app.py

The server will start at http://localhost:7860

Deployment to Hugging Face Spaces

  1. Create a new Space on Hugging Face
  2. Select "Docker" as the SDK
  3. Upload all files from this repository
  4. The Space will automatically build and start the container

API Usage Examples

Python - Image Enhancement

import requests

with open("image.jpg", "rb") as f:
    response = requests.post(
        "https://your-space.hf.space/enhance",
        files={"file": f},
        params={"scale": 4}
    )
    
with open("enhanced.png", "wb") as f:
    f.write(response.content)

Python - Background Removal

import requests

with open("photo.jpg", "rb") as f:
    response = requests.post(
        "https://your-space.hf.space/remove-background",
        files={"file": f},
        params={"bgcolor": "transparent"}
    )
    
with open("no_background.png", "wb") as f:
    f.write(response.content)

Python - Noise Reduction

import requests

with open("noisy.jpg", "rb") as f:
    response = requests.post(
        "https://your-space.hf.space/denoise",
        files={"file": f},
        params={"strength": 15}
    )
    
with open("denoised.png", "wb") as f:
    f.write(response.content)

Python - Document Scanning

import requests

with open("document_photo.jpg", "rb") as f:
    response = requests.post(
        "https://your-space.hf.space/docscan",
        files={"file": f},
        params={"enhance_hd": True, "scale": 2}
    )
    
with open("scanned_document.png", "wb") as f:
    f.write(response.content)

cURL Examples

# Enhance image
curl -X POST "https://your-space.hf.space/enhance?scale=4" \
  -F "file=@image.jpg" -o enhanced.png

# Remove background
curl -X POST "https://your-space.hf.space/remove-background?bgcolor=transparent" \
  -F "file=@photo.jpg" -o nobg.png

# Denoise image
curl -X POST "https://your-space.hf.space/denoise?strength=10" \
  -F "file=@noisy.jpg" -o denoised.png

# Scan document
curl -X POST "https://your-space.hf.space/docscan?enhance_hd=true&scale=2" \
  -F "file=@document.jpg" -o scanned.png

License

MIT License