Repository for extraction of reflectance curves of electrochromic materials reducing the effect of gamma correction using computer vision techniques and LEGO color calibration patches.
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
# 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# 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/activatemake 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 environmentselectrochromic_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
- Place your video files in the
dataset/directory - 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_appThe 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
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]Execute the experiment analysis:
# Using uv environment
make run_experiment_uv
# Or using standard environment
make run_experimentThe analysis pipeline will:
- π¨ Extract color patches from the first frame
- β‘ Optimize gamma correction (if enabled)
- π Generate ROI mask automatically or load existing
- π Analyze temporal changes throughout the video
- π Generate reflectance curves and statistics
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
reflectance_curves.png: Main visualization showing temporal evolutionstatistics.txt: Numerical summary of the analysisconfig.json: Complete experiment configuration for reproducibilitygamma_linearization.jpg: Gamma correction validation plotsMask.png: ROI mask used for analysis
# Code formatting
make format
# Code linting
make lint
# Clean all environments
make clean
# Show help
make helpThe 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.
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.yamlautomatically - π Reset functionality: Start over easily if needed
- Automatically finds optimal gamma value for color linearization
- Generates RΒ² optimization curves
- Validates correction effectiveness
- Intelligent region of interest detection
- Fallback to manual mask loading
- Temporal stability validation
- Various video formats (.mp4, .avi, .mov)
- Different color spaces (Y, gray, L*)
- Flexible resolution handling
- Video not found: Ensure video files are in
dataset/directory - Permission errors: Check file permissions and virtual environment activation
- Memory issues: Use smaller video files or reduce resolution
- LEGO patch detection fails: Ensure good lighting and clear patch visibility
# Check environment
make help
# Verify installation
python -c "import dash; print('Dash installed successfully')"
# Check video files
ls dataset/- Pablo GalΓ‘n - Tecnalia Research & Innovation
- Artzai PicΓ³n - Tecnalia Research & Innovation
- Jon Velasco - BCMaterials
This project is licensed under the MIT License - see the LICENSE file for details.
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}
}| Task | Command |
|---|---|
| Setup | make init |
| Configure | make run_config_app_uv |
| Analyze | make run_experiment_uv |
| Help | make help |
| Clean | make clean |
Happy analyzing! π¬β¨