Skip to content

pctablet505/Shadow-Removal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Shadow Removal

A lightweight computer vision project for automatic shadow removal using iterative shading and reflectance decomposition.


Description

This project removes unwanted shadows from images by decomposing the scene into shading (illumination) and reflectance (intrinsic surface color) components. It uses adaptive thresholding with integral images to identify shadow regions and then iteratively refines the decomposition to recover the true appearance of the scene.

Built entirely with OpenCV and NumPy — no deep learning required.


Algorithm Overview

  1. Adaptive Thresholding with Integral Images

    • Computes a local threshold for each pixel using an integral image for efficiency.
    • Produces a binary mask distinguishing well-lit regions from shadowed regions.
  2. Iterative Shading & Reflectance Decomposition

    • Initializes reflectance R and shading S from the input image.
    • For each iteration:
      • Estimates shading by convolving the masked reflectance with a local averaging filter.
      • Updates reflectance as R = I / (S + ε).
      • Clips values to valid range and repeats.
    • After convergence, applies Otsu-based shadow masking and global intensity correction to produce the final shadow-free image.
  3. Post-Processing

    • Otsu thresholding on the final shading map to refine the shadow mask.
    • Global mean scaling per channel to restore natural brightness.

Requirements

  • Python 3.7+
  • OpenCV (opencv-python)
  • NumPy
  • Matplotlib
  • SciPy
  • Seaborn

Install with:

pip install opencv-python numpy matplotlib scipy seaborn

Usage

  1. Clone the repository

    git clone https://github.com/pctablet505/Shadow-Removal.git
    cd Shadow-Removal
  2. Run the script

    python "iterative shading reflectance.py"

    The script will:

    • Read images from the specified input directory
    • Remove shadows using the iterative algorithm
    • Save side-by-side before/after visualizations to the output directory
  3. Adjust parameters

    • n_iters: Number of shading-reflectance iterations (default: 10)
    • dx, dy: Local filter size for shading estimation (default: 5)

Results

The algorithm produces shadow-free images by separating illumination changes from the underlying scene content. Sample outputs show clean removal of hard shadows while preserving natural textures and colors.

Input Output
Original image with cast shadows Shadow-removed image with uniform illumination

Note: The script currently uses hardcoded input/output paths. Update the path and output folder variables inside the script to point to your own images.


References

  • Inspired by intrinsic image decomposition and classical retinex theory.
  • Integral-image adaptive thresholding for fast local binarization.

About

Automatic shadow removal using iterative shading and reflectance decomposition (computer vision)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages