Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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:

  • Interactive LEGO patch selector for precise region selection
  • Gamma correction optimization for improved color accuracy
  • Automated video analysis with ROI mask generation
  • Reflectance curve extraction with temporal analysis

πŸ› οΈ Installation

Quick Start with uv (Recommended)

# 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

Step 2: Configure Experiments (Interactive Method - Recommended)

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:

  • πŸ“Ή Video Selection: Choose from available videos in dataset
  • 🧱 LEGO Patch Selection: Interactive selection of 4 color patches (black, dark grey, clear grey, white)
  • 🎯 ROI Definition: Draw region of interest for analysis
  • ⚑ Gamma Calibration: Enable/disable gamma correction
  • πŸ’Ύ Configuration Export: Automatic generation of params.yaml

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:

  • reflectance_curves.png: Main visualization showing temporal evolution
  • statistics.txt: Numerical summary of the analysis
  • config.json: Complete experiment configuration for reproducibility
  • gamma_linearization.jpg: Gamma correction validation plots
  • Mask.png: ROI mask used for analysis

πŸ”§ 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:

  • πŸ–±οΈ Click-and-drag selection: Draw rectangles around each LEGO patch
  • 🎯 ROI drawing tools: Rectangle and freehand selection for analysis region
  • πŸ“Š Real-time preview: See your selections as you make them
  • ⚑ Configuration validation: Automatic verification of patch order and completeness
  • πŸ’Ύ One-click export: Generate params.yaml automatically
  • πŸ”„ Reset functionality: Start over easily if needed

πŸš€ Advanced Features

Gamma Optimization

  • Automatically finds optimal gamma value for color linearization
  • Generates RΒ² optimization curves
  • Validates correction effectiveness

Automated ROI Detection

  • Intelligent region of interest detection
  • Fallback to manual mask loading
  • Temporal stability validation

Multi-format Support

  • Various video formats (.mp4, .avi, .mov)
  • Different color spaces (Y, gray, L*)
  • Flexible resolution handling

πŸ†˜ 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

  • Pablo GalΓ‘n - Tecnalia Research & Innovation
  • Artzai PicΓ³n - Tecnalia Research & Innovation
  • Jon Velasco - BCMaterials

πŸ“„ 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! 🎬✨

About

Image-based method for characterization of electrochromic materials analysing the effect of gamma correction

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages