abhijeetsarkargis commited on
Commit
71477a6
·
1 Parent(s): e5aa9c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -24
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
- # Perform SLIC (Simple Linear Iterative Clustering) segmentation
19
- segments = slic(band_data, n_segments=100, compactness=10, sigma=1)
20
 
21
- # Map segment labels to different colors
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 Interface
49
- iface = gr.Interface(fn=main,
50
- inputs="text",
51
- outputs=None,
52
- title="TIFF Image Band Visualization and Segmentation",
53
- description="Enter the path to a TIFF image containing multiple bands.",
54
- examples=[['Composite_10_bands_Purulia_2.tif']],
55
- allow_flagging=False)
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()