]> AND Private Git Repository - myo-class.git/blobdiff - totraindir.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
applied mask horizontally
[myo-class.git] / totraindir.py
index 4917b56fcfd5ad6098ac4f6d3d1f14a7b407b261..1fbaf08481a790594b088fe442c69e71ae9651c8 100644 (file)
@@ -4,12 +4,12 @@ import pydicom
 from os.path import join
 
 # locals
-from topng import topng
-from regularjson import search, RT_PATH, JSON_GTS, INFA_STR
+from topng import topng, mask
+from regularjson import search, RT_PATH, JSON_GTS, INFA_STR, EPI_STR
 
 # constants
 GLOB_DIR = '../../Data/Images_anonymous/'
-OUT_DIR = './train/'
+OUT_DIR = './generated/train/'
 INDICE_CASE = 'Case'
 
 START = None # to manage the number of Patient Case to use in training + validation, if START == None => 0, if END == None => last index, it will use all in GLOB_DIR
@@ -22,6 +22,11 @@ def get(l, i, r):
 
 if __name__ == '__main__':
        l = sorted(ls(GLOB_DIR))
+
+       # Initiliaze 
+       wmin = hmin = None # None is important here, confert the 'minimum' algo
+       wmax = hmax = w = h = 0
+
        for cas in l[START:END]:# cas like 'Case0002'
                caspath = join(GLOB_DIR, cas)
 
@@ -58,20 +63,29 @@ if __name__ == '__main__':
                                continue
                                pass
 
-
                        for i, dic in enumerate(l1):
                                # print('join', r, l2[i])
                                ref = join(r, l2[i]) # logically, should be the json ref of i dicom image
 
                                infarctus = search(ref, INFA_STR)
-                               if infarctus:
-                                       # print("infarctus:", infarctus) # Testing..
-                                       # topng(join(caspath, dic), '%/%-%' % (join(OUT_DIR, 'infarctus'), cas, dic)
-                                       # print(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'infarctus'), cas, dic)) # Testing..
-                                       topng(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'infarctus'), cas, dic))
-                               else:
-                                       # print("no infarctus:", infarctus) # Testing..
-                                       # print(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'noinfarctus'), cas, dic)) # Testing..
-                                       topng(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'noinfarctus'), cas, dic))
-
-       print('Ended!')
\ No newline at end of file
+                               # epimask = mask(ref, EPI_STR)
+                               # print("infarctus:", infarctus) # Testing..
+                               # topng(join(caspath, dic), '%/%-%' % (join(OUT_DIR, 'infarctus'), cas, dic)
+                               w, h = topng(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'infarctus' if infarctus else 'noinfarctus'), cas, dic))
+
+                               # search maximums
+                               if wmax < w: wmax = w 
+                               if hmax < h: hmax = h
+
+                               # search width minimum
+                               if wmin is None: wmin = w
+                               elif wmin > w: wmin = w
+                               
+                               # search height minimum
+                               if hmin is None: hmin = h
+                               elif hmin > h: hmin = h
+
+       print('min-width, max-width:', (wmin, wmax))
+       print('min-height, max-height:', (hmin, hmax))
+
+       print('Ended!')