Martin Horvat преди 1 година
родител
ревизия
de787baa8c
променени са 1 файла, в които са добавени 22 реда и са изтрити 22 реда
  1. 22 22
      python/extract_suv_from_mask.py

+ 22 - 22
python/extract_suv_from_mask.py

@@ -34,7 +34,7 @@ def organ_percentile(img, mask, level, p):
 
     h = img[mask == level]
     print("Extracting SUV% for organ", level)
-    
+
     #histo=[]
     # col=["red", "green", "yellow","pink", "brown", "darkblue", "black", "purple"]
     # i=level
@@ -45,44 +45,43 @@ def organ_percentile(img, mask, level, p):
 
     return suv_x
 
-    
-def main():  
-    
-    # Get the current script's directory
-    current_dir = os.path.dirname(os.path.abspath(__file__))
-    
-    inputCSV = os.path.join(current_dir, "..", 'data', 'cases_retroMManon.csv')                          #input csv file that has the path to each patient image
-    
-    #Returns concatinated sequnces of evenly spaced numbers over a specified interval - for SUV percentile
+
+def main():
+
+    # Input csv file that has the path to each patient imagey
+    inputCSV = os.path.join('../data/cases_retroMManon.csv')
+
+    # Returns concatinated sequnces of evenly spaced numbers over a specified interval - for SUV percentile
     pv=numpy.concatenate((numpy.linspace(10,50,5),
-            numpy.linspace(55,80,6),  
+            numpy.linspace(55,80,6),
             numpy.linspace(82,90,5),
             numpy.linspace(91,100,10)))
-    
+
     pvi=pv.astype(int)      #have to be indigers to be able to append to name
     col_names = ["SUV" + str(x) for x in pvi]
-    
+
     flists = []
-                    
-    with open(inputCSV, 'r') as inFile:                                         #goes trough the whole csv file and makes an flist (list) 
+
+    # goes trough the whole csv file and makes an flist (list)
+    with open(inputCSV, 'r') as inFile:
         cr = csv.DictReader(inFile, lineterminator='\n')
         flists = [row for row in cr]
-        
+
     alldata=[]
 
     histo=[]
-    for idx, entry in enumerate(flists, start=1):                               #
+    for idx, entry in enumerate(flists, start=1):
         PET = entry['Image']
         Seg = entry['Mask']
         Visit = entry['Visit']
         ID = entry['ID']
-    
+
         #open PET image and segmentation
         niPET=nibabel.load(PET)
         niSeg=nibabel.load(Seg)
-        
+
         print(" Processing Patient, Visit , (Image: , Mask:)", idx, len(flists), Visit, entry['Image'], entry['Mask'])
-        #In nnU-Net (organ segmentation are numbered): 
+        #In nnU-Net (organ segmentation are numbered):
         #1 liver  #DM
         #2 spleen  #DM
         #3 lungs #DM
@@ -91,7 +90,7 @@ def main():
         #6 pancreas
         #7 bladder
         #8 kidneys
-    
+
         #extract SUV percentiles from PET image with mask - segmentation
         for level in [1,2,3,4,5,6,7,8]:
             v=organ_percentile(niPET.get_fdata(),niSeg.get_fdata(),level,pv)
@@ -108,9 +107,10 @@ def main():
     # plt.show()
     Names=["Organ", "PatientID", "Visit"]
     Names=numpy.concatenate((Names,col_names))
+
     #make a dataframe to write the data than in excel - that can be read by another script
     df=pd.DataFrame(alldata,columns=Names)
-    df.to_excel('..\\data\\percentilesAnon.xlsx', index=None) #path to where you want to save excel
+    df.to_excel('../data/percentilesAnon.xlsx', index=None) #path to where you want to save excel
     print("Done.")
 
 if __name__ == '__main__':