Inpainting: Image Editor using Object Detection and Diffusion Models

Intelligent Image Editing with Automatic Object Detection and AI-Powered Inpainting

Mahanth Yalla and Md Kaif Alam

Indian Institute of Science, Bengaluru

Project Overview

Inpainting Example
This project provides a comprehensive web application for intelligent image inpainting, combining state-of-the-art object detection with diffusion-based generative models. Users can upload images, automatically detect objects within them, select specific regions for removal or modification, and seamlessly generate realistic inpainted results. The system offers both advanced AI-powered editing and classic image filtering capabilities, all through an intuitive web interface accessible on both desktop and mobile devices.

Key Features

Automatic Object Detection

Leverage COCO-trained models to automatically identify and segment objects within uploaded images, eliminating manual masking.

Diffusion-Based Inpainting

Utilize advanced diffusion models to generate photorealistic content that seamlessly fills selected regions while maintaining context.

Interactive Web Interface

Built with Streamlit for an intuitive, responsive interface that works seamlessly across desktop and mobile devices.

RESTful API Backend

FastAPI-powered backend providing robust, scalable image processing services with clear API endpoints.

How It Works

Architecture Overview

Frontend: Streamlit

Interactive web application providing user-friendly interface for image upload, object selection, and result visualization.

Backend: FastAPI

High-performance REST API handling image processing requests, model inference, and result generation.

Object Detection

COCO-trained detection models automatically identify and segment objects within images for precise masking.

Inpainting Engine

Diffusion-based generative models create realistic content to fill masked regions while preserving image coherence.

Processing Pipeline

  1. Image Upload: User uploads an image through the Streamlit web interface
  2. Object Detection: Backend automatically detects and segments all objects using COCO categories
  3. Object Selection: User selects which detected objects to remove or modify
  4. Mask Generation: System creates precise binary masks for selected regions
  5. Inpainting: Diffusion model generates realistic content to fill masked areas
  6. Result Display: Multiple generated results displayed for user selection and download

Demo Gallery Interactive

Desktop Interface

Desktop Interface Upload
Streamlit interface with uploaded image of kids playing football. User selects "SportsBall" object for removal.
Desktop Interface Results
Inpainting results showing seamless removal of the sports ball with realistic background fill.

Mobile Interface

Mobile Interface
Clean, responsive mobile interface optimized for touch interactions.
Mobile Object Selection
Uploaded image with automatic cat detection. User selects cat object for removal.
Mobile Results
Generated results showing successful cat removal with natural background inpainting.

Classic Filters

Filter Menu
Filter selection menu offering various traditional image processing options.
Blur Filter
Example of Gaussian blur filter applied to image for artistic or privacy effects.

Technology Stack

Core Technologies

Python 3.9+ PyTorch Streamlit FastAPI Uvicorn OpenCV Pillow

AI/ML Models

COCO Object Detection Diffusion Models Stable Diffusion Inpainting Transformers

Development Tools

Conda Jupyter Git REST API

Setup & Installation

Prerequisites

Installation Steps

1. Clone Repository

git clone https://github.com/Mahanth-Maha/Inpainting.git
cd Inpainting

2. Create Virtual Environment

conda create -n inpaint python=3.9 -y
conda activate inpaint

3. Install Jupyter Kernel (Optional)

conda install -c anaconda ipykernel -y
python -m ipykernel install --user --name inpaint --display-name "inpaint"

4. Install PyTorch

Visit pytorch.org for platform-specific instructions, or use:

# For CUDA 12.8
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

5. Install Dependencies

pip install -r requirements.txt

6. Configure Environment

cp env_template .env
# Edit .env file with your configurations

Default .env settings:

ANNOTE_MAPPING_FILE_PATH="models/annotations/coco_category_mapping.json"
DEBUG_LEVEL="INFO"

Running the Application

Start Backend Server

In Terminal 1 (keep running):

conda activate inpaint
cd src/backend
uvicorn main:app --reload

Start Frontend Web App

In Terminal 2 (keep running):

conda activate inpaint
cd src/frontend
streamlit run app.py

Note: The web app will automatically launch in your default browser at http://localhost:8501

Usage Guide

Basic Workflow

  1. Launch Application: Ensure both backend and frontend servers are running
  2. Upload Image: Click "Browse files" or drag-and-drop an image into the upload area
  3. Wait for Detection: System automatically detects all objects in the image
  4. Select Objects: Choose which detected objects you want to remove or modify
  5. Optional Text Prompt: Add custom text prompts to guide the inpainting generation
  6. Generate Results: Click "Inpaint" to generate multiple result variations
  7. Review & Download: Browse generated results and download your preferred output

API Endpoints

POST /detect

Detects objects in uploaded image, returns bounding boxes and categories

POST /inpaint

Performs inpainting on selected regions, returns generated images

POST /filter

Applies classic image filters (blur, sharpen, edge detection, etc.)

Feature Highlights

Multi-Object Selection

Select multiple objects simultaneously for batch removal or modification, saving time on complex edits.

Custom Prompts

Guide the inpainting process with text prompts to replace removed objects with specific content.

High-Resolution Support

Process high-resolution images while maintaining quality and detail in generated regions.

Filter Library

Access classic image processing filters for quick edits beyond AI-powered inpainting.

Resources & Links

GitHub Repository

Complete source code, documentation, and issue tracking

View Repository →

Demo

See the application in action with sample images and use cases

View Demo →

Documentation

Detailed usage instructions, API reference, and troubleshooting

Read Docs →

Future Enhancements

Contact & Support

Report Issues

Found a bug or have a feature request?

Open an Issue →

Discussions

Have questions or want to share ideas?

Raise PR →

Project Contributors

Get in Touch

For collaborations, research inquiries, or general questions

Mahanth Yalla

Email: mahanthyalla [at] iisc.ac.in

Website: mahanthyalla.in

M.Tech Artificial Intelligence,
Indian Institute of Science, Bengaluru

Md Kaif Alam

Email: kaifalam [at] iisc.ac.in

M.Tech Artificial Intelligence,
Indian Institute of Science, Bengaluru

See All Projects of Mine →