AshWu03 commited on
Commit ·
a227cf5
1
Parent(s): b1b05b1
fixed app.py bug
Browse files- README.md +14 -13
- README.txt +0 -9
- app.py +1 -1
- mosaic_generator.py +0 -82
README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
| 1 |
+
Run and install by downloading the folder and running mosiac generator.py or by using the gradio interface found at https://huggingface.co/spaces/friedeggy/Lab1.
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
Example of use:
|
| 5 |
+
Before
|
| 6 |
+

|
| 7 |
+
After
|
| 8 |
+

|
| 9 |
+
|
| 10 |
+
Performance:
|
| 11 |
+
21 times faster than before!
|
| 12 |
+
Drastically decreases the time required to find a matching tile
|
| 13 |
+
Vecorizes all functions
|
| 14 |
+
Uses caching to store tiles and to find matching tiles
|
README.txt
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
Run and install by downloading the folder and running mosiac generator.py or by using the gradio interface found at ajgjbakjdfgnadklfjgnadkfljngajkslfsng.
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
Performance:
|
| 6 |
-
21 times faster than before!
|
| 7 |
-
Drastically decreases the time required to find a matching tile
|
| 8 |
-
Vecorizes all functions
|
| 9 |
-
Uses caching to store tiles and to find matching tiles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -28,7 +28,7 @@ def create_gradio_interface():
|
|
| 28 |
config.grid_size = (grid_size, grid_size)
|
| 29 |
|
| 30 |
# Create mosaic
|
| 31 |
-
mosaic = create_mosaic(input_image)
|
| 32 |
|
| 33 |
# Compute MSE
|
| 34 |
mse = compute_mse(input_image, mosaic)
|
|
|
|
| 28 |
config.grid_size = (grid_size, grid_size)
|
| 29 |
|
| 30 |
# Create mosaic
|
| 31 |
+
mosaic = create_mosaic(input_image, "tiles", config.grid_size)
|
| 32 |
|
| 33 |
# Compute MSE
|
| 34 |
mse = compute_mse(input_image, mosaic)
|
mosaic_generator.py
CHANGED
|
@@ -12,14 +12,12 @@ Author: Ashley Wu
|
|
| 12 |
Date: Fall 2025
|
| 13 |
"""
|
| 14 |
import numpy as np
|
| 15 |
-
import gradio as gr
|
| 16 |
import functools
|
| 17 |
import sys
|
| 18 |
import config
|
| 19 |
import tile_manager
|
| 20 |
from image_processor import preprocess_image, divide_into_grid
|
| 21 |
from PIL import Image
|
| 22 |
-
from metrics import compute_mse
|
| 23 |
|
| 24 |
#Must set a higher recursion limit due to the vectorize call
|
| 25 |
sys.setrecursionlimit(100000)
|
|
@@ -111,83 +109,3 @@ def create_mosaic(image, tile_directory, grid_size=16):
|
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
-
def create_gradio_interface():
|
| 115 |
-
"""
|
| 116 |
-
Create a Gradio interface for the mosaic generator.
|
| 117 |
-
"""
|
| 118 |
-
|
| 119 |
-
def process_image(input_image, grid_size):
|
| 120 |
-
"""
|
| 121 |
-
Process image and return mosaic.
|
| 122 |
-
|
| 123 |
-
Parameters:
|
| 124 |
-
-----------
|
| 125 |
-
input_image : PIL.Image
|
| 126 |
-
Input image from Gradio
|
| 127 |
-
grid_size : int
|
| 128 |
-
Grid size (will be grid_size × grid_size)
|
| 129 |
-
|
| 130 |
-
Returns:
|
| 131 |
-
--------
|
| 132 |
-
tuple : (mosaic_image, mse_value, message)
|
| 133 |
-
"""
|
| 134 |
-
try:
|
| 135 |
-
# Update grid size
|
| 136 |
-
config.grid_size = (grid_size, grid_size)
|
| 137 |
-
|
| 138 |
-
# Create mosaic
|
| 139 |
-
mosaic = create_mosaic(input_image)
|
| 140 |
-
|
| 141 |
-
# Compute MSE
|
| 142 |
-
mse = compute_mse(input_image, mosaic)
|
| 143 |
-
|
| 144 |
-
message = f"Mosaic created successfully!\nGrid: {grid_size}×{grid_size}\nMSE: {mse:.2f}"
|
| 145 |
-
|
| 146 |
-
return mosaic, message
|
| 147 |
-
|
| 148 |
-
except Exception as e:
|
| 149 |
-
return None, f"Error: {str(e)}"
|
| 150 |
-
|
| 151 |
-
# Create Gradio interface
|
| 152 |
-
with gr.Blocks(title="Image Mosaic Generator") as demo:
|
| 153 |
-
gr.Markdown("# 🎨 Image Mosaic Generator")
|
| 154 |
-
gr.Markdown("Upload an image and create a mosaic version using colored tiles!")
|
| 155 |
-
|
| 156 |
-
with gr.Row():
|
| 157 |
-
with gr.Column():
|
| 158 |
-
input_image = gr.Image(type="pil", label="Input Image")
|
| 159 |
-
grid_size = gr.Slider(
|
| 160 |
-
minimum=8,
|
| 161 |
-
maximum=64,
|
| 162 |
-
value=32,
|
| 163 |
-
step=8,
|
| 164 |
-
label="Grid Size (cells per side)"
|
| 165 |
-
)
|
| 166 |
-
generate_btn = gr.Button("Generate Mosaic", variant="primary")
|
| 167 |
-
|
| 168 |
-
with gr.Column():
|
| 169 |
-
output_image = gr.Image(label="Mosaic Output")
|
| 170 |
-
output_text = gr.Textbox(label="Status", lines=3)
|
| 171 |
-
|
| 172 |
-
# Connect components
|
| 173 |
-
generate_btn.click(
|
| 174 |
-
fn=process_image,
|
| 175 |
-
inputs=[input_image, grid_size],
|
| 176 |
-
outputs=[output_image, output_text]
|
| 177 |
-
)
|
| 178 |
-
|
| 179 |
-
# Add examples if available
|
| 180 |
-
gr.Markdown("### 💡 Tips")
|
| 181 |
-
gr.Markdown("""
|
| 182 |
-
- Start with smaller grid sizes (16×16) for faster processing
|
| 183 |
-
- Larger grid sizes create more detailed mosaics but take longer
|
| 184 |
-
- The default tiles are simple colored squares - you must add your own tiles to the 'tiles' folder!
|
| 185 |
-
""")
|
| 186 |
-
|
| 187 |
-
return demo
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
if __name__ == "__main__":
|
| 191 |
-
# Create and launch the Gradio interface
|
| 192 |
-
demo = create_gradio_interface()
|
| 193 |
-
demo.launch()
|
|
|
|
| 12 |
Date: Fall 2025
|
| 13 |
"""
|
| 14 |
import numpy as np
|
|
|
|
| 15 |
import functools
|
| 16 |
import sys
|
| 17 |
import config
|
| 18 |
import tile_manager
|
| 19 |
from image_processor import preprocess_image, divide_into_grid
|
| 20 |
from PIL import Image
|
|
|
|
| 21 |
|
| 22 |
#Must set a higher recursion limit due to the vectorize call
|
| 23 |
sys.setrecursionlimit(100000)
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|