Teoman21 commited on
Commit
4d8cc10
·
1 Parent(s): 4376584

-update readme

Browse files
Files changed (1) hide show
  1. README.md +9 -227
README.md CHANGED
@@ -1,229 +1,11 @@
1
- # 🎨 Mosaic Generator
 
 
 
 
 
 
 
 
2
 
3
- A comprehensive mosaic generation system that transforms images into beautiful mosaic-style reconstructions using advanced image processing techniques.
4
 
5
- ## Features
6
-
7
- ### Core Functionality
8
- - **Image Preprocessing**: Automatic resizing and cropping to fit grid requirements
9
- - **Color Quantization**: Optional uniform and K-means quantization for simplified color variations
10
- - **Grid Analysis**: Efficient vectorized NumPy operations for analyzing image grid cells
11
- - **Tile Mapping**: Replace grid cells with matching image tiles from Hugging Face datasets
12
- - **Quality Metrics**: Comprehensive similarity analysis using MSE, PSNR, SSIM, and color metrics
13
-
14
- ### Performance Features
15
- - **Vectorized Operations**: NumPy-based efficient processing for optimal performance
16
- - **Implementation Comparison**: Side-by-side comparison of vectorized vs loop-based methods
17
- - **Grid Size Benchmarking**: Performance analysis across different grid resolutions
18
- - **Real-time Metrics**: Live processing time and quality measurements
19
-
20
- ### User Interface
21
- - **Interactive Gradio Interface**: Easy-to-use web interface with parameter controls
22
- - **Real-time Preview**: Instant visualization of mosaic generation results
23
- - **Performance Analysis**: Built-in benchmarking tools for optimization
24
- - **Comprehensive Settings**: Fine-grained control over all generation parameters
25
-
26
- ## Installation
27
-
28
- 1. Clone the repository:
29
- ```bash
30
- git clone <repository-url>
31
- cd Mosaic_Generator
32
- ```
33
-
34
- 2. Install dependencies:
35
- ```bash
36
- pip install -r requirements.txt
37
- ```
38
-
39
- 3. (Optional) Login to Hugging Face for dataset access:
40
- ```bash
41
- huggingface-cli login
42
- ```
43
-
44
- That's it! No setup script needed - just install the requirements and you're ready to go.
45
-
46
- ## Usage
47
-
48
- ### Running the Application
49
-
50
- Start the Gradio interface:
51
- ```bash
52
- python run_app.py
53
- ```
54
-
55
- The application will launch at `http://localhost:7860` with a comprehensive web interface.
56
-
57
- **Important**: Use `python run_app.py` instead of `python app.py` to prevent the dataset from being downloaded every time you upload an image. The `run_app.py` script disables auto-reload which causes the constant re-downloading.
58
-
59
- **Note**: The first time you generate a mosaic, the app will load tiles from Hugging Face (this takes a few moments). Subsequent generations will be much faster as tiles are cached. To pre-load tiles for faster startup, run:
60
- ```bash
61
- python preload_tiles.py
62
- ```
63
-
64
- ### Using the Interface
65
-
66
- 1. **Upload an Image**: Click on the image upload area and select your input image
67
- 2. **Configure Parameters**:
68
- - **Basic Settings**: Adjust grid size, tile size, and output resolution
69
- - **Advanced Settings**: Choose implementation method, color matching space, and quantization options
70
- 3. **Generate Mosaic**: Click "Generate Mosaic" to create your mosaic
71
- 4. **View Results**: See the generated mosaic alongside quality metrics and processing information
72
-
73
- ### Performance Analysis
74
-
75
- Use the "Performance Analysis" tab to:
76
- - Compare vectorized vs loop-based implementations
77
- - Benchmark different grid sizes
78
- - Analyze performance scaling characteristics
79
-
80
- ### Command Line Benchmarking
81
-
82
- Run comprehensive benchmarks:
83
- ```bash
84
- python benchmark.py --grid-sizes 16 32 48 64 --output-dir images
85
- ```
86
-
87
- ## Technical Architecture
88
-
89
- ### Core Components
90
-
91
- 1. **MosaicGenerator** (`src/mosaic.py`): Main mosaic generation engine
92
- 2. **TileManager** (`src/tiles.py`): Manages tile collection and matching
93
- 3. **Color Quantization** (`src/quantization.py`): Implements uniform and K-means quantization
94
- 4. **Similarity Metrics** (`src/metrics.py`): Comprehensive quality assessment
95
- 5. **Pipeline** (`src/pipeline.py`): Orchestrates the complete generation process
96
- 6. **Configuration** (`src/config.py`): Centralized parameter management
97
-
98
- ### Key Algorithms
99
-
100
- #### Grid Analysis
101
- - **Vectorized Operations**: Uses NumPy's `block_view` for efficient grid cell analysis
102
- - **Color Matching**: Supports both RGB (euclidean) and LAB (perceptual) color spaces
103
- - **Performance Optimization**: Vectorized operations provide significant speedup over loops
104
-
105
- #### Tile Matching
106
- - **Color Space Conversion**: Perceptual matching in LAB color space
107
- - **Distance Metrics**: Euclidean distance for optimal tile selection
108
- - **Brightness Normalization**: Optional tile brightness standardization
109
-
110
- #### Quality Assessment
111
- - **MSE/PSNR**: Standard pixel-wise similarity metrics
112
- - **SSIM**: Structural similarity for perceptual quality
113
- - **Color Analysis**: Histogram correlation and channel-specific metrics
114
-
115
- ## Configuration Options
116
-
117
- ### Grid Settings
118
- - **Grid Size**: 8×8 to 128×128 tiles (default: 32×32)
119
- - **Tile Size**: 16×16 to 64×64 pixels (default: 32×32)
120
- - **Output Resolution**: Customizable output dimensions
121
-
122
- ### Processing Options
123
- - **Implementation**: Vectorized (recommended) or loop-based
124
- - **Color Matching**: LAB (perceptual) or RGB (euclidean)
125
- - **Quantization**: Uniform or K-means color reduction
126
- - **Tile Processing**: Optional brightness normalization
127
-
128
- ### Dataset Configuration
129
- - **Tile Source**: Hugging Face "Kratos-AI/KAI_car-images" dataset
130
- - **Tile Limit**: Configurable number of tiles to load (default: 200 for better quality)
131
- - **Caching**: Tiles are cached after first load for faster subsequent use
132
- - **Streaming**: Uses streaming dataset loading to avoid downloading full dataset
133
- - **Fallback Tiles**: Extensive color palette (40+ colors) if dataset unavailable
134
-
135
- ## Performance Characteristics
136
-
137
- ### Scalability
138
- - **Linear Scaling**: Processing time scales linearly with number of tiles
139
- - **Memory Efficient**: Vectorized operations minimize memory overhead
140
- - **Optimized Algorithms**: NumPy-based implementations for maximum performance
141
-
142
- ### Benchmark Results
143
- Typical performance on modern hardware:
144
- - **32×32 grid**: ~1-3 seconds processing time (optimized)
145
- - **64×64 grid**: ~3-8 seconds processing time (optimized)
146
- - **Vectorized vs Loops**: 3-10x speedup factor
147
- - **Tile matching**: Optimized with scipy and pre-computed LAB colors
148
-
149
- ### Quality Metrics
150
- - **High SSIM**: Maintains structural similarity (>0.8 for most images)
151
- - **Low MSE**: Minimal pixel-wise error (<0.05 for quality reconstructions)
152
- - **Color Accuracy**: Good histogram correlation (>0.7)
153
-
154
- ## Assignment Requirements Compliance
155
-
156
- ✅ **Step 1: Image Selection and Preprocessing**
157
- - Automatic image resizing and cropping
158
- - Optional color quantization (uniform and K-means)
159
- - Grid-compatible resolution adjustment
160
-
161
- ✅ **Step 2: Image Grid and Thresholding**
162
- - Configurable grid division (8×8 to 128×128)
163
- - Vectorized NumPy operations for performance
164
- - Intensity and color analysis per grid cell
165
-
166
- ✅ **Step 3: Tile Mapping**
167
- - Hugging Face dataset integration for tile sources
168
- - Intelligent tile matching based on color similarity
169
- - Configurable tile sizes and processing options
170
-
171
- ✅ **Step 4: Gradio Interface**
172
- - Comprehensive web interface with parameter controls
173
- - Real-time mosaic generation and preview
174
- - User-friendly parameter adjustment
175
-
176
- ✅ **Step 5: Performance Metrics**
177
- - MSE (Mean Squared Error) calculation
178
- - SSIM (Structural Similarity Index) assessment
179
- - Additional metrics: PSNR, RMSE, MAE, color analysis
180
-
181
- ✅ **Step 6: Performance Analysis**
182
- - Grid size benchmarking (16×16, 32×32, 64×64)
183
- - Implementation comparison (vectorized vs loops)
184
- - Performance scaling analysis and reporting
185
-
186
- ## File Structure
187
-
188
- ```
189
- Mosaic_Generator/
190
- ├── app.py # Main application entry point
191
- ├── run_app.py # Recommended way to run the app (no auto-reload)
192
- ├── benchmark.py # Command-line benchmarking tool
193
- ├── example.py # Example usage demonstration
194
- ├── preload_tiles.py # Pre-load tiles for faster startup
195
- ├── requirements.txt # Python dependencies
196
- ├── README.md # This file
197
- ├── src/ # Source code directory
198
- │ ├── __init__.py # Package initialization
199
- │ ├── config.py # Configuration management
200
- │ ├── mosaic.py # Core mosaic generation
201
- │ ├── tiles.py # Tile management system
202
- │ ├── quantization.py # Color quantization algorithms
203
- │ ├── metrics.py # Similarity metrics
204
- │ ├── pipeline.py # Complete generation pipeline
205
- │ ├── utils.py # Utility functions
206
- │ └── gradio_interface.py # Gradio interface implementation
207
- ├── helpers/ # Helper utilities
208
- │ └── download_tiles.py # Tile download utilities
209
- └── images/ # Output directory for generated images
210
- ```
211
-
212
- ## Contributing
213
-
214
- 1. Fork the repository
215
- 2. Create a feature branch
216
- 3. Make your changes
217
- 4. Add tests if applicable
218
- 5. Submit a pull request
219
-
220
- ## License
221
-
222
- This project is part of CS5130 coursework and follows academic integrity guidelines.
223
-
224
- ## Acknowledgments
225
-
226
- - Hugging Face for providing the tile dataset
227
- - Scikit-image for image processing utilities
228
- - Gradio for the web interface framework
229
- - NumPy and PIL for efficient image manipulation
 
1
+ ---
2
+ title: Mosaic Generator
3
+ emoji: 🧩
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ app_file: run_app.py # use this since you recommend run_app.py
8
+ pinned: false
9
+ ---
10
 
 
11