File size: 7,152 Bytes
719e71f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# 🎨 Colorspace Explorer - Project Summary

## Overview
A comprehensive interactive Streamlit application for exploring colorspaces, built for educational purposes in graduate-level image analysis courses.

## Project Structure

```
colorspaces/
β”œβ”€β”€ app.py                  # Main Streamlit application (950+ lines)
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ Makefile               # Build and deployment automation
β”œβ”€β”€ deploy.sh              # HuggingFace Spaces deployment script
β”œβ”€β”€ check_status.sh        # Deployment status checker
β”œβ”€β”€ .python-version        # Python version specification
β”œβ”€β”€ packages.txt           # System-level dependencies
β”œβ”€β”€ README.md              # Comprehensive documentation
β”œβ”€β”€ README_HF.md           # HuggingFace Spaces metadata
β”œβ”€β”€ QUICKSTART.md          # Quick start guide
β”œβ”€β”€ LICENSE                # MIT License
└── images/                # Sample images and test patterns
    β”œβ”€β”€ 1-light.png       # Colorblind test plates
    β”œβ”€β”€ 3-dark.png
    β”œβ”€β”€ cameraman.png     # Standard test images
    β”œβ”€β”€ lena.png
    β”œβ”€β”€ shapes.jpg
    └── ...
```

## Features Implemented

### βœ… Colorspaces Covered

1. **RGB (Red, Green, Blue)**
   - Interactive color mixer with sliders
   - Channel separation and visualization
   - Grayscale intensity views
   - Additive color model demonstration

2. **HSV/HSI (Hue, Saturation, Value/Intensity)**
   - Cylindrical color picker
   - Hue circle visualization
   - Real-time image manipulation (hue shift, saturation, value)
   - Channel separation

3. **CIE-LAB (Perceptual Colorspace)**
   - L*a*b* controls
   - Perceptually uniform color differences (Ξ”E)
   - Opponent color channels
   - Device-independent representation

4. **CMYK (Cyan, Magenta, Yellow, Key/Black)**
   - Subtractive color model mixer
   - RGB to CMYK conversion
   - Print separation plates visualization
   - Comparison with additive model

5. **YCbCr (Compression-oriented)**
   - Luminance-chrominance separation
   - Chroma subsampling demonstration (4:4:4, 4:2:2, 4:2:0)
   - Interactive compression ratio visualization
   - JPEG/video compression explanation

6. **Gamma Correction**
   - Interactive gamma slider (0.1 - 3.0)
   - Visual gamma curve plotting
   - Before/after comparison
   - Histogram analysis

7. **White Balance**
   - Temperature presets (Daylight, Incandescent, Fluorescent, Shade)
   - Manual RGB channel adjustment
   - Gray World automatic white balance
   - RGB histogram visualization

8. **Color Blindness Simulation**
   - Protanopia (no red cones)
   - Deuteranopia (no green cones)
   - Tritanopia (no blue cones)
   - Monochromacy (grayscale)
   - Difference heatmaps
   - Accessibility guidelines
   - Support for Ishihara test plates

### πŸŽ“ Educational Features

- **Interactive Controls**: Sliders, radio buttons, and file uploaders
- **Visual Comparisons**: Side-by-side before/after displays
- **Real-time Updates**: Instant feedback on parameter changes
- **Educational Content**: Explanations, formulas, and key insights
- **Practical Applications**: Real-world use cases for each colorspace
- **Sample Images**: Diverse test images including colorblind tests

### πŸ› οΈ Technical Features

- **Efficient Image Processing**: Using OpenCV and NumPy
- **Matplotlib Integration**: For curves and histograms
- **Responsive Layout**: Wide layout with columns for optimal viewing
- **Image Upload Support**: Users can test with their own images
- **Automatic Resizing**: Handles large images gracefully
- **Caching**: @st.cache_resource for performance

## Dependencies

- **streamlit** (1.39.0): Web application framework
- **numpy** (1.26.4): Numerical computations
- **opencv-python** (4.10.0.84): Image processing
- **pillow** (10.4.0): Image I/O
- **matplotlib** (3.9.2): Plotting and visualization

## Usage

### Local Development

```bash
# Quick start
make setup    # Install everything
make run      # Start the app

# Other commands
make test     # Run basic tests
make clean    # Clean up environment
```

### Deployment

```bash
# Deploy to HuggingFace Spaces
make deploy

# Check deployment status
make status
```

## Key Algorithms Implemented

1. **RGB ↔ HSV Conversion**: Using colorsys and OpenCV
2. **RGB ↔ LAB Conversion**: Using OpenCV color space conversion
3. **RGB β†’ CMYK Conversion**: K = 1 - max(R,G,B), CMY = (1 - RGB - K)/(1 - K)
4. **RGB ↔ YCbCr Conversion**: Using OpenCV
5. **Chroma Subsampling**: 2x downsampling with nearest-neighbor upsampling
6. **Gamma Correction**: Output = Input^Ξ³
7. **White Balance**: Per-channel scaling with Gray World algorithm
8. **Color Blindness Simulation**: Using transformation matrices from Brettel et al.

## Educational Alignment

This tool complements theoretical lectures on:
- Color representation in digital images
- Perceptual color spaces
- Color transformations
- Image compression techniques
- Display calibration and correction
- Accessibility and inclusive design

## Testing Recommendations

1. **RGB Tab**: Use images with distinct colors (shapes.jpg, circles.jpg)
2. **HSV Tab**: Try hue shifting on colorful images
3. **LAB Tab**: Test perceptual uniformity on gradients
4. **CMYK Tab**: Use photos to see print separations
5. **YCbCr Tab**: Compare subsampling on detailed images
6. **Gamma Tab**: Use cameraman.png or lena.png
7. **White Balance Tab**: Test on images with color casts
8. **Color Blindness Tab**: Use numbered test plates (1-light.png, etc.)

## Future Enhancements (Optional)

- [ ] Add more colorspaces (XYZ, LUV, LCH)
- [ ] Include color palette generation
- [ ] Add color harmony tools (complementary, triadic, etc.)
- [ ] Implement histogram equalization
- [ ] Add color quantization (K-means)
- [ ] Include color transfer between images
- [ ] Add batch processing capabilities
- [ ] Export processed images
- [ ] Save/load parameter presets

## Performance Considerations

- Images automatically resized to max 400-600px for interactive tabs
- Caching used for image loading
- Efficient NumPy operations for color transformations
- Matplotlib figures properly closed to prevent memory leaks

## Deployment Checklist

- [x] Main application (app.py)
- [x] Requirements file
- [x] Makefile with all commands
- [x] Deployment scripts (deploy.sh, check_status.sh)
- [x] Documentation (README.md, QUICKSTART.md)
- [x] HuggingFace metadata (README_HF.md)
- [x] System dependencies (packages.txt)
- [x] Python version specification (.python-version)
- [x] .gitignore file
- [x] Sample images in images/ folder

## Credits

- Based on the sampling-quantization demo structure
- Color blindness simulation algorithms from Brettel, ViΓ©not, and Mollon
- Educational content aligned with University of Bern image analysis curriculum

## License

MIT License - Free for educational and research use

---

**Status**: βœ… Complete and ready for deployment
**Total Lines of Code**: ~950+ lines in app.py
**Total Files**: 13 configuration/documentation files + sample images
**Estimated Build Time**: 2-3 minutes on HuggingFace Spaces