Spaces:
Runtime error
Runtime error
Commit ·
d1d8cb3
1
Parent(s): 5349407
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import rasterio
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
with rasterio.open(tiff_image.name) as dataset:
|
| 9 |
-
# Read all the raster bands
|
| 10 |
-
image = dataset.read()
|
| 11 |
|
| 12 |
-
# Get
|
| 13 |
-
num_bands =
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
#
|
|
|
|
|
|
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=visualize_bands,
|
| 26 |
-
inputs=gr.inputs.
|
| 27 |
-
outputs=gr.outputs.Image(label="
|
| 28 |
-
title="10-Band TIFF Image Visualization",
|
| 29 |
-
description="Upload a 10-band .tif image and visualize all its bands.",
|
| 30 |
-
live=True
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import rasterio
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
+
def visualize_bands(image_path):
|
| 6 |
+
# Open the image file
|
| 7 |
+
src = rasterio.open(image_path)
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Get information about the image
|
| 10 |
+
num_bands = src.count
|
| 11 |
+
height = src.height
|
| 12 |
+
width = src.width
|
| 13 |
|
| 14 |
+
# Create a subplot for each band
|
| 15 |
+
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(15, 6), sharex=True, sharey=True)
|
| 16 |
|
| 17 |
+
# Loop through each band and plot it
|
| 18 |
+
for i, ax in enumerate(axes.flat):
|
| 19 |
+
band_data = src.read(i + 1)
|
| 20 |
+
ax.imshow(band_data, cmap='gray')
|
| 21 |
+
ax.set_title(f"Band {i + 1}")
|
| 22 |
|
| 23 |
+
plt.tight_layout()
|
| 24 |
+
plt.close() # Close the plot to avoid displaying it as an output
|
| 25 |
|
| 26 |
+
return plt # Return the plot for Gradio to display
|
| 27 |
+
|
| 28 |
+
# Interface for Gradio app
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=visualize_bands,
|
| 31 |
+
inputs=gr.inputs.File(type="file", label="10-band .tif Image"),
|
| 32 |
+
outputs=gr.outputs.Image(type="plot", label="Bands Visualization")
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
+
iface.launch(share=True)
|
|
|
|
|
|