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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
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
 
@@ -66,19 +66,21 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180):
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
 
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
 
 
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
+ coronal_slice = np.rot90(coronal_slice, k=2) # Additional 180 degrees
70
  sagittal_slice = np.rot90(sagittal_slice, k=1) # 90 degrees anticlockwise
71
+ sagittal_slice = np.rot90(sagittal_slice, k=2) # Additional 180 degrees
72
 
73
  # Create subplots
74
  fig, axes = plt.subplots(1, 3, figsize=(12, 4))
75
 
76
  # Plot each rotated slice
77
+ axes[0].imshow(axial_slice, cmap="gray", origin="lower", aspect='auto')
78
  axes[0].axis("off")
79
 
80
+ axes[1].imshow(coronal_slice, cmap="gray", origin="lower", aspect='auto')
81
  axes[1].axis("off")
82
 
83
+ axes[2].imshow(sagittal_slice, cmap="gray", origin="lower", aspect='auto')
84
  axes[2].axis("off")
85
 
86
  # Save the figure