Spaces:
Runtime error
Runtime error
Commit ·
71477a6
1
Parent(s): e5aa9c3
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
|
| 2 |
import rasterio
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
-
from skimage.segmentation import slic
|
| 5 |
-
from skimage.color import label2rgb
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
# Function to visualize a single band
|
|
@@ -15,18 +13,9 @@ def plot_band(band_data, band_id):
|
|
| 15 |
|
| 16 |
# Function to perform segmentation on a single band
|
| 17 |
def segment_band(band_data, band_id):
|
| 18 |
-
#
|
| 19 |
-
segments = slic(band_data, n_segments=100, compactness=10, sigma=1)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
segmented_image = label2rgb(segments, image=band_data, kind='avg')
|
| 23 |
-
|
| 24 |
-
plt.figure(figsize=(8, 8))
|
| 25 |
-
plt.imshow(segmented_image)
|
| 26 |
-
plt.title(f"Segmented Band {band_id}")
|
| 27 |
-
plt.show()
|
| 28 |
-
|
| 29 |
-
def main(image_path):
|
| 30 |
try:
|
| 31 |
# Open the TIFF file in read mode
|
| 32 |
with rasterio.open(image_path) as dataset:
|
|
@@ -45,14 +34,11 @@ def main(image_path):
|
|
| 45 |
except Exception as e:
|
| 46 |
print(f"An error occurred: {e}")
|
| 47 |
|
| 48 |
-
# Gradio
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
if __name__ == "__main__":
|
| 58 |
-
iface.launch()
|
|
|
|
| 1 |
|
| 2 |
import rasterio
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
# Function to visualize a single band
|
|
|
|
| 13 |
|
| 14 |
# Function to perform segmentation on a single band
|
| 15 |
def segment_band(band_data, band_id):
|
| 16 |
+
# ... (same as before)
|
|
|
|
| 17 |
|
| 18 |
+
def visualize_tiff(image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
# Open the TIFF file in read mode
|
| 21 |
with rasterio.open(image_path) as dataset:
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
print(f"An error occurred: {e}")
|
| 36 |
|
| 37 |
+
# Create a Gradio interface to upload the TIFF image and visualize it
|
| 38 |
+
gr.Interface(visualize_tiff,
|
| 39 |
+
inputs="file",
|
| 40 |
+
outputs="text",
|
| 41 |
+
live=True,
|
| 42 |
+
capture_session=True,
|
| 43 |
+
title="TIFF Image Visualizer",
|
| 44 |
+
description="Upload a TIFF image containing multiple bands to visualize and segment its bands.").launch()
|
|
|
|
|
|
|
|
|