Browse Source

changed getquantitvevalues scode so that white matter tracts are added to the mix

arefks 2 weeks ago
parent
commit
90c52b4a40
1 changed files with 9 additions and 3 deletions
  1. 9 3
      code/GetQuantitativeValues.py

+ 9 - 3
code/GetQuantitativeValues.py

@@ -59,7 +59,12 @@ def process_files(input_path, output_path, create_figures, save_nifti_mask):
         # Create the temp path to search for dwi_masks
         temp_path = os.path.join(os.path.dirname(file_path), "RegisteredTractMasks_adjusted")
         dwi_masks = glob.glob(os.path.join(temp_path, "*dwi_flipped.nii.gz"))
-
+        white_matter_index = next((i for i, path in enumerate(dwi_masks) if "White_matter" in path), None)
+        white_matter_path = dwi_masks.pop(white_matter_index)
+        # Load white matter mask
+        white_matter_img = nib.load(white_matter_path)
+        white_matter_data = white_matter_img.get_fdata()
+        
         # Load DWI data using nibabel
         dwi_img = nib.load(file_path)
         dwi_data = dwi_img.get_fdata()
@@ -83,10 +88,11 @@ def process_files(input_path, output_path, create_figures, save_nifti_mask):
             # Assuming you want to calculate the average value within the mask region
             for pp in pix_dialation:
                 if pp != 0:
-                    mask_data = binary_dilation(mask_data_pre_dilation, iterations=pp)
+                    mask_data0 = binary_dilation(mask_data_pre_dilation, iterations=pp)
                 else:
-                    mask_data = mask_data_pre_dilation > 0
+                    mask_data0 = mask_data_pre_dilation > 0
                     
+                mask_data = mask_data0 & (white_matter_data > 0)
                 if stroke_path:
                     stroke_image = nib.load(stroke_path)
                     stroke_data = stroke_image.get_fdata()