Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,30 +7,30 @@ def cargar_imagen_tif(tifile):
|
|
7 |
try:
|
8 |
with rasterio.open(tifile, "r") as src:
|
9 |
data = src.read()
|
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 |
|
|
|
7 |
try:
|
8 |
with rasterio.open(tifile, "r") as src:
|
9 |
data = src.read()
|
10 |
+
image = rasterio.image.fromarray(data[0]) # Convertir el arreglo raster a una imagen Rasterio
|
11 |
+
return convertir_a_blanco_y_negro(image) # 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_image):
|
16 |
try:
|
17 |
+
image_array = np.array(input_image)
|
18 |
|
19 |
+
binary_image = np.zeros_like(image_array)
|
20 |
|
21 |
color_threshold = 50
|
22 |
|
23 |
+
for i in range(image_array.shape[0]):
|
24 |
+
for j in range(image_array.shape[1]):
|
25 |
+
pixel_color = image_array[i, j]
|
26 |
if np.all(pixel_color <= color_threshold):
|
27 |
+
binary_image[i, j] = 0
|
28 |
else:
|
29 |
+
binary_image[i, j] = 255
|
30 |
|
31 |
+
binary_image = Image.fromarray(np.uint8(binary_image))
|
32 |
|
33 |
+
return binary_image, "Hecho"
|
34 |
except Exception as e:
|
35 |
return f"Error al convertir a blanco y negro: {str(e)}"
|
36 |
|