|
| 1 | +import os |
| 2 | +from os.path import join as jph |
| 3 | + |
| 4 | +from LABelsToolkit.tools.defs import root_dir |
| 5 | +from LABelsToolkit.main import LABelsToolkit as LaB |
| 6 | + |
| 7 | +import a_generate_phantoms_for_examples as gen |
| 8 | + |
| 9 | + |
| 10 | +# ---- GENERATE DATA ---- |
| 11 | + |
| 12 | + |
| 13 | +if not os.path.exists(jph(root_dir, 'data_examples', 'ellipsoids.nii.gz')): |
| 14 | + |
| 15 | + creation_list = {'Examples folder' : True, |
| 16 | + 'Punt e mes' : False, |
| 17 | + 'C' : False, |
| 18 | + 'Planetaruim' : False, |
| 19 | + 'Buckle ellipsoids' : True, |
| 20 | + 'Ellipsoids family' : False, |
| 21 | + 'Cubes in the sky' : False, |
| 22 | + 'Sandwich' : False, |
| 23 | + 'Four-folds' : False} |
| 24 | + |
| 25 | + gen.generate_figures(creation_list) |
| 26 | + |
| 27 | + |
| 28 | +# ---- PATH MANAGER ---- |
| 29 | + |
| 30 | +# input: |
| 31 | +pfi_input_anatomy = jph(root_dir, 'data_examples', 'ellipsoids.nii.gz') |
| 32 | +pfo_output_folder = jph(root_dir, 'data_output') |
| 33 | + |
| 34 | +assert os.path.exists(pfi_input_anatomy), pfi_input_anatomy |
| 35 | +assert os.path.exists(pfo_output_folder) |
| 36 | + |
| 37 | +# output: |
| 38 | +pfi_intensities_segmentation = jph(pfo_output_folder, 'ellipsoids_segm_int.nii.gz') |
| 39 | +pfi_otsu_segmentation = jph(pfo_output_folder, 'ellipsoids_segm_otsu.nii.gz') |
| 40 | +pfi_mog_segmentation_crisp = jph(pfo_output_folder, 'ellipsoids_segm_mog_crisp.nii.gz') |
| 41 | +pfi_mog_segmentation_prob = jph(pfo_output_folder, 'ellipsoids_segm_mog_prob.nii.gz') |
| 42 | + |
| 43 | +print('---- PROCESS 1: intensities segmentation ----') |
| 44 | + |
| 45 | +la = LaB() |
| 46 | +la.segment.simple_intensities_thresholding(pfi_input_anatomy, pfi_intensities_segmentation, number_of_levels=5) |
| 47 | + |
| 48 | +print('---- PROCESS 2: Otsu ----') |
| 49 | + |
| 50 | +la = LaB() |
| 51 | +la.segment.otsu_thresholding(pfi_input_anatomy, pfi_otsu_segmentation, side='above', return_as_mask=False) |
| 52 | + |
| 53 | +print('---- PROCESS 2: MoG ----') |
| 54 | + |
| 55 | +la = LaB() |
| 56 | +la.segment.mixture_of_gaussians(pfi_input_anatomy, pfi_mog_segmentation_crisp, pfi_mog_segmentation_prob, |
| 57 | + K=5, see_histogram=True) |
| 58 | + |
| 59 | +print('---- VIEW ----') |
| 60 | + |
| 61 | +opener1 = 'itksnap -g {} -s {}'.format(pfi_input_anatomy, pfi_intensities_segmentation) |
| 62 | +opener2 = 'itksnap -g {} -s {}'.format(pfi_input_anatomy, pfi_otsu_segmentation) |
| 63 | +opener3 = 'itksnap -g {} -s {}'.format(pfi_input_anatomy, pfi_mog_segmentation_crisp) |
| 64 | +opener4 = 'itksnap -g {} -o {}'.format(pfi_input_anatomy, pfi_mog_segmentation_prob) |
| 65 | + |
| 66 | +os.system(opener1) |
| 67 | +os.system(opener2) |
| 68 | +os.system(opener3) |
| 69 | +os.system(opener4) |
0 commit comments