FrancescoLR commited on
Commit
2d8f0f2
·
verified ·
1 Parent(s): 0ac3af1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -33,7 +33,7 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180):
33
  Extracts slices centered around the center of mass of non-zero voxels in a 3D NIfTI image.
34
  The slices are taken along axial, coronal, and sagittal planes and saved as a single PNG.
35
  """
36
- # Load NIfTI image and get the data
37
  img = nib.load(nifti_path)
38
  data = img.get_fdata()
39
 
@@ -63,21 +63,23 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180):
63
  coronal_slice = extract_2d_slice(data, center, axis=1) # Coronal (y-axis)
64
  sagittal_slice = extract_2d_slice(data, center, axis=0) # Sagittal (x-axis)
65
 
 
 
 
 
 
66
  # Create subplots
67
  fig, axes = plt.subplots(1, 3, figsize=(12, 4))
68
 
69
- # Plot each slice
70
  axes[0].imshow(axial_slice, cmap="gray", origin="lower")
71
  axes[0].axis("off")
72
- axes[0].set_title("Axial")
73
 
74
  axes[1].imshow(coronal_slice, cmap="gray", origin="lower")
75
  axes[1].axis("off")
76
- axes[1].set_title("Coronal")
77
 
78
  axes[2].imshow(sagittal_slice, cmap="gray", origin="lower")
79
  axes[2].axis("off")
80
- axes[2].set_title("Sagittal")
81
 
82
  # Save the figure
83
  plt.tight_layout()
 
33
  Extracts slices centered around the center of mass of non-zero voxels in a 3D NIfTI image.
34
  The slices are taken along axial, coronal, and sagittal planes and saved as a single PNG.
35
  """
36
+ # Load NIfTI image and get the data
37
  img = nib.load(nifti_path)
38
  data = img.get_fdata()
39
 
 
63
  coronal_slice = extract_2d_slice(data, center, axis=1) # Coronal (y-axis)
64
  sagittal_slice = extract_2d_slice(data, center, axis=0) # Sagittal (x-axis)
65
 
66
+ # Apply rotations to each slice
67
+ axial_slice = np.rot90(axial_slice, k=-1) # 90 degrees clockwise
68
+ coronal_slice = np.rot90(coronal_slice, k=1) # 90 degrees anticlockwise
69
+ sagittal_slice = np.rot90(sagittal_slice, k=1) # 90 degrees anticlockwise
70
+
71
  # Create subplots
72
  fig, axes = plt.subplots(1, 3, figsize=(12, 4))
73
 
74
+ # Plot each rotated slice
75
  axes[0].imshow(axial_slice, cmap="gray", origin="lower")
76
  axes[0].axis("off")
 
77
 
78
  axes[1].imshow(coronal_slice, cmap="gray", origin="lower")
79
  axes[1].axis("off")
 
80
 
81
  axes[2].imshow(sagittal_slice, cmap="gray", origin="lower")
82
  axes[2].axis("off")
 
83
 
84
  # Save the figure
85
  plt.tight_layout()