FrancescoLR commited on
Commit
50a7b79
·
1 Parent(s): f5eba2f

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -29,7 +29,8 @@ def download_model():
29
  def extract_middle_slice(nifti_path, output_image_path):
30
  """
31
  Extracts a middle slice from a 3D NIfTI image and saves it as a PNG file.
32
- The figure size is adjusted dynamically based on the slice's aspect ratio.
 
33
  """
34
  import nibabel as nib
35
  import matplotlib.pyplot as plt
@@ -44,15 +45,16 @@ def extract_middle_slice(nifti_path, output_image_path):
44
 
45
  # Calculate aspect ratio
46
  height, width = slice_data.shape
47
- aspect_ratio = (width / height) * 0.5
48
 
49
- # Dynamically adjust figure size based on aspect ratio
50
- plt.figure(figsize=(6 * aspect_ratio, 6)) # Height fixed to 6, width scaled by aspect ratio
51
  plt.imshow(slice_data, cmap="gray")
52
  plt.axis("off")
53
  plt.savefig(output_image_path, bbox_inches="tight", pad_inches=0)
54
  plt.close()
55
 
 
56
  # Function to run nnUNet inference
57
  @spaces.GPU # Decorate the function to allocate GPU for its execution
58
  def run_nnunet_predict(nifti_file):
 
29
  def extract_middle_slice(nifti_path, output_image_path):
30
  """
31
  Extracts a middle slice from a 3D NIfTI image and saves it as a PNG file.
32
+ The figure size is adjusted dynamically based on the slice's aspect ratio
33
+ and scaled to be 50% smaller.
34
  """
35
  import nibabel as nib
36
  import matplotlib.pyplot as plt
 
45
 
46
  # Calculate aspect ratio
47
  height, width = slice_data.shape
48
+ aspect_ratio = width / height
49
 
50
+ # Dynamically adjust figure size based on aspect ratio and scale down by 0.5
51
+ plt.figure(figsize=(4 * aspect_ratio, 4)) # Height scaled to 3, width scaled proportionally
52
  plt.imshow(slice_data, cmap="gray")
53
  plt.axis("off")
54
  plt.savefig(output_image_path, bbox_inches="tight", pad_inches=0)
55
  plt.close()
56
 
57
+
58
  # Function to run nnUNet inference
59
  @spaces.GPU # Decorate the function to allocate GPU for its execution
60
  def run_nnunet_predict(nifti_file):