from os.path import join
# locals
-from topng import topng, mask
-from regularjson import search, RT_PATH, JSON_GTS, INFA_STR, EPI_STR
+from topng import topng, mask, CROP_SIZE
+from regularjson import search, RT_PATH, JSON_GTS, INFA_STR, EPI_STR, ENDO_STR
# constants
GLOB_DIR = '../../Data/Images_anonymous/'
-OUT_DIR = './generated/train/'
+OUT_DIR = './generated/90/'
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
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
+ ref = join(r, l2[i]) # logically, should be the json ref's "parent directory" of i dicom image
infarctus = search(ref, INFA_STR)
- # epimask = mask(ref, EPI_STR)
+ epimask = search(ref, EPI_STR)
+ endomask = search(ref, ENDO_STR)
+ # print("ref left:", l1[i]) # Testing..
+ # print("ref right:", ref) # Testing..
# 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!')
+ # print('epimask', epimask)
+
+ if epimask:# this condition could be if necessary
+ # w, h = topng(join(caspath, dic), '{}/{}-{}'.format(join(OUT_DIR, 'infarctus' if infarctus else 'noinfarctus'), cas, dic), epimask=epimask['path'] if epimask else None)
+ # img_, dicimg_, minmax_ = topng(join(caspath, dic),
+ # '{}/{}-{}'.format(join(OUT_DIR, 'infarctus' if infarctus else 'noinfarctus'), cas, dic),
+ # epimask=epimask['path'] if epimask else None,
+ # verbose=True,
+ # )
+
+ # Possibly data augmentation purpose here
+ w, h = topng(
+ join(caspath, dic),
+ outfile='{}/crop-mask/{}-{}'.format(join(OUT_DIR,
+ 'infarctus' if infarctus else 'noinfarctus'),
+ cas,
+ dic,
+ ),
+ epimask=epimask['path'] if epimask else None,
+ centercrop=CROP_SIZE,
+ blackmask=True,
+ ) # crop and mask with black
+
+ if endomask:
+ w, h = topng(
+ join(caspath, dic),
+ outfile='{}/crop-mask-hollow/{}-{}'.format(join(OUT_DIR,
+ 'infarctus' if infarctus else 'noinfarctus'),
+ cas,
+ dic,
+ ),
+ epimask=epimask['path'] if epimask else None,
+ endomask=endomask['path'] if endomask else None,
+ centercrop=CROP_SIZE,
+ blackmask=True,
+ ) # crop and (mask and fill hollow) with black
+
+ w, h = topng(
+ join(caspath, dic),
+ outfile='{}/crop-nomask/{}-{}'.format(join(OUT_DIR,
+ 'infarctus' if infarctus else 'noinfarctus'),
+ cas,
+ dic,
+ ),
+ epimask=epimask['path'] if epimask else None,
+ centercrop=CROP_SIZE,
+ ) # just crop, don't apply black mask
+
+ # w, h = topng(
+ # join(caspath, dic),
+ # outfile='{}/contour/{}-{}'.format(join(OUT_DIR,
+ # 'infarctus' if infarctus else 'noinfarctus'),
+ # cas,
+ # dic,
+ # ),
+ # epimask=epimask['path'] if epimask else None,
+ # redcontour=True,
+ # ) # draw a red contour for visibily purpose
+
+ # segmentation width & height <<
+ # xmin, ymin, xmax, ymax = minmax_
+ # w = xmax - xmin + 1 # +1 : even the position takes a bit
+ # h = ymax - ymin + 1
+ # segmentation width & height >>
+
+
+ # # 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!')