electrochromic_characterization

Electrochromic Characterization using Video Analysis

Repository for extraction of reflectance curves of electrochromic materials reducing the effect of gamma correction using computer vision techniques and LEGO color calibration patches.

🎯 Overview

This project provides tools for analyzing electrochromic materials using video recordings and standardized LEGO color patches. The system includes:

πŸ› οΈ Installation

# Clone the repository
git clone git@github.com:pgalantec/electrochromic_characterization.git
cd electrochromic_characterization

# Setup environment (installs uv if needed)
make init

# Activate environment
source .venv/bin/activate

Alternative Installation (Standard Python)

# Clone the repository
git clone git@github.com:pgalantec/electrochromic_characterization.git
cd electrochromic_characterization

# Create virtual environment
make create_env

# Activate environment
source env/bin/activate

Available Commands

make help           # Show all available commands
make init           # Setup environment with uv (fast)
make create_env     # Setup environment with standard venv
make clean          # Remove all virtual environments

πŸ“ Project Structure

electrochromic_characterization/
β”œβ”€β”€ assets/                     # Logo images
β”œβ”€β”€ dataset/                    # Video files (.mp4, .avi)
β”œβ”€β”€ output/                     # Experiment results
β”œβ”€β”€ src/                        # Source code
β”‚   β”œβ”€β”€ lego_app_v4.py         # Interactive configuration app
β”‚   β”œβ”€β”€ experiment.py          # Analysis pipeline
β”‚   β”œβ”€β”€ opt_gamma.py           # Gamma optimization
β”‚   └── utils/                 # Utility functions
β”œβ”€β”€ params.yaml                # Experiment configuration
β”œβ”€β”€ Makefile                   # Development commands
└── README.md

πŸš€ Usage

Step 1: Prepare Your Data

  1. Place your video files in the dataset/ directory
  2. Supported formats: .mp4, .avi, .mov

Launch the interactive LEGO patch selector:

# Using uv environment
make run_config_app_uv

# Or using standard environment
make run_config_app

The application will open in your browser at http://localhost:8050 and provides:

Step 3: Configure Experiments (Manual Method)

Alternatively, you can manually edit params.yaml:

videos:
  - video_path: "dataset/your_video.mp4"
    exp_name: "your_experiment_name"
    calibration: false                    # Enable gamma correction
    frame_dtype: Y                       # Color space: Y/gray/L
    patches: [                           # LEGO patch coordinates [x1,y1], [x2,y2]
        [[20, 1200], [100, 1380]],      # Black patch
        [[20, 950], [100, 1150]],       # Dark grey patch  
        [[20, 660], [100, 880]],        # Clear grey patch
        [[20, 400], [100, 600]]         # White patch
    ]

lego_srgb:                              # Nominal LEGO sRGB values
  black: [18, 18, 21]
  dark_grey: [98, 101, 102]  
  clear_grey: [160, 163, 164]
  white: [244, 238, 228]

Step 4: Run Analysis

Execute the experiment analysis:

# Using uv environment
make run_experiment_uv

# Or using standard environment  
make run_experiment

The analysis pipeline will:

  1. 🎨 Extract color patches from the first frame
  2. ⚑ Optimize gamma correction (if enabled)
  3. 🎭 Generate ROI mask automatically or load existing
  4. πŸ“Š Analyze temporal changes throughout the video
  5. πŸ“ˆ Generate reflectance curves and statistics

πŸ“Š Output Results

Results are stored in output/{video_name}/{experiment_name}/:

output/ExpCalY-OptGamma/
β”œβ”€β”€ config.json                 # Experiment configuration
β”œβ”€β”€ patches.png                 # Visualization of selected patches
β”œβ”€β”€ Mask.png                   # ROI binary mask
β”œβ”€β”€ gamma_linearization.jpg    # Gamma correction plot
β”œβ”€β”€ r2_optimization.jpg        # RΒ² optimization curve
β”œβ”€β”€ reflectance_curves.png     # Main results visualization
β”œβ”€β”€ statistics.txt             # Numerical analysis
└── temporal_analysis/         # Frame-by-frame data

Key Output Files:

πŸ”§ Development Tools

# Code formatting
make format

# Code linting  
make lint

# Clean all environments
make clean

# Show help
make help

πŸ“ LEGO Color Patches

The system uses 4 standardized LEGO color patches for calibration:

Patch Color Nominal sRGB Purpose
πŸ–€ Black [18, 18, 21] Dark reference
⚫ Dark Grey [98, 101, 102] Low-mid reference
βšͺ Clear Grey [160, 163, 164] Mid-high reference
⬜ White [244, 238, 228] Bright reference

Selection Order: Always select patches in this order for consistent results.

🎨 Interactive Configuration Features

The LEGO patch selector application provides:

πŸš€ Advanced Features

Gamma Optimization

Automated ROI Detection

Multi-format Support

πŸ†˜ Troubleshooting

Common Issues:

  1. Video not found: Ensure video files are in dataset/ directory
  2. Permission errors: Check file permissions and virtual environment activation
  3. Memory issues: Use smaller video files or reduce resolution
  4. LEGO patch detection fails: Ensure good lighting and clear patch visibility

Getting Help:

# Check environment
make help

# Verify installation
python -c "import dash; print('Dash installed successfully')"

# Check video files
ls dataset/

πŸ‘¨β€πŸ’» Contributors

πŸ“„ License

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

πŸ”— Citation

If you use this work in your research, please cite:

@software{electrochromic_characterization,
  title={Electrochromic Characterization using Video Analysis},
  author={GalΓ‘n, Pablo and PicΓ³n, Artzai and Velasco, Jon},
  year={2024},
  institution={Tecnalia Research \& Innovation, BCMaterials}
}

🎯 Quick Reference

Task Command
Setup make init
Configure make run_config_app_uv
Analyze make run_experiment_uv
Help make help
Clean make clean

Happy analyzing! 🎬✨