Update Dockerfile to optimize application setup and streamline dependencies
Browse files- main.py +8 -32
- requirements.txt +1 -0
main.py
CHANGED
@@ -10,6 +10,7 @@ from typing import Dict, List, Optional
|
|
10 |
import cv2
|
11 |
import numpy as np
|
12 |
from PIL import Image
|
|
|
13 |
from fastapi import FastAPI, HTTPException, UploadFile, File
|
14 |
from fastapi.staticfiles import StaticFiles
|
15 |
from pydantic import BaseModel
|
@@ -236,39 +237,14 @@ def generate_new_cube(user_prompt: str) -> dict:
|
|
236 |
|
237 |
|
238 |
def apply_lut_to_image(image_path: str, lut_path: str) -> np.ndarray:
|
239 |
-
"""Apply LUT to image using
|
240 |
try:
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
transformer = LUTTransformer()
|
248 |
-
if not transformer.parse_cube_file(lut_path):
|
249 |
-
raise ValueError(f"Could not parse LUT file: {lut_path}")
|
250 |
-
|
251 |
-
lut_data = np.array(transformer.lut_data)
|
252 |
-
lut_size = transformer.size
|
253 |
-
|
254 |
-
lut_3d = lut_data.reshape((lut_size, lut_size, lut_size, 3))
|
255 |
-
|
256 |
-
img_normalized = img.astype(np.float32) / 255.0
|
257 |
-
|
258 |
-
result = np.zeros_like(img_normalized)
|
259 |
-
|
260 |
-
for i in range(img.shape[0]):
|
261 |
-
for j in range(img.shape[1]):
|
262 |
-
r, g, b = img_normalized[i, j]
|
263 |
-
|
264 |
-
r_idx = min(int(r * (lut_size - 1)), lut_size - 1)
|
265 |
-
g_idx = min(int(g * (lut_size - 1)), lut_size - 1)
|
266 |
-
b_idx = min(int(b * (lut_size - 1)), lut_size - 1)
|
267 |
-
|
268 |
-
result[i, j] = lut_3d[r_idx, g_idx, b_idx]
|
269 |
-
|
270 |
-
result = np.clip(result * 255, 0, 255).astype(np.uint8)
|
271 |
-
return result
|
272 |
|
273 |
except Exception as e:
|
274 |
print(f"Error applying LUT to image: {e}")
|
|
|
10 |
import cv2
|
11 |
import numpy as np
|
12 |
from PIL import Image
|
13 |
+
from pillow_lut import load_cube_file
|
14 |
from fastapi import FastAPI, HTTPException, UploadFile, File
|
15 |
from fastapi.staticfiles import StaticFiles
|
16 |
from pydantic import BaseModel
|
|
|
237 |
|
238 |
|
239 |
def apply_lut_to_image(image_path: str, lut_path: str) -> np.ndarray:
|
240 |
+
"""Apply LUT to image using pillow_lut"""
|
241 |
try:
|
242 |
+
lut = load_cube_file(lut_path)
|
243 |
+
im = Image.open(image_path)
|
244 |
+
result_image = im.filter(lut)
|
245 |
+
|
246 |
+
result_array = np.array(result_image)
|
247 |
+
return result_array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
except Exception as e:
|
250 |
print(f"Error applying LUT to image: {e}")
|
requirements.txt
CHANGED
@@ -24,6 +24,7 @@ opencv-python==4.12.0.88
|
|
24 |
orjson==3.11.0
|
25 |
packaging==25.0
|
26 |
pillow==11.3.0
|
|
|
27 |
pydantic==2.11.7
|
28 |
pydantic_core==2.33.2
|
29 |
python-dotenv==1.1.1
|
|
|
24 |
orjson==3.11.0
|
25 |
packaging==25.0
|
26 |
pillow==11.3.0
|
27 |
+
pillow-lut==1.0.1
|
28 |
pydantic==2.11.7
|
29 |
pydantic_core==2.33.2
|
30 |
python-dotenv==1.1.1
|