Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
-
import
|
5 |
|
6 |
def cargar_imagen_tif(tifile):
|
7 |
try:
|
8 |
-
with
|
9 |
-
data =
|
10 |
-
|
11 |
-
return convertir_a_blanco_y_negro(
|
12 |
except Exception as e:
|
13 |
return f"Error al cargar la imagen TIFF: {str(e)}"
|
14 |
|
15 |
-
def convertir_a_blanco_y_negro(
|
16 |
try:
|
17 |
-
|
18 |
|
19 |
-
|
20 |
|
21 |
color_threshold = 50
|
22 |
|
23 |
-
for i in range(
|
24 |
-
for j in range(
|
25 |
-
pixel_color =
|
26 |
if np.all(pixel_color <= color_threshold):
|
27 |
-
|
28 |
else:
|
29 |
-
|
30 |
|
31 |
-
|
32 |
|
33 |
-
return
|
34 |
except Exception as e:
|
35 |
return f"Error al convertir a blanco y negro: {str(e)}"
|
36 |
|
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
+
import scipy.misc
|
5 |
|
6 |
def cargar_imagen_tif(tifile):
|
7 |
try:
|
8 |
+
with open(tifile, 'rb') as f:
|
9 |
+
data = scipy.misc.imread(f, mode='L')
|
10 |
+
tuki = Image.fromarray(data) # Convertir el arreglo raster a una imagen PIL
|
11 |
+
return convertir_a_blanco_y_negro(tuki) # Captura el valor de retorno de la función
|
12 |
except Exception as e:
|
13 |
return f"Error al cargar la imagen TIFF: {str(e)}"
|
14 |
|
15 |
+
def convertir_a_blanco_y_negro(input_img):
|
16 |
try:
|
17 |
+
img_array = np.array(input_img)
|
18 |
|
19 |
+
binary_img = np.zeros_like(img_array)
|
20 |
|
21 |
color_threshold = 50
|
22 |
|
23 |
+
for i in range(img_array.shape[0]):
|
24 |
+
for j in range(img_array.shape[1]):
|
25 |
+
pixel_color = img_array[i, j]
|
26 |
if np.all(pixel_color <= color_threshold):
|
27 |
+
binary_img[i, j] = 0
|
28 |
else:
|
29 |
+
binary_img[i, j] = 255
|
30 |
|
31 |
+
binary_img = Image.fromarray(np.uint8(binary_img))
|
32 |
|
33 |
+
return binary_img, "Hecho"
|
34 |
except Exception as e:
|
35 |
return f"Error al convertir a blanco y negro: {str(e)}"
|
36 |
|