CoolFace
Apppublic

Jsahoo20/portrait-enhance-cv

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

Studio Portrait AI – Computer Vision Project

This project converts raw human portrait images captured in uncontrolled environments (mobile camera, uneven lighting, cluttered background) into studio-quality portraits using computer vision and lightweight AI techniques.

The focus is on natural enhancement, identity preservation, and fast inference.


Problem Statement

Raw portrait images often suffer from:

  • Cluttered or distracting backgrounds
  • Uneven lighting
  • Low contrast
  • Lack of subject separation

The goal is to simulate a professional studio portrait look while maintaining a natural appearance and avoiding aggressive beauty filters.


Approach Overview

The system follows a structured enhancement pipeline:

  1. 1.Foreground Matting (U²-Net via rembg) A lightweight neural matting model (U²-Net) is used to extract a soft alpha matte of the person. Unlike hard segmentation, matting preserves fine details such as hair and facial boundaries.
  1. 1.Background Inpainting The subject region is removed from the background and filled using image inpainting. This prevents halo artifacts when background blur is applied.
  1. 1.Background Blur (Bokeh Effect) A lens-style Gaussian blur is applied only to the reconstructed background, simulating DSLR depth of field.
  1. 1.Subject Enhancement Conservative unsharp masking is applied to improve facial clarity while preserving natural skin texture.
  1. 1.Studio Tone Adjustment An S-curve contrast adjustment is applied to improve overall tonal balance, similar to studio color grading.
  1. 1.Alpha Compositing The enhanced subject and blurred background are blended using the alpha matte for smooth transitions.

Why U²-Net?

U²-Net is used only for matting, not for face generation or beautification.

  • Produces soft alpha mattes instead of binary masks
  • Preserves hair and edge details
  • Lightweight and fast on CPU
  • Does not alter facial identity

This makes it suitable for realistic portrait enhancement.


Key Features

  • Natural-looking studio portraits
  • Hair-accurate subject separation
  • Identity-preserving enhancement
  • Fast CPU-based inference
  • Simple and interactive Streamlit UI

Demo Interface

The application is built using Streamlit and allows:

  • Image upload
  • One-click portrait enhancement
  • Side-by-side before/after comparison
  • Download of final result

Tech Stack

  • Python
  • OpenCV
  • NumPy
  • rembg (U²-Net matting)
  • Streamlit

How to Run Locally

bash
git clone https://github.com/Jsahoo20/portrait-enhance-cv.git
cd portrait-enhance-cv

pip install -r requirements.txt
streamlit run app.py