Skip to content

almus-06/project-clearbg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClearBG - Professional Background Removal

ClearBG is a production-ready web application for high-quality background removal using the MODNet deep learning model. It is optimized for portrait matting, preserving fine details like hair even on complex backgrounds. It now includes advanced refinement tools like brush editing and a precise color removal tool.

Features

  • AI-Powered Matting: Uses MODNet for professional-grade transparency.
  • Advanced Refinement Tools: Use brush tools to manually restore or remove details, or the color removal tool to instantly drop out specific background colors.
  • Fast Performance: Optimized for CPU inference with intelligent image scaling.
  • Premium UI: Modern glassmorphism design with instantaneous previews built with React and Vite.
  • Asynchronous Backend: Built with FastAPI for efficient request handling.

Project Structure

clearbg/
├── frontend/                # React & Vite frontend
│   ├── src/                 # React components and hooks
│   ├── package.json
│   └── vite.config.js       # Vite configuration with proxy to backend
├── pretrained/              # Model weights (auto-downloaded)
├── scripts/
│   └── download_weights.py  # Weight downloader utility
├── src/
│   ├── models/
│   │   └── modnet.py        # MODNet architecture
│   ├── inference.py         # AI processing & color removal logic
│   └── main.py              # FastAPI application
├── requirements.txt         # Python dependencies
└── README.md

Setup Instructions

1. Prerequisites

  • Python 3.9+
  • Node.js & npm

2. Install Dependencies

Install both Python and Node.js dependencies using the main installation script:

npm run install-all

(Alternatively, you can manually run pip install -r requirements.txt at the root and npm install inside the frontend/ directory).

3. Download Model Weights

Run the following script to fetch the pretrained MODNet weights (approx. 50MB):

python scripts/download_weights.py

4. Run the Application

You will need two terminals running simultaneously for full-stack functionality:

Terminal 1 (Backend - FastAPI):

python src/main.py

Terminal 2 (Frontend - React/Vite):

npm run dev

5. Access the Web App

Open your browser and navigate to the frontend dev server URL (typically http://localhost:5173).


Technical Details

  • Model: MODNet (MobileNetV2 backbone).
  • Inference: PyTorch (CPU mode by default).
  • Optimization: Input images are intelligently resized to a 512px height/width (maintaining aspect ratio) for inference, and the resulting alpha mask is upscaled back to original dimensions for the final output. This ensures fast processing while maintaining output quality.
  • Color Removal: Leverages HSV masking and color space transformations to target specific hues cleanly with adjustable tolerance.

About

ClearBG is a full-stack, AI-driven web application that provides studio-quality background removal by combining a lightning-fast React and Vite frontend with a powerful Python FastAPI backend.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors