Hemaxi commited on
Commit
9dfef1f
·
verified ·
1 Parent(s): 78aa717

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -1,15 +1,35 @@
1
  import gradio as gr
2
  import numpy as np
3
- import tifffile as tiff
4
  from aicsimageio import AICSImage # To handle .czi files
5
  import matplotlib.pyplot as plt
 
6
 
7
  # Placeholder for your 3D model
8
  def process_3d_image(image):
9
  # Dummy model implementation: Replace with your actual model logic
10
- binary_mask = (image > image.mean()).astype(np.uint8)
 
11
  return binary_mask
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # Function to handle file input and processing
14
  def process_file(file):
15
  """
@@ -17,12 +37,7 @@ def process_file(file):
17
  """
18
  if file.name.endswith(".tif"):
19
  # Load .tif file as a 3D numpy array
20
- image = tiff.imread(file.name)
21
- elif file.name.endswith(".czi"):
22
- # Load .czi file using AICSImage
23
- img = AICSImage(file.name)
24
- image = img.get_image_data("CZYX") # Extracting 3D data
25
- image = image[0, 0] # Assuming single channel, single timepoint
26
  else:
27
  raise ValueError("Unsupported file format. Please upload a .tif or .czi file.")
28
 
 
1
  import gradio as gr
2
  import numpy as np
3
+ import tifffile
4
  from aicsimageio import AICSImage # To handle .czi files
5
  import matplotlib.pyplot as plt
6
+ import predict_mask from prediction
7
 
8
  # Placeholder for your 3D model
9
  def process_3d_image(image):
10
  # Dummy model implementation: Replace with your actual model logic
11
+ model_dir = 'https://huggingface.co/Hemaxi/3DCycleGAN/tree/main/CycleGANVesselSegmentation.h5'
12
+ binary_mask = predict_mask(model_dir,image)
13
  return binary_mask
14
 
15
+ def auximread(filepath):
16
+
17
+ image = tifffile.imread(filepath)
18
+
19
+ #the output image should be (X,Y,Z)
20
+ original_0 = np.shape(image)[0]
21
+ original_1 = np.shape(image)[1]
22
+ original_2 = np.shape(image)[2]
23
+
24
+ index_min = np.argmin([original_0, original_1, original_2])
25
+
26
+ if index_min == 0:
27
+ image = image.transpose(1,2,0)
28
+ elif index_min == 1:
29
+ image = image.transpose(0,2,1)
30
+
31
+ return image
32
+
33
  # Function to handle file input and processing
34
  def process_file(file):
35
  """
 
37
  """
38
  if file.name.endswith(".tif"):
39
  # Load .tif file as a 3D numpy array
40
+ image = auximread(file.name)
 
 
 
 
 
41
  else:
42
  raise ValueError("Unsupported file format. Please upload a .tif or .czi file.")
43