CoolFace
Apppublic

Zoro828/imageRestoration

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

๐Ÿ–ผ๏ธ Image Restoration Studio

<div align="center">

![Flask](https://flask.palletsprojects.com/) ![OpenCV](https://opencv.org/) ![Python](https://python.org) ![License](LICENSE) ![Status]()

Professional-grade image restoration with multi-algorithm inpainting

โ€ข Report Bug โ€ข Request Feature

<img src="https://github.com/FarazKhanAI/ImageRestoration/blob/main/demo.gif?raw=true" width="600" alt="Image Restoration Demo">

</div>

๐ŸŽฏ What It Does

Restore damaged photos with AI-powered precision. Remove scratches, blemishes, and unwanted objects while preserving original details and colors.

โœจ Key Features

  • โ€”โœ… Multi-Algorithm Inpainting - Combines Telea, Navier-Stokes, and hybrid methods
  • โ€”โœ… Smart Mask Processing - Feathering and edge-aware mask creation
  • โ€”โœ… Color Preservation - Maintains original color consistency
  • โ€”โœ… Fast Processing - 2-10 seconds for most images
  • โ€”โœ… Batch Processing - Automatically saves masks and results

๐Ÿš€ Get Started in 2 Minutes

Prerequisites

  • โ€”Python 3.10 or higher
  • โ€”Git (optional)

Installation

bash
# 1. Clone the repository
git clone https://github.com/FarazKhanAI/ImageRestoration.git
cd ImageRestoration

# 2. Create virtual environment (optional but recommended)
python -m venv venv

# 3. Activate environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate

# 4. Install dependencies
pip install -r requirements.txt

# 5. Run the application
python app.py

Open your browser and visit: http://localhost:5000

๐Ÿ“– How to Use

Step 1: Upload Image

  • โ€”Drag & drop your image or click to browse
  • โ€”Supports JPG, PNG, BMP, TIFF (up to 16MB)

Step 2: Mark Damage Areas

  • โ€”Use the brush tool to mark scratches, stains, or objects
  • โ€”Adjust brush size with the slider
  • โ€”Use Undo/Clear if needed

Step 3: Adjust Parameters

  • โ€”Inpainting Method:
  • โ€”Fast (Telea) - Quick restoration
  • โ€”Quality (Navier-Stokes) - Better for textures
  • โ€”Hybrid - Best overall (recommended)
  • โ€”Brush Size: 5-100px
  • โ€”Inpainting Radius: 1-20px

Step 4: Process & Download

  • โ€”Click "Process & Restore Image"
  • โ€”View before/after comparison
  • โ€”Download restored image in high quality

๐Ÿ—๏ธ Technical Architecture

Backend Stack

ComponentTechnologyPurpose
Web FrameworkFlask 3.0REST API & routing
Image ProcessingOpenCV 4.8Core inpainting algorithms
PerformanceNumbaJIT compilation for speed
Math OperationsNumPyMatrix operations
Image I/OPillowImage format handling

Processing Pipeline

1. Image Upload โ†’ Validation โ†’ Resize
2. Mask Creation โ†’ Feathering โ†’ Dilation
3. Inpainting Selection โ†’ Algorithm execution
4. Color Correction โ†’ Post-processing
5. Result Generation โ†’ Metrics calculation

๐Ÿ“ Project Structure

image-restoration-app/
โ”œโ”€โ”€ app.py                    # Main Flask application
โ”œโ”€โ”€ config.py                # Configuration settings
โ”œโ”€โ”€ requirements.txt         # Python dependencies
โ”‚
โ”œโ”€โ”€ backend/                 # Core processing logic
โ”‚   โ”œโ”€โ”€ image_processor.py   # Main processing pipeline
โ”‚   โ”œโ”€โ”€ scratch_removal.py   # Advanced inpainting algorithms
โ”‚   โ”œโ”€โ”€ utils.py            # Helper functions (mask creation, I/O)
โ”‚   โ”œโ”€โ”€ enhancement.py      # Color adjustments (optional)
โ”‚   โ””โ”€โ”€ validators.py       # Input validation
โ”‚
โ”œโ”€โ”€ templates/               # Frontend HTML
โ”‚   โ”œโ”€โ”€ base.html           # Base layout
โ”‚   โ””โ”€โ”€ index.html          # Main interface
โ”‚
โ”œโ”€โ”€ static/                  # Web assets
โ”‚   โ”œโ”€โ”€ css/style.css       # Styling
โ”‚   โ””โ”€โ”€ js/main.js          # Interactive features
โ”‚
โ””โ”€โ”€ instance/               # User data (not in git)
    โ”œโ”€โ”€ uploads/raw/        # Original uploaded images
    โ”œโ”€โ”€ uploads/masks/      # Generated mask images
    โ””โ”€โ”€ processed/          # Restored output images

๐Ÿง  Advanced Inpainting Algorithms

Multi-Algorithm Strategy

The system intelligently selects the best algorithm based on damage size:

Damage SizeAlgorithm UsedProcessing TimeBest For
Small (<1%)Fast Telea<2 secondsScratches, spots
Medium (1-10%)Navier-Stokes2-5 secondsTextured areas
Large (>10%)Hybrid Approach5-15 secondsLarge object removal

Key Technical Improvements

  1. 1.Edge Preservation - Uses Canny edge detection to protect boundaries
  2. 2.Color Matching - Adjusts inpainted colors to match surroundings
  3. 3.Multi-Scale Processing - Handles different damage sizes optimally
  4. 4.Soft Mask Blending - Feathering prevents visible seams

โšก Performance & Optimization

Processing Times

Image ResolutionMask SizeProcessing Time
800ร—600Small1-3 seconds
1920ร—1080Medium3-7 seconds
4000ร—3000Large7-15 seconds

Memory Usage

  • โ€”Minimal footprint: ~100MB for typical images
  • โ€”Auto-resizing: Large images automatically scaled to 2000px max dimension
  • โ€”Efficient cleanup: Temporary files removed after processing

๐Ÿšข Deployment Options

Option 1: Local Development

bash
python app.py
# Runs on http://localhost:5000 with debug mode

Option 2: Production with Gunicorn

bash
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app

Option 3: Free Cloud Deployment

Render.com (Recommended)
  1. 1.Connect your GitHub repository
  2. 2.Set build command: pip install -r requirements.txt
  3. 3.Set start command: python app.py
  4. 4.Get free HTTPS and auto-deploy
PythonAnywhere
  1. 1.Upload files via web interface
  2. 2.Configure WSGI file
  3. 3.Free tier available (limited)

๐Ÿ”ง Configuration

Environment Variables

Create .env file for production:

env
SECRET_KEY=your-secret-key-here
MAX_CONTENT_LENGTH=16777216  # 16MB
DEBUG=False

Directory Setup

The application automatically creates:

instance/              # Created automatically
โ”œโ”€โ”€ uploads/raw/      # Original images
โ”œโ”€โ”€ uploads/masks/    # Mask images (saved here!)
โ””โ”€โ”€ processed/        # Final results

๐Ÿ› Troubleshooting

Common Issues & Solutions

IssueSolution
Mask not appearingCheck browser console for errors, ensure you're drawing on the canvas
Processing too slowReduce image size before uploading (max 2000px recommended)
Color mismatchTry the "Hybrid" inpainting method for better color preservation
Blank resultsCheck server logs for errors, verify image format is supported

Debug Mode

Enable debug logging by setting DEBUG = True in app.py:

python
# In app.py
DEBUG = True

๐Ÿค Contributing

We welcome contributions! Here's how to help:

  1. 1.Fork the repository
  2. 2.Create a feature branch (git checkout -b feature/improvement)
  3. 3.Commit your changes (git commit -m 'Add some improvement')
  4. 4.Push to the branch (git push origin feature/improvement)
  5. 5.Open a Pull Request

Development Setup

bash
# Clone and setup
git clone https://github.com/FarazKhanAI/ImageRestoration.git
cd ImageRestoration
pip install -r requirements.txt

# Run tests
python -m pytest tests/

# Format code
black .

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ง Support & Contact

๐Ÿ™ Acknowledgments

Special thanks to:

  • โ€”OpenCV Team - For the incredible computer vision library
  • โ€”Flask Community - For the lightweight web framework
  • โ€”All Contributors - Who help improve this project

<div align="center">

Ready to restore your images?

Get Started Now | View Demo

Made with โค๏ธ using Flask & OpenCV

</div>

๐Ÿ“š Next Steps

Planned Improvements

  • โ€”[ ] Batch Processing - Restore multiple images at once
  • โ€”[ ] AI Enhancement - Add deep learning models for better results
  • โ€”[ ] Mobile App - iOS/Android companion apps
  • โ€”[ ] Cloud Storage - Google Drive/Dropbox integration

Frontend Updates (Coming Soon)

  • โ€”Dark mode toggle
  • โ€”More brush styles and shapes
  • โ€”Real-time preview while drawing
  • โ€”Advanced comparison slider

Tip: For best results, use high-quality source images and mark damage areas precisely with appropriate brush size.