Spaces:
Runtime error
Runtime error
Commit
Β·
7eaec10
1
Parent(s):
0d14c53
add tab
Browse files- lut_processor.py +19 -4
lut_processor.py
CHANGED
@@ -21,14 +21,23 @@ def apply_lut(image, lut_name, gamma_correction=True, clip_values=True, strength
|
|
21 |
# Get full path to LUT file
|
22 |
lut_file = Path('cube_luts') / lut_name
|
23 |
|
24 |
-
# Read LUT file
|
25 |
try:
|
26 |
lut = read_LUT_IridasCube(str(lut_file))
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
except Exception as e:
|
29 |
print(f"Error reading LUT file: {e}")
|
30 |
return image.numpy() * 255.0
|
31 |
|
|
|
|
|
32 |
# Handle clipping
|
33 |
if clip_values:
|
34 |
if lut.domain[0].max() == lut.domain[0].min() and lut.domain[1].max() == lut.domain[1].min():
|
@@ -61,13 +70,19 @@ def apply_lut(image, lut_name, gamma_correction=True, clip_values=True, strength
|
|
61 |
if is_non_default_domain:
|
62 |
lut_img = (lut_img - lut.domain[0]) / dom_scale
|
63 |
|
|
|
|
|
|
|
64 |
lut_img = torch.from_numpy(lut_img).float()
|
65 |
|
66 |
if strength < 1.0:
|
67 |
lut_img = strength * lut_img + (1 - strength) * image
|
68 |
|
69 |
-
# Convert back to uint8 range
|
70 |
-
|
|
|
|
|
|
|
71 |
|
72 |
def create_lut_tab():
|
73 |
available_luts = get_available_luts()
|
|
|
21 |
# Get full path to LUT file
|
22 |
lut_file = Path('cube_luts') / lut_name
|
23 |
|
24 |
+
# Read LUT file with error handling for different encodings
|
25 |
try:
|
26 |
lut = read_LUT_IridasCube(str(lut_file))
|
27 |
+
except UnicodeDecodeError:
|
28 |
+
# Try different encodings if utf-8 fails
|
29 |
+
try:
|
30 |
+
with open(str(lut_file), 'r', encoding='latin-1') as f:
|
31 |
+
lut = read_LUT_IridasCube(f)
|
32 |
+
except Exception as e:
|
33 |
+
print(f"Error reading LUT file with latin-1 encoding: {e}")
|
34 |
+
return image.numpy() * 255.0
|
35 |
except Exception as e:
|
36 |
print(f"Error reading LUT file: {e}")
|
37 |
return image.numpy() * 255.0
|
38 |
|
39 |
+
lut.name = lut_name
|
40 |
+
|
41 |
# Handle clipping
|
42 |
if clip_values:
|
43 |
if lut.domain[0].max() == lut.domain[0].min() and lut.domain[1].max() == lut.domain[1].min():
|
|
|
70 |
if is_non_default_domain:
|
71 |
lut_img = (lut_img - lut.domain[0]) / dom_scale
|
72 |
|
73 |
+
# Ensure values are in valid range
|
74 |
+
lut_img = np.clip(lut_img, 0, 1)
|
75 |
+
|
76 |
lut_img = torch.from_numpy(lut_img).float()
|
77 |
|
78 |
if strength < 1.0:
|
79 |
lut_img = strength * lut_img + (1 - strength) * image
|
80 |
|
81 |
+
# Convert back to uint8 range and ensure proper bounds
|
82 |
+
result = (lut_img.numpy() * 255.0)
|
83 |
+
result = np.clip(result, 0, 255).astype(np.uint8)
|
84 |
+
|
85 |
+
return result
|
86 |
|
87 |
def create_lut_tab():
|
88 |
available_luts = get_available_luts()
|