コード例 #1
0
def experiment(training_yaml_path,
               testing_yaml_path,
               featers_plus_classifs,
               tile_shape,
               use_voxelsize_norm,
               working_voxelsize_mm,
               visualization=False,
               train=False):

    training_yaml = misc.obj_from_file(training_yaml_path, filetype='yaml')
    testing_yaml = misc.obj_from_file(testing_yaml_path, filetype='yaml')

    # import ipdb; ipdb.set_trace()  # noqa BREAKPOINT

    results = []

    for fpc in featers_plus_classifs:
        feature_fcn = fpc[0]
        classif_fcn = fpc[1]

        fvall = one_exp_set_for_whole_dataset(
            training_yaml, testing_yaml, tile_shape, feature_fcn, classif_fcn,
            train, use_voxelsize_norm, working_voxelsize_mm, visualization)

        result = {'params': str(fpc), 'fvall': fvall}
        results.append(result)
        print(results)

    return results
コード例 #2
0
def experiment(training_yaml_path, testing_yaml_path,  featers_plus_classifs,
               tile_shape,
               use_voxelsize_norm,
               working_voxelsize_mm,
               visualization=False, train=False):

    training_yaml = misc.obj_from_file(training_yaml_path, filetype='yaml')
    testing_yaml = misc.obj_from_file(testing_yaml_path, filetype='yaml')

    # import ipdb; ipdb.set_trace()  # noqa BREAKPOINT

    results = []

    for fpc in featers_plus_classifs:
        feature_fcn = fpc[0]
        classif_fcn = fpc[1]

        fvall = one_exp_set_for_whole_dataset(
            training_yaml, testing_yaml, tile_shape,
            feature_fcn, classif_fcn,
            train,
            use_voxelsize_norm,
            working_voxelsize_mm,
            visualization)

        result = {'params': str(fpc), 'fvall': fvall}
        results.append(result)
        print results

    return results
コード例 #3
0
def main():

    parser = argparse.ArgumentParser(
        description=__doc__)  # 'Simple VTK Viewer')

    parser.add_argument('-i', '--inputfile', default=None, help='File as .pkl')
    parser.add_argument('-o',
                        '--outputfile',
                        default=None,
                        help='Output file. Filetype is given by extension.')

    parser.add_argument('-k',
                        '--key',
                        default='data3d',
                        help='Which key should be writen to output file. \
                        Default is "data3d". You can use "segmentation"')
    args = parser.parse_args()
    data = misc.obj_from_file(args.inputfile, filetype='pickle')
    data3d_uncrop = qmisc.uncrop(data[args.key], data['crinfo'],
                                 data['orig_shape'])
    #import ipdb; ipdb.set_trace() # BREAKPOINT
    import SimpleITK as sitk
    sitk_img = sitk.GetImageFromArray(data3d_uncrop.astype(np.uint16),
                                      isVector=True)
    sitk.WriteImage(sitk_img, args.outputfile)
    print(
        "Warning: .mhd and .raw format has corupted metadta. You can edit it manually."
    )
コード例 #4
0
ファイル: simple_segmentation.py プロジェクト: Trineon/lisa
def main():

    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
            description='Module for segmentation of simple anatomical structures')
    parser.add_argument('-i', '--inputfile',
            default='organ.pkl',
            help='path to data dir')

    args = parser.parse_args()

    data = misc.obj_from_file(args.inputfile, filetype = 'pickle')
    data3d = data['data3d']
    voxelsize_mm = data['voxelsize_mm']

    ss = SimpleSegmentation()
    simple_seg = ss.simple_segmentation(data3d, voxelsize_mm)

    #visualization
    pyed = sed3.sed3(data['data3d'], seeds=simple_seg)
    pyed.show()

    # save
    savestring = raw_input('Save output data? (y/n): ')
    if savestring in ['Y', 'y']:
        misc.obj_to_file(data, "resection.pkl", filetype='pickle')
コード例 #5
0
def experiment(path_to_yaml,
               featrs_plus_classifs,
               tile_shape,
               visualization=False,
               train=False):

    inputdata = misc.obj_from_file(path_to_yaml, filetype='yaml')

    #import ipdb; ipdb.set_trace()  # noqa BREAKPOINT

    results = []

    for fpc in featrs_plus_classifs:
        feature_fcn = fpc[0]
        classif_fcn = fpc[1]

        fvall = one_experiment_setting_for_whole_dataset(
            inputdata, tile_shape, feature_fcn, classif_fcn, train,
            visualization)

        result = {'params': str(fpc), 'fvall': fvall}
        results.append(result)
        print(results)

    return results
コード例 #6
0
ファイル: pklz_info.py プロジェクト: jedocs/lisa
def main():

    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    data3d_a_path = None  # os.path.join(path_to_script, '../../../data/medical/data_orig/sliver07/training-part1/liver-orig001.mhd')
    data3d_b_path = None  #os.path.join(path_to_script, '../../../data/medical/data_orig/sliver07/training-part1/liver-seg001.mhd')
    parser = argparse.ArgumentParser(
        description='Information about pkl/pklz file')
    parser.add_argument('pklzFile', help='path to data')
    args = parser.parse_args()

    data = misc.obj_from_file(args.pklzFile, 'pickle')
    print(data)

    try:
        pyed = sed3.sed3(data['data3d'], contour=data['segmentation'])
        pyed.show()
    except:
        try:

            pyed = sed3.sed3(data['data3d'])
            pyed.show()
        except:
            print("Problem with visualization")
コード例 #7
0
ファイル: simple_segmentation.py プロジェクト: kunesj/lisa
def main():

    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description='Module for segmentation of simple anatomical structures')
    parser.add_argument('-i',
                        '--inputfile',
                        default='organ.pkl',
                        help='path to data dir')

    args = parser.parse_args()

    data = misc.obj_from_file(args.inputfile, filetype='pickle')
    data3d = data['data3d']
    voxelsize_mm = data['voxelsize_mm']

    ss = SimpleSegmentation()
    simple_seg = ss.simple_segmentation(data3d, voxelsize_mm)

    #visualization
    pyed = sed3.sed3(data['data3d'], seeds=simple_seg)
    pyed.show()

    # save
    savestring = raw_input('Save output data? (y/n): ')
    if savestring in ['Y', 'y']:
        misc.obj_to_file(data, "resection.pkl", filetype='pickle')
コード例 #8
0
ファイル: update_stable.py プロジェクト: kunesj/lisa
def update_by_plan(filename="~/lisa_data/.update_plan.yaml",
                   update_periode_days=10):
    """
    :return: True or False
    """

    filename = op.expanduser(filename)

    retval = False
    now = datetime.datetime.now()
    try:
        # this import is necessary here. This module requires scipy and it is
        # not installed yet
        import misc
        data = misc.obj_from_file(filename)

        string_date = data['update_datetime']
        dt = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f")
        dt_delta = datetime.timedelta(days=update_periode_days)
        if now > (dt + dt_delta):
            retval = True
            data['update_datetime'] = str(now)
            misc.obj_to_file(data, filename)

        # data['update_datetime'] =
    except:
        retval = True
        data = {}
        data['update_datetime'] = str(now)
        import lisa_data
        lisa_data.create_lisa_data_dir_tree()
        misc.obj_to_file(data, filename)

    return retval
コード例 #9
0
ファイル: pklz_info.py プロジェクト: vlukes/lisa
def main():

    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    data3d_a_path = None # os.path.join(path_to_script, '../../../data/medical/data_orig/sliver07/training-part1/liver-orig001.mhd')
    data3d_b_path = None #os.path.join(path_to_script, '../../../data/medical/data_orig/sliver07/training-part1/liver-seg001.mhd')
    parser = argparse.ArgumentParser(
            description='Information about pkl/pklz file')
    parser.add_argument('pklzFile',
            help='path to data' )
    args = parser.parse_args()

    data = misc.obj_from_file(args.pklzFile, 'pickle')
    print data

    try:
        pyed = py3DSeedEditor.py3DSeedEditor(data['data3d'], contour=data['segmentation'])
        pyed.show()
    except:
        try:

            pyed = py3DSeedEditor.py3DSeedEditor(data['data3d'])
            pyed.show()
        except:
            print "Problem with visualization"
コード例 #10
0
ファイル: update_stable.py プロジェクト: andrlikjirka/lisa
def update_by_plan(filename="~/lisa_data/.update_plan.yaml", update_periode_days=10):
    """
    :return: True or False
    """

    filename = op.expanduser(filename)

    retval = False
    now = datetime.datetime.now() 
    try:
        # this import is necessary here. This module requires scipy and it is 
        # not installed yet
        import misc
        data = misc.obj_from_file(filename)

        string_date = data['update_datetime']
        dt = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f")
        dt_delta = datetime.timedelta(days=update_periode_days)
        if now > (dt + dt_delta):
            retval = True
            data['update_datetime'] = str(now)
            misc.obj_to_file(data, filename)

        # data['update_datetime'] = 
    except:
        retval = True
        data = {}
        data['update_datetime'] = str(now)
        import lisa_data
        lisa_data.create_lisa_data_dir_tree()
        misc.obj_to_file(data, filename)

    return retval
コード例 #11
0
ファイル: gen_volume_tree.py プロジェクト: Trineon/lisa
    def importFromYaml(self, filename):
        rawdata = misc.obj_from_file(filename=filename, filetype='yaml')
        self.rawdata = rawdata

        try:
            self.tree_data = self.rawdata['graph']['porta']
        except:
            self.tree_data = self.rawdata['Graph']
コード例 #12
0
ファイル: config.py プロジェクト: vlukes/lisa
def update_config_records(filename, new_cfg):
    """
    All records of config file are updated exept records_to_save.
    """
    if os.path.isfile(filename):
        cfg = misc.obj_from_file(filename, filetype='yaml')
        cfg.update(new_cfg)
        print cfg
        misc.obj_to_file(new_cfg, "test_" + filename , filetype='yaml')
コード例 #13
0
ファイル: config.py プロジェクト: vlukes/lisa
def delete_config_records(filename, records_to_save=[]):
    """
    All records of config file are deleted except records_to_save.
    """
    if os.path.isfile(filename):
        cfg = misc.obj_from_file(filename, filetype='yaml')
        new_cfg = subdict(cfg, records_to_save)
        print cfg
        misc.obj_to_file(new_cfg, "test_" + filename , filetype='yaml')
コード例 #14
0
def main():

    # logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    # logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description='Module for segmentation of simple anatomical structures')
    parser.add_argument('-i',
                        '--inputfile',
                        default='vessels.pkl',
                        help='path to data dir')

    # args = parser.parse_args()
    # horsi kvalita segmentace
    # datapath = os.path.join(path_to_script, "../vessels1.pkl")
    # hypodenzni meta
    # datapath = os.path.join(path_to_script, args.inputfile)
    # horsi kvalita segmentace
    # datapath = os.path.join(path_to_script, "../organ.pkl")

    # data = misc.obj_from_file(args.inputfile, filetype = 'pickle')

    dcmdir = '/home/tomas/Dropbox/Work/Data/medical/org-38289898-export1.pklz'
    data = misc.obj_from_file(dcmdir, filetype='pickle')

    # windowing
    data['data3d'] = tools.windowing(data['data3d'], level=50, width=350)
    # data['data3d'] = smoothing(data['data3d'], sliceId=0)

    # smoothing ----------------
    # bilateral
    # data['data3d'] = tools.smoothing_bilateral(data['data3d'],
    # sigma_space=15, sigma_color=0.05, sliceId=0)
    # more bilateral
    # data['data3d'] = tools.smoothing_bilateral(data['data3d'],
    # sigma_space=15, sigma_color=0.1, sliceId=0)
    # total-variation
    data['data3d'] = tools.smoothing_tv(data['data3d'], weight=0.05, sliceId=0)
    # more total-variation
    # data['data3d'] = tools.smoothing_tv(data['data3d'], weight=0.2,
    # multichannel=False, sliceId=0)
    # sed3.sed3(data['data3d']).show()

    tumory = Lesions()
    # tumory.overlay_test()
    tumory.import_data(data)
    tumory.automatic_localization()

    tumors = tumory.segmentation == tumory.data['slab']['lesions']
    sed3.sed3(tumory.data3d, contour=tumors).show()
コード例 #15
0
ファイル: gen_volume_tree.py プロジェクト: andrlikjirka/lisa
    def importFromYaml(self, filename):
        rawdata = misc.obj_from_file(filename=filename, filetype='yaml')
        self.rawdata = rawdata

        try:
            # key is usually "porta" or "microstructure"
            keys = self.rawdata['graph'].keys()
            self.tree_data = self.rawdata['graph'][keys[0]]
        except:
            self.tree_data = self.rawdata['Graph']
コード例 #16
0
ファイル: lesions.py プロジェクト: vlukes/lisa
def main():

    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    # logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description='Module for segmentation of simple anatomical structures')
    parser.add_argument('-i', '--inputfile', default='vessels.pkl',
                        help='path to data dir')

    # args = parser.parse_args()
    # horsi kvalita segmentace
    # datapath = os.path.join(path_to_script, "../vessels1.pkl")
    # hypodenzni meta
    # datapath = os.path.join(path_to_script, args.inputfile)
    # horsi kvalita segmentace
    # datapath = os.path.join(path_to_script, "../organ.pkl")

    # data = misc.obj_from_file(args.inputfile, filetype = 'pickle')

    dcmdir = '/home/tomas/Dropbox/Work/Data/medical/org-38289898-export1.pklz'
    data = misc.obj_from_file(dcmdir, filetype='pickle')

    # windowing
    data['data3d'] = tools.windowing(data['data3d'], level=50, width=350)
    # data['data3d'] = smoothing(data['data3d'], sliceId=0)

    # smoothing ----------------
    # bilateral
    # data['data3d'] = tools.smoothing_bilateral(data['data3d'],
    # sigma_space=15, sigma_color=0.05, sliceId=0)
    # more bilateral
    # data['data3d'] = tools.smoothing_bilateral(data['data3d'],
    # sigma_space=15, sigma_color=0.1, sliceId=0)
    # total-variation
    data['data3d'] = tools.smoothing_tv(data['data3d'], weight=0.05, sliceId=0)
    # more total-variation
    # data['data3d'] = tools.smoothing_tv(data['data3d'], weight=0.2,
    # multichannel=False, sliceId=0)
    # py3DSeedEditor.py3DSeedEditor(data['data3d']).show()
    # ---------------------------gym

    tumory = Lesions()
    # tumory.overlay_test()
    tumory.import_data(data)
    tumory.automatic_localization()

    tumors = tumory.segmentation == tumory.data['slab']['lesions']
    py3DSeedEditor.py3DSeedEditor(tumory.data3d, contour=tumors).show()
コード例 #17
0
ファイル: qmisc_test.py プロジェクト: vlukes/lisa
    def test_obj_to_and_from_file_pickle(self):
        testdata = np.random.random([4, 4, 3])
        test_object = {'a': 1, 'data': testdata}

        filename = 'test_obj_to_and_from_file.pkl'
        misc.obj_to_file(test_object, filename, 'pickle')
        saved_object = misc.obj_from_file(filename, 'pickle')

        self.assertTrue(saved_object['a'] == 1)
        self.assertTrue(saved_object['data'][1, 1, 1] == testdata[1, 1, 1])

        os.remove(filename)
コード例 #18
0
ファイル: config.py プロジェクト: vlukes/lisa
def check_config_version_and_remove_old_records(filename, version,
                                                records_to_save):
    """
    Check if config file version is ok. If it is not all records except
    records_to_save are deleted and config_version in file is set to version.
    It is used to update user configuration.
    """
    if os.path.isfile(filename):
        cfg = misc.obj_from_file(filename, filetype='yaml')
        if ('config_version' in cfg and (cfg['config_version'] == version)):
# everything is ok, no need to panic
            return
        else:
# older version of config file
            cfg = misc.obj_from_file(filename, filetype='yaml')
            misc.obj_to_file(cfg, filename + '.old', filetype='yaml')
            print 'cfg ', cfg
            new_cfg = subdict(cfg, records_to_save)
            new_cfg['config_version'] = version
            print 'ncfg ', new_cfg
            misc.obj_to_file(new_cfg, filename, filetype='yaml')
コード例 #19
0
ファイル: histology_analyser.py プロジェクト: vlukes/lisa
    def skeleton_analysis(self, guiUpdateFunction = None):
        """
        Glossary:
        element: line structure of skeleton connected to node on both ends
        node: connection point of elements. It is one or few voxelsize_mm
        terminal: terminal node


        """
        if not fast_debug:
            if self.volume_data is not None:
                skdst = self.__radius_analysis_init()

            stats = {}
            len_edg = np.max(self.sklabel)
            #len_edg = 30
                
            for edg_number in range(1,len_edg+1):
                edgst = self.__connection_analysis(edg_number)
                edgst.update(self.__edge_length(edg_number))
                edgst.update(self.__edge_curve(edg_number, edgst, self.voxelsize_mm))
                edgst.update(self.__edge_vectors(edg_number, edgst))
                #edgst = edge_analysis(sklabel, i)
                if self.volume_data is not None:
                    edgst['radius_mm'] = float(self.__radius_analysis(edg_number,skdst))
                stats[edgst['id']] = edgst
                
                if guiUpdateFunction is not None: # update gui progress
                    guiUpdateFunction(edg_number,len_edg,1)

#save data for faster debug
            struct = {'sVD':self.volume_data, 'stats':stats, 'len_edg':len_edg}
            misc.obj_to_file(struct, filename='tmp.pkl', filetype='pickle')
        else:
            struct = misc.obj_from_file(filename='tmp.pkl', filetype='pickle')
            self.volume_data = struct['sVD']
            stats = struct['stats']
            len_edg = struct['len_edg']


        #@TODO dokončit
        for edg_number in range (1,len_edg+1):
            edgst = stats[edg_number]
            edgst.update(self.__connected_edge_angle(edg_number, stats))
            
            if guiUpdateFunction is not None: # update gui progress
                    guiUpdateFunction(edg_number,len_edg,2)




        return stats
コード例 #20
0
ファイル: PavelTestingModule.py プロジェクト: kunesj/lisa
def main4():

    data = misc.obj_from_file('c:\_bp_data\d5\org-liver-orig004.mhd-3mm_alpha45.pklz', filetype = 'pickle')

    outputTmp = sg.vesselSegmentation(
        data['data3d'],
        segmentation = data['segmentation'],
        threshold = -1,
        inputSigma = 0.15,
        dilationIterations = 2,
        interactivity = True,
        biggestObjects = False,
        binaryClosingIterations = 2,
        binaryOpeningIterations = 0)
コード例 #21
0
ファイル: PavelTestingModule.py プロジェクト: mjirik/lisa
def main4():

    data = misc.obj_from_file('c:\_bp_data\d5\org-liver-orig004.mhd-3mm_alpha45.pklz', filetype = 'pickle')

    outputTmp = sg.vesselSegmentation(
        data['data3d'],
        segmentation = data['segmentation'],
        threshold = -1,
        inputSigma = 0.15,
        dilationIterations = 2,
        interactivity = True,
        biggestObjects = False,
        binaryClosingIterations = 2,
        binaryOpeningIterations = 0)
コード例 #22
0
ファイル: histology_analyser.py プロジェクト: vlukes/lisa
def processData(inputfile=None,threshold=None,skeleton=False,crop=None):
    ### when input is just skeleton
    if skeleton:
        logger.info("input is skeleton")
        struct = misc.obj_from_file(filename='tmp0.pkl', filetype='pickle')
        data3d_skel = struct['skel']
        data3d_thr = struct['thr']
        data3d = struct['data3d']
        metadata = struct['metadata']
        ha = HistologyAnalyser(data3d, metadata, threshold, nogui=True)
        logger.info("end of is skeleton")
    else: 
        ### Reading/Generating data
        if inputfile is None: ## Using generated sample data
            logger.info('Generating sample data...')
            metadata = {'voxelsize_mm': [1, 1, 1]}
            data3d = generate_sample_data(1)
        else: ## Normal runtime
            dr = datareader.DataReader()
            data3d, metadata = dr.Get3DData(inputfile)
        
        ### Crop data
        if crop is not None:
            logger.debug('Croping data: %s', str(crop))
            data3d = data3d[crop[0]:crop[1], crop[2]:crop[3], crop[4]:crop[5]]
        
        ### Init HistologyAnalyser object
        logger.debug('Init HistologyAnalyser object')
        ha = HistologyAnalyser(data3d, metadata, threshold, nogui=True)
        
        ### No GUI == No Remove Area
        
        ### Segmentation
        logger.debug('Segmentation')
        data3d_thr, data3d_skel = ha.data_to_skeleton()
        
    ### Computing statistics
    logger.info("######### statistics")
    ha.skeleton_to_statistics(data3d_thr, data3d_skel)
    
    ### Saving files
    logger.info("##### write to file")
    ha.writeStatsToCSV()
    ha.writeStatsToYAML()
    ha.writeSkeletonToPickle('skel.pkl')
    #struct = {'skel': data3d_skel, 'thr': data3d_thr, 'data3d': data3d, 'metadata':metadata}
    #misc.obj_to_file(struct, filename='tmp0.pkl', filetype='pickle')
    
    ### End
    logger.info('Finished')
コード例 #23
0
ファイル: qmisc_test.py プロジェクト: vlukes/lisa
    def test_obj_to_and_from_file_with_directories(self):
        import shutil
        testdata = np.random.random([4, 4, 3])
        test_object = {'a': 1, 'data': testdata}

        dirname = '__test_write_and_read'
        filename = '__test_write_and_read/test_obj_to_and_from_file.pkl'

        misc.obj_to_file(test_object, filename, 'pickle')
        saved_object = misc.obj_from_file(filename, 'pickle')

        self.assertTrue(saved_object['a'] == 1)
        self.assertTrue(saved_object['data'][1, 1, 1] == testdata[1, 1, 1])

        shutil.rmtree(dirname)
コード例 #24
0
ファイル: volumetry_evaluation.py プロジェクト: kunesj/lisa
def evaluate_and_write_to_file(
        inputYamlFile,
        directoryPklz,
        directorySliver,
        outputfile,
        visualization,
        return_dir_lists=False,
        special_evaluation_function=None,
        return_all_data=False
):
    """
    Function computes yaml file (if there are given input sliver and pklz
    directories). Based on yaml file are compared sliver segmentations and
    our pklz files.
    """
    dirlists = None
    if (directoryPklz is not None) and (directorySliver is not None):
        dirlists = generate_input_yaml(
            directorySliver,
            directoryPklz,
            yaml_filename=inputYamlFile,
            return_dir_lists=return_dir_lists
        )

    # input parser
    data_file = inputYamlFile
    inputdata = misc.obj_from_file(data_file, filetype='yaml')

    evaluation_all = eval_all_from_dataset_metadata(
        inputdata, visualization,
        special_evaluation_function=special_evaluation_function
    )

    logger.debug(str(evaluation_all))
    logger.debug('eval all')

    logger.debug(make_sum(evaluation_all))
    write_csv(evaluation_all, filename=outputfile + '.csv')
    misc.obj_to_file(evaluation_all, outputfile + '.pkl', filetype='pkl')

    retval = []

    if return_dir_lists:
        retval.append(dirlists)
    if return_all_data:
        retval.append(evaluation_all)
    if len(retval) > 0:
        return retval
コード例 #25
0
ファイル: config.py プロジェクト: vlukes/lisa
def get_config(filename, default_cfg):
    """
    Looks config file and update default_cfg values.

    If file does not exist it is created.
    """
    if os.path.isfile(filename):
        cfg = misc.obj_from_file(filename, filetype='yaml')
        default_cfg.update(cfg)
        cfg_out = default_cfg
    else:
        misc.obj_to_file(default_cfg, filename, filetype='yaml')
        cfg_out = default_cfg

        # default config
    return cfg_out
コード例 #26
0
ファイル: histology_analyser_gui.py プロジェクト: vlukes/lisa
    def processDataGUI(self, data3d=None, metadata=None, crgui=True):
        """
        GUI version of histology analysation algorithm
        """
        self.data3d = data3d
        self.metadata = metadata
        self.crgui = crgui
        
        ### when input is just skeleton
        # TODO - edit input_is_skeleton mode to run in gui + test if it works
        if self.args_skeleton: 
            logger.info("input is skeleton")
            struct = misc.obj_from_file(filename='tmp0.pkl', filetype='pickle')
            self.data3d_skel = struct['skel']
            self.data3d_thr = struct['thr']
            self.data3d = struct['data3d']
            self.metadata = struct['metadata']
            self.ha = HA.HistologyAnalyser(self.data3d, self.metadata, nogui=False)
            logger.info("end of is skeleton")
            self.fixWindow() # just to be sure
        else:
            ### Crop data
            self.setStatusBarText('Crop Data')
            if self.args_crop is not None: # --crop cli parameter crop
                crop = self.args_crop
                logger.debug('Croping data: %s', str(crop))
                self.data3d = self.data3d[crop[0]:crop[1], crop[2]:crop[3], crop[4]:crop[5]]
            if self.crgui is True: # --crgui gui crop
                logger.debug('Gui data crop')
                self.data3d = self.showCropDialog(self.data3d)
            
            ### Init HistologyAnalyser object
            logger.debug('Init HistologyAnalyser object')
            self.ha = HA.HistologyAnalyser(self.data3d, self.metadata, nogui=False)
            
            ### Remove Area
            logger.debug('Remove area')
            self.setStatusBarText('Remove area')
            self.showRemoveDialog(self.ha.data3d)

            ### Segmentation
            logger.debug('Segmentation Query Dialog')
            self.showSegmQueryDialog()
コード例 #27
0
ファイル: datareader.py プロジェクト: gilyclem/larVolumeToObj
    def __ReadFromFile(self, datapath):
        path, ext = os.path.splitext(datapath)
        ext = ext[1:]
        if ext in ('pklz', 'pkl'):
            logger.debug('pklz format detected')
            import misc
            data = misc.obj_from_file(datapath, filetype='pkl')
            data3d = data.pop('data3d')
            # etadata must have series_number
            metadata = {
                'series_number': 0,
                'datadir': datapath
            }
            metadata.update(data)

        elif ext in ['hdf5']:
            data = self.read_hdf5(datapath)
            data3d = data.pop('data3d')

            # back compatibility
            if 'metadata' in data.keys():
                data = data['metadata']
            # etadata must have series_number
            metadata = {
                'series_number': 0,
                'datadir': datapath
            }
            metadata.update(data)

        elif ext in ['idx']:
            import idxformat
            idxreader = idxformat.IDXReader()
            data3d, metadata = idxreader.read(datapath)
	   
        elif ext in ['dcm', 'DCM', 'dicom']:
            data3d, metadata = self._read_with_sitk(datapath)
            metadata = self._fix_sitk_bug(datapath, metadata)
        else:
            logger.debug('file format "' + ext + '"')
            # reading raw file
            data3d, metadata = self._read_with_sitk(datapath)
	
        return data3d, metadata
コード例 #28
0
ファイル: convert_pkl.py プロジェクト: Trineon/lisa
def main():

    parser = argparse.ArgumentParser(description=__doc__) # 'Simple VTK Viewer')

    parser.add_argument('-i','--inputfile', default=None,
                      help='File as .pkl')
    parser.add_argument('-o','--outputfile', default=None,
                      help='Output file. Filetype is given by extension.')

    parser.add_argument('-k','--key', default='data3d',
                      help='Which key should be writen to output file. \
                        Default is "data3d". You can use "segmentation"')
    args = parser.parse_args()
    data = misc.obj_from_file(args.inputfile, filetype = 'pickle')
    data3d_uncrop = qmisc.uncrop(data[args.key], data['crinfo'], data['orig_shape'])
    #import ipdb; ipdb.set_trace() # BREAKPOINT
    import SimpleITK as sitk
    sitk_img = sitk.GetImageFromArray(data3d_uncrop.astype(np.uint16), isVector=True)
    sitk.WriteImage(sitk_img, args.outputfile)
    print "Warning: .mhd and .raw format has corupted metadta. You can edit it manually."
コード例 #29
0
ファイル: organ_segmentation.py プロジェクト: Trineon/lisa
def main():  # pragma: no cover

    #    import ipdb; ipdb.set_trace() # BREAKPOINT
    try:
        ch, fh = logger_init()
        cfg = lisa_config_init()
        args = parser_init(cfg)

        # rint args["arg"]
        oseg_argspec_keys = config.get_function_keys(
            OrganSegmentation.__init__)

        if args["debug"]:
            ch.setLevel(logging.DEBUG)
            args["debug_mode"] = True

        if args["iparams"] is not None:
            params = misc.obj_from_file(args["iparams"], filetype='pickle')

        else:
            params = config.subdict(args, oseg_argspec_keys)

        logger.debug('params ' + str(params))
        oseg = OrganSegmentation(**params)

        if args["no_interactivity"]:
            oseg.ninteractivity()
            oseg.save_outputs()
        else:
            # mport_gui()
            from lisaWindow import OrganSegmentationWindow
            from PyQt4.QtGui import QApplication
            app = QApplication(sys.argv)
            oseg_w = OrganSegmentationWindow(oseg)  # noqa
#    import pdb; pdb.set_trace()
            sys.exit(app.exec_())

    except Exception as e:
        # mport exceptionProcessing
        exceptionProcessing.reportException(e)
        print traceback.format_exc()
コード例 #30
0
def experiment(path_to_yaml, featrs_plus_classifs, tile_shape, visualization=False, train=False):

    inputdata = misc.obj_from_file(path_to_yaml, filetype="yaml")

    # import ipdb; ipdb.set_trace()  # noqa BREAKPOINT

    results = []

    for fpc in featrs_plus_classifs:
        feature_fcn = fpc[0]
        classif_fcn = fpc[1]

        fvall = one_experiment_setting_for_whole_dataset(
            inputdata, tile_shape, feature_fcn, classif_fcn, train, visualization
        )

        result = {"params": str(fpc), "fvall": fvall}
        results.append(result)
        print results

    return results
コード例 #31
0
    def get_dir(self, writedicomdirfile=True):
        """
        Check if exists dicomdir file and load it or cerate it

        dcmdir = get_dir(dirpath)

        dcmdir: list with filenames, SeriesNumber and SliceLocation
        """
        createdcmdir = True

        dicomdirfile = os.path.join(self.dirpath, self.dicomdir_filename)
        ftype = 'pickle'
        # if exist dicomdir file and is in correct version, use it
        if os.path.exists(dicomdirfile):
            try:
                dcmdirplus = misc.obj_from_file(dicomdirfile, ftype)
                if dcmdirplus['version'] == __version__:
                    createdcmdir = False
                dcmdir = dcmdirplus['filesinfo']
            except:
                logger.debug('Found dicomdir.pkl with wrong version')
                pass

        if createdcmdir:
            dcmdirplus = self.create_dir()
            dcmdir = dcmdirplus['filesinfo']
            if (writedicomdirfile) and len(dcmdir) > 0:
                # obj_to_file(dcmdirplus, dicomdirfile, ftype)
                try:
                    misc.obj_to_file(dcmdirplus, dicomdirfile, ftype)
                except:
                    logger.warning('Cannot write dcmdir file')
                    traceback.print_exc()

                # bj_to_file(dcmdir, dcmdiryamlpath )

        dcmdir = dcmdirplus['filesinfo']
        return dcmdir
コード例 #32
0
ファイル: histology_analyser.py プロジェクト: vlukes/lisa
    def run(self):
        #self.preprocessing()
        app = QApplication(sys.argv)
        if not fast_debug:
            data3d_thr = self.data_to_binar()

            #self.data3d_thri = self.muxImage(
            #        self.data3d_thr2.astype(np.uint16),
            #        metadata
            #        )
            #sitk.Show(self.data3d_thri)

            #self.data3di = self.muxImage(
            #        self.data3d.astype(np.uint16),
            #        metadata
            #        )
            #sitk.Show(self.data3di)


            #app.exec_()
            data3d_skel = self.binar_to_skeleton(data3d_thr)

            print "skelet"

        # pyed = seqt.QTSeedEditor(
        #         data3d,
        #         contours=data3d_thr.astype(np.int8),
        #         seeds=data3d_skel.astype(np.int8)
        #         )
            #app.exec_()
        else:
            struct = misc.obj_from_file(filename='tmp0.pkl', filetype='pickle')
            data3d_skel = struct['sk']
            data3d_thr = struct['thr']

        self.skeleton_to_statistics(data3d_skel)
コード例 #33
0
ファイル: resection.py プロジェクト: jedocs/lisa
        win.add(vbox)

        fig = Figure()
        canvas = FigureCanvas(fig)  # a gtk.DrawingArea
        ax = fig.add_subplot(111, projection='3d')

        a = np.array([[0, 0], [10, 0], [10, 10], [0, 10]])
        p = Polygon(a, fill=True)
        ax.add_patch(p)
        art3d.pathpatch_2d_to_3d(p, z=3)

        ax.set_xlim3d(0, 20)
        ax.set_ylim3d(0, 20)
        ax.set_zlim3d(0, 20)

        vbox.pack_start(canvas)
        win.show_all()

        # Run the Gtk mainloop
        gtk.main()


if __name__ == "__main__":
    data = misc.obj_from_file("vessels.pickle", filetype='pickle')
    #ds = data['segmentation'] == data['slab']['liver']
    #pyed = sed3.sed3(data['segmentation'])
    #pyed.show()
    resection(data)

#    SectorDisplay2__()
コード例 #34
0
ファイル: gen_volume_tree.py プロジェクト: vlukes/lisa
 def importFromYaml(self, filename):
     data = misc.obj_from_file(filename=filename, filetype='yaml')
     self.data = data
コード例 #35
0
ファイル: volumetry_evaluation.py プロジェクト: vlukes/lisa
def eval_all_from_dataset_metadata(inputdata, visualization=False):
    """
    set metadata
    """
    evaluation_all = {
        'file1': [],
        'file2': [],
        'volume1_mm3': [],
        'volume2_mm3': [],
        'err1_mm3': [],
        'err2_mm3': [],
        'err1_percent': [],
        'err2_percent': [],
        'voe': [],
        'vd': [],
        'avgd': [],
        'rmsd': [],
        'processing_time': [],
        'organ_interactivity_counter': [],
        'maxd': []

    }
    for i in range(0, len(inputdata['data'])):

        reader = datareader.DataReader()
        data3d_a_path = os.path.join(inputdata['basedir'],
                                     inputdata['data'][i]['sliverseg'])
        data3d_a, metadata_a = reader.Get3DData(data3d_a_path)
        print "inputdata ", inputdata['data'][i].keys()
        try:
# if there is defined overlay
            data3d_a = reader.GetOverlay()[inputdata['data'][i][
                'overlay_number']]
            logger.info('overlay loaded')
            print 'overlay loaded'
        except:
            logger.debug("overlay not loaded")
            pass

        logger.debug('data A shape ' + str(data3d_a.shape))

        data3d_b_path = os.path.join(inputdata['basedir'],
                                     inputdata['data'][i]['ourseg'])
        obj_b = misc.obj_from_file(data3d_b_path, filetype='pickle')
        #data_b, metadata_b = reader.Get3DData(data3d_b_path)

        data3d_b = qmisc.uncrop(obj_b['segmentation'],
                                obj_b['crinfo'], data3d_a.shape)

        #import pdb; pdb.set_trace()
        #data3d_a = (data3d_a > 1024).astype(np.int8)
        data3d_a = (data3d_a > 0).astype(np.int8)
        data3d_b = (data3d_b > 0).astype(np.int8)

        if visualization:
            pyed = py3DSeedEditor.py3DSeedEditor(data3d_a,  # + (4 * data3d_b)
                                                 contour=data3d_b)
            pyed.show()

        evaluation_one = compare_volumes(data3d_a, data3d_b,
                                         metadata_a['voxelsize_mm'])
        evaluation_all['file1'].append(data3d_a_path)
        evaluation_all['file2'].append(data3d_b_path)
        evaluation_all['volume1_mm3'].append(evaluation_one['volume1_mm3'])
        evaluation_all['volume2_mm3'].append(evaluation_one['volume2_mm3'])
        evaluation_all['err1_mm3'].append(evaluation_one['err1_mm3'])
        evaluation_all['err2_mm3'].append(evaluation_one['err2_mm3'])
        evaluation_all['err1_percent'].append(evaluation_one['err1_percent'])
        evaluation_all['err2_percent'].append(evaluation_one['err2_percent'])
        evaluation_all['voe'].append(evaluation_one['voe'])
        evaluation_all['vd'].append(evaluation_one['vd'])
        evaluation_all['avgd'].append(evaluation_one['avgd'])
        evaluation_all['rmsd'].append(evaluation_one['rmsd'])
        evaluation_all['maxd'].append(evaluation_one['maxd'])
        if 'processing_time' in obj_b.keys():
            #this is only for compatibility with march2014 data
            processing_time = obj_b['processing_time']
            organ_interactivity_counter = obj_b['organ_interactivity_counter']
        else:
            processing_time = obj_b['processing_information']['organ_segmentation']['processing_time']  # noqa
            organ_interactivity_counter = obj_b['processing_information']['organ_segmentation']['organ_interactivity_counter']  # noqa
        evaluation_all['processing_time'].append(processing_time)
        evaluation_all['organ_interactivity_counter'].append(
            organ_interactivity_counter)

    return evaluation_all
コード例 #36
0
ファイル: viewer3.py プロジェクト: Trineon/lisa
def main():
    '''
    Parser slouží pro zadávání vstupních parametrů přes příkazovou řádku. Je možné zadat celkem 6 parametrů.
    K čemu jednotlivé parametry slouží, se můžeme dočíst při zadání příkazu (viewer3.py --help) do příkazové řádky
    '''

    parser = argparse.ArgumentParser(description='Simple VTK Viewer')

    parser.add_argument('-pkl','--picklefile', default=None,
                      help='Zadání vstupního zdroje dat. Soubor .pkl jsou zpravidla segmentovaná data')
    parser.add_argument('-vtk','--vtkfile', default=None,
                      help='Zadání vstupního zdroje dat. Soubor .vtk je soubor vygenerovaný programem VTK')
    parser.add_argument('-mode','--mode', default='View',
                      help='Zadání resekčního, nebo zobrazovacího režimu')
    parser.add_argument('-slab','--slab', default = 'liver',
                      help='Zde zadáváme zda chceme zobrazit játra, nebo portální žílu')
    parser.add_argument('-vs','--voxelsize_mm', default = [1,1,1],
                      type=eval,
                      help='Viewer_size')
    parser.add_argument('-deg','--degradace', default = None, type=int,
                      help='Hodnota degradace (snizeni poctu dat)')

    args = parser.parse_args()

    '''
    Pokud programu nezadáme data vyhlásí chybu, že nemá data
    '''
    if (args.picklefile or args.vtkfile) is None:
       raise IOError('No input data!')

    '''
    Zde se program větví na dvě možnosti podle toho, jaký druh zdroje dat jsme zvolili
    Pokud jsme zvolili jako zdroj dat pickle soubor (segmentovaná data) vytvoří se objekt
    prohlížeče (Viewer) a předá se mu tento zdro, společně s informací zda chceme program
    spustit v resekčním, nebo prohlížecím režimu.
    '''
    if args.picklefile:
        viewer = Viewer(args.picklefile,args.mode)
        data = misc.obj_from_file(args.picklefile, filetype = 'pickle')

        '''
        Zde programu zadáme hodnotu degradace (pokud není změněna parametrem deg)
        '''
        if (args.slab == 'porta') &  (args.degradace is None):
            viewer.degrad = 2
        if (args.slab == 'liver') &  (args.degradace is None):
            viewer.degrad = 4
        if args.degradace != None:
            viewer.degrad = args.degradace

        '''
        Data jsou zmenšována degradací v každém rozměru
        '''
        viewer.data = data
        viewer.data['segmentation'] = viewer.data['segmentation'][::viewer.degrad,::viewer.degrad,::viewer.degrad]
        viewer.data['segmentation'] = viewer.data['segmentation'][:,::-1,:]
        '''
        Pokud data neobsahují portální žílu je zahlášena chyba a program dále pracuje s celými játry
        '''
        try:
            mesh = viewer.generate_mesh(viewer.data['segmentation'] == viewer.data['slab'][args.slab],viewer.data['voxelsize_mm'])
        except KeyError:
            try:
                print 'Data bohuzel neobsahuji zadany slab:', args.slab
                print 'Zobrazena budou pouze dostupna data'
                viewer.info_text.appendPlainText (_fromUtf8('Data bohužel neobsahují zadanou část jater'))
                viewer.info_text.appendPlainText (_fromUtf8('Zobrazena budou pouze dostupná data'))
                mesh = viewer.generate_mesh(viewer.data['segmentation'] == viewer.data['slab']['liver'],viewer.data['voxelsize_mm'])
                '''
                Pokud data navíc neobsahují parametr rozměr voxelu (velmi vyjímečná záležitost) jsou programu předány jednotkové
                rozměry voxelu (1,1,1)
                '''
            except KeyError:
                data['voxelsize_mm'] = np.squeeze([1,1,1])
                mesh = viewer.generate_mesh(viewer.data['segmentation'] == viewer.data['slab'][args.slab],viewer.data['voxelsize_mm'])

        '''
        Pokud je zadán mód Cut(prohlížecí režim) nejdříve zobrazíme editor, abychom mohli začít vypisovat
        informace pro uživatele
        '''
        if args.mode == 'Cut':
            viewer.show()
        viewer.View(mesh)

    '''
    Pokud je zadán jako vstupní zdroj dat soubor vtk. Je vytvořen objekt prohlížeče(Viewer) a je mu předán vstupní soubor
    společně se zvoleným módem
    '''
    if args.vtkfile:
        viewer = Viewer(args.vtkfile,args.mode)
        if args.mode == 'Cut':
            viewer.show()
        viewer.View(args.vtkfile)

    viewer.iren.Initialize()
    app.exec_()
    sys.exit(app.exec_())
コード例 #37
0
def report(eval_files,
           labels,
           markers,
           show=True,
           output_prefix='',
           use_plt=True,
           pklz_dirs=None,
           experiment_name='',
           filename_separator=''):
    """

    based on
    :eval_files: list of filenames with input data without extension. If it is
    None, based on pklz_disr the default eval_list is generated.
    :use_plt: can supress using of matplotlib
    :pklz_dirs: is used for generating eval_files if eval_files is None.
    Obsolete
    """

    # TODO image_basename  generovat obrazky
    expn = np.array(range(0, len(markers)))
    expn_labels = labels
    dp_params = {
        'markers': markers,
        'labels': labels,
        'loc': 0,
        'show': show,
        'filename': output_prefix,
        'filename_separator': filename_separator
    }
    sp_params = {
        'expn': expn,
        'expn_labels': expn_labels,
        'show': show,
        'filename': output_prefix,
        'use_plt': use_plt,
        'filename_separator': filename_separator
    }
    # return
    # yaml_files = [os.path.normpath(path) + '.yaml' for path in pklz_dirs]
    # logger.debug(str(yaml_files))

    if eval_files is None:
        if pklz_dirs is not None:
            eval_files = [
                os.path.normpath(path) + '_eval' for path in pklz_dirs
            ]
        else:
            logger.error('pklz_dirs and eval_files is None')
            raise Exception('pklz_dirs and eval_files is None')

    logger.debug(str(eval_files))
    data = [
        misc.obj_from_file(fname + '.pkl', filetype='pkl')
        for fname in eval_files
    ]

    df_all = create_data_frame(data, labels, eval_files, experiment_name)
    __df_to_csv_and_latex(df_all, output_prefix)

    if use_plt:
        logger.debug("first plot")

        dataplot(data, 'voe', 'Volume Difference Error [%]', **dp_params)
        dataplot(data, 'vd', 'Total Volume Difference [%]', **dp_params)
        dataplot(data, 'processing_time', 'Processing time [s]', **dp_params)
        dataplot(data, 'maxd', 'MaxD [mm]', **dp_params)
        dataplot(data, 'avgd', 'AvgD [mm]', **dp_params)
        dataplot(data, 'rmsd', 'RMSD [mm]', **dp_params)
        # dataplot(data, 'rmsd', 'RMSD [mm]', **dp_params)

        logger.debug("Souhrn měření")

    vd_mn, tmp = sumplot(data, 'vd', 'Total Volume Difference', **sp_params)
    voe_mn, tmp = sumplot(data, 'voe', 'Volume Difference Error', **sp_params)
    avgd_mn, tmp = sumplot(data, 'avgd', 'Average Distance', **sp_params)
    maxd_mn, tmp = sumplot(data, 'maxd', 'Maxiamal Distance', **sp_params)
    rmsd_mn, tmp = sumplot(data, 'rmsd', 'Square Distance', **sp_params)

    logger.info("\n")
    logger.info('vd   ' + str(vd_mn))
    logger.info("voe " + str(voe_mn))
    logger.info('maxd ' + str(maxd_mn))
    logger.info('avgd ' + str(avgd_mn))
    logger.info('rmsd ' + str(rmsd_mn))

    logger.info("Přepočteno na skóre")
    # print tables[0].shape
    # pandas.set_option('display.max_columns', None)
    scoreTotal, scoreMetrics, scoreAll = sliverScoreAll(data)

    tables, indexes, columns = scoreTableEvaluation(scoreMetrics)

    dataframes = __create_data_frames(tables, indexes, columns)
    __save_data_frames(dataframes, labels, output_prefix)

    # df = pandas.DataFrame(tables[0], index=indexes[0], columns=columns[0])
    # print df.to_string()

    if use_plt:
        dataplot(scoreAll, 'voe', 'Volume Difference Error [points]',
                 **dp_params)
        dataplot(scoreAll, 'vd', 'Total Volume Difference [points]',
                 **dp_params)

        dataplot(scoreAll, 'maxd', 'MaxD [points]', **dp_params)
        dataplot(scoreAll, 'avgd', 'AvgD [points]', **dp_params)
        dataplot(scoreAll, 'rmsd', 'RMSD [points]', **dp_params)
        # tohle je zoufale propletani ruznych dat
        dataplot(data, 'score_pts', 'Score [points]', **dp_params)

    vd_mn, tmp = sumplot(scoreAll, 'vd', 'Total Volume Difference',
                         **sp_params)
    voe_mn, tmp = sumplot(scoreAll, 'voe', 'Volume Difference Error',
                          **sp_params)
    avgd_mn, tmp = sumplot(scoreAll, 'avgd', 'Average Distance', **sp_params)
    maxd_mn, tmp = sumplot(scoreAll, 'maxd', 'Maxiamal Distance', **sp_params)
    rmsd_mn, tmp = sumplot(scoreAll, 'rmsd', 'Square Distance', **sp_params)

    logger.info("Overall score")

    scoreTotal, scoreMetrics, scoreAll = sliverScoreAll(data)
    logger.info('Overall score: ' + str(scoreTotal))

    if use_plt:
        plot_total(scoreMetrics,
                   labels=labels,
                   err_scale=0.05,
                   show=show,
                   filename=output_prefix)

    return df_all
コード例 #38
0
ファイル: virtual_resection.py プロジェクト: Trineon/lisa
def View(name):
    data = misc.obj_from_file("out", filetype='pickle')
    resection(data, name)
コード例 #39
0
ファイル: viewer3.py プロジェクト: mjirik/lisa
def main():
    '''
    Parser slouží pro zadávání vstupních parametrů přes příkazovou řádku. Je možné zadat celkem 6 parametrů.
    K čemu jednotlivé parametry slouží, se můžeme dočíst při zadání příkazu (viewer3.py --help) do příkazové řádky
    '''

    parser = argparse.ArgumentParser(description='Simple VTK Viewer')

    parser.add_argument(
        '-pkl',
        '--picklefile',
        default=None,
        help=
        'Zadání vstupního zdroje dat. Soubor .pkl jsou zpravidla segmentovaná data'
    )
    parser.add_argument(
        '-vtk',
        '--vtkfile',
        default=None,
        help=
        'Zadání vstupního zdroje dat. Soubor .vtk je soubor vygenerovaný programem VTK'
    )
    parser.add_argument('-mode',
                        '--mode',
                        default='View',
                        help='Zadání resekčního, nebo zobrazovacího režimu')
    parser.add_argument(
        '-slab',
        '--slab',
        default='liver',
        help='Zde zadáváme zda chceme zobrazit játra, nebo portální žílu')
    parser.add_argument('-vs',
                        '--voxelsize_mm',
                        default=[1, 1, 1],
                        type=eval,
                        help='Viewer_size')
    parser.add_argument('-deg',
                        '--degradace',
                        default=None,
                        type=int,
                        help='Hodnota degradace (snizeni poctu dat)')

    args = parser.parse_args()
    '''
    Pokud programu nezadáme data vyhlásí chybu, že nemá data
    '''
    if (args.picklefile or args.vtkfile) is None:
        raise IOError('No input data!')
    '''
    Zde se program větví na dvě možnosti podle toho, jaký druh zdroje dat jsme zvolili
    Pokud jsme zvolili jako zdroj dat pickle soubor (segmentovaná data) vytvoří se objekt
    prohlížeče (Viewer) a předá se mu tento zdro, společně s informací zda chceme program
    spustit v resekčním, nebo prohlížecím režimu.
    '''
    if args.picklefile:
        viewer = Viewer(args.picklefile, args.mode)
        data = misc.obj_from_file(args.picklefile, filetype='pickle')
        '''
        Zde programu zadáme hodnotu degradace (pokud není změněna parametrem deg)
        '''
        if (args.slab == 'porta') & (args.degradace is None):
            viewer.degrad = 2
        if (args.slab == 'liver') & (args.degradace is None):
            viewer.degrad = 4
        if args.degradace != None:
            viewer.degrad = args.degradace
        '''
        Data jsou zmenšována degradací v každém rozměru
        '''
        viewer.data = data
        viewer.data['segmentation'] = viewer.data[
            'segmentation'][::viewer.degrad, ::viewer.degrad, ::viewer.degrad]
        viewer.data['segmentation'] = viewer.data['segmentation'][:, ::-1, :]
        '''
        Pokud data neobsahují portální žílu je zahlášena chyba a program dále pracuje s celými játry
        '''
        try:
            mesh = viewer.generate_mesh(
                viewer.data['segmentation'] == viewer.data['slab'][args.slab],
                viewer.data['voxelsize_mm'])
        except KeyError:
            try:
                print('Data bohuzel neobsahuji zadany slab:', args.slab)
                print('Zobrazena budou pouze dostupna data')
                viewer.info_text.appendPlainText(
                    'Data bohužel neobsahují zadanou část jater')
                viewer.info_text.appendPlainText(
                    'Zobrazena budou pouze dostupná data')
                mesh = viewer.generate_mesh(
                    viewer.data['segmentation'] == viewer.data['slab']
                    ['liver'], viewer.data['voxelsize_mm'])
                '''
                Pokud data navíc neobsahují parametr rozměr voxelu (velmi vyjímečná záležitost) jsou programu předány jednotkové
                rozměry voxelu (1,1,1)
                '''
            except KeyError:
                data['voxelsize_mm'] = np.squeeze([1, 1, 1])
                mesh = viewer.generate_mesh(
                    viewer.data['segmentation'] == viewer.data['slab'][
                        args.slab], viewer.data['voxelsize_mm'])
        '''
        Pokud je zadán mód Cut(prohlížecí režim) nejdříve zobrazíme editor, abychom mohli začít vypisovat
        informace pro uživatele
        '''
        if args.mode == 'Cut':
            viewer.show()
        viewer.View(mesh)
    '''
    Pokud je zadán jako vstupní zdroj dat soubor vtk. Je vytvořen objekt prohlížeče(Viewer) a je mu předán vstupní soubor
    společně se zvoleným módem
    '''
    if args.vtkfile:
        viewer = Viewer(args.vtkfile, args.mode)
        if args.mode == 'Cut':
            viewer.show()
        viewer.View(args.vtkfile)

    viewer.iren.Initialize()
    app.exec_()
    sys.exit(app.exec_())
コード例 #40
0
ファイル: histology_analyser.py プロジェクト: Trineon/lisa
def processData(args):
    """
    Processing data without gui
    """
    inputfile=args.inputfile
    threshold=args.threshold
    mask_file=args.maskfile
    crop=args.crop
    voxelsize=args.voxelsize
    binaryClosing=args.binaryopening
    binaryOpening=args.binaryclosing
    
    # Reading/Generating data
    if inputfile is None:  # # Using generated sample data
        logger.info('Generating sample data...')
        metadata = {'voxelsize_mm': [1, 1, 1]}
        data3d = generate_sample_data(1, 0, 0)
    else:  # Normal runtime
        dr = datareader.DataReader()
        data3d, metadata = dr.Get3DData(inputfile)

    # Custom voxel size
    if voxelsize is not None:
        metadata['voxelsize_mm'] = voxelsize

    # Crop data
    if crop is not None:
        logger.debug('Croping data: %s', str(crop))
        data3d = data3d[crop[0]:crop[1], crop[2]:crop[3], crop[4]:crop[5]].copy()

    # Init HistologyAnalyser object
    logger.debug('Init HistologyAnalyser object')
    ha = HistologyAnalyser(data3d, metadata, threshold, 
             binaryClosing=binaryClosing, binaryOpening=binaryOpening, 
             nogui=True)

    # Remove Area = Load mask from file
    if mask_file is not None:
        logger.debug('Loading mask from file...')
        mask = misc.obj_from_file(filename=mask_file, filetype='pickle')
        if ha.data3d.shape == mask.shape:
            ha.data3d_masked = mask
            ha.data3d[mask == 0] = np.min(ha.data3d)
        else:
            raise ValueError('Mask file has wrong dimensions '+str(mask.shape))
    
    # Segmentation
    logger.debug('Segmentation')
    ha.data_to_skeleton()

    # Computing statistics
    logger.info("# ## ## ## ## statistics")
    ha.data_to_statistics()

    # Saving files
    logger.info("# ## ## write stats to file")
    ha.writeStatsToCSV()
    ha.writeStatsToYAML()
    
    # ## Histology report
    logger.info("# ## ## Histology report")
    hr = HistologyReport()
    hr.data = ha.stats
    hr.generateStats()
    hr.writeReportToCSV()
    hr.writeReportToYAML()
    
    # Add results Record
    if crop is not None:
        label = str(crop[0])+"-"+str(crop[1])
    else:
        label = "0-end"
    if inputfile is None:
        hr.addResultsRecord(label=label)
    else:
        hr.addResultsRecord(label=label, datapath=inputfile)

    # ## End
    logger.info('Finished')
コード例 #41
0
def View(name):
    data = misc.obj_from_file("out", filetype='pickle')
    resection(data, name)
コード例 #42
0
    if args.inputfile == None:
        oseg = organ_segmentation.OrganSegmentation(
            args.dcmdir,
            working_voxelsize_mm=6,
            autocrop=True,
            autocrop_margin_mm=[10, 10, 10])
        oseg.interactivity()
        # Uvolneni pameti
        garbage.collect()
        print("Volume " +
              str(oseg.get_segmented_volume_size_mm3() / 1000000.0) + ' [l]')
        # get data in list
        data = oseg.export()
    else:
        data = misc.obj_from_file(args.inputfile, filetype='pickle')

    import sed3
    # pyed = sed3.sed3(oseg.orig_scale_segmentation)
    #pyed.show()
    # information about crop
    #cri = oseg.crinfo
    #oseg.data3d = oseg.data3d[cri[0][0]:cri[0][1],cri[1][0]:cri[1][1],cri[2][0]:cri[2][1]]
    #pyed = sed3.sed3(oseg.data3d, contour = oseg.orig_scale_segmentation)

    print('slab', data['slab'])
    #import ipdb; ipdb.set_trace()  # BREAKPOINT
    #pyed = sed3.sed3(data['data3d'], contour = data['segmentation'])
    #pyed.show()
    #import pdb; pdb.set_trace()
コード例 #43
0
def processIt(pklz_dirs, sliver_dir, yaml_files, eval_files, markers, labels):
    import misc
    """
    Funkce vypíše report o celém experimentu.
    """
    data = [
        misc.obj_from_file(fname + '.pkl', filetype='pkl')
        for fname in eval_files
    ]

    print "Jednotlivá měření"
    dataplot(data,
             'voe',
             'Volume Difference Error [%]',
             markers=markers,
             labels=labels,
             loc=0)
    dataplot(data,
             'vd',
             'Total Volume Difference [%]',
             markers=markers,
             labels=labels,
             loc=0)

    dataplot(data,
             'processing_time',
             'Processing time [s]',
             markers=markers,
             labels=labels,
             loc=0)

    dataplot(data, 'maxd', 'MaxD [mm]', markers=markers, labels=labels, loc=0)
    dataplot(data, 'avgd', 'AvgD [mm]', markers=markers, labels=labels, loc=0)
    dataplot(data, 'rmsd', 'RMSD [mm]', markers=markers, labels=labels, loc=0)

    print "Souhrn měření"

    # import "experiment_support.ipynb"

    expn = np.array(range(0, len(labels)))
    expn_labels = labels

    print expn_labels
    print expn

    vd_mn, tmp = sumplot(data, 'vd', 'Total Volume Difference', expn,
                         expn_labels)
    voe_mn, tmp = sumplot(data, 'voe', 'Volume Difference Error', expn,
                          expn_labels)

    avgd_mn, tmp = sumplot(data, 'avgd', 'Average Distance', expn, expn_labels)
    maxd_mn, tmp = sumplot(data, 'maxd', 'Maxiamal Distance', expn,
                           expn_labels)
    rmsd_mn, tmp = sumplot(data, 'rmsd', 'Square Distance', expn, expn_labels)

    print 'vd   ', vd_mn
    print "voe ", voe_mn
    print 'maxd ', maxd_mn
    print 'avgd ', avgd_mn
    print 'rmsd ', rmsd_mn

    print "Přepočteno na skóre"

    import pandas
    # print tables[0].shape
    # pandas.set_option('display.max_columns', None)
    scoreTotal, scoreMetrics, scoreAll = sliverScoreAll(data)

    tables, indexes, columns = scoreTableEvaluation(scoreMetrics)

    df = pandas.DataFrame(tables[0], index=indexes[0], columns=columns[0])
    print df.to_string()
    dataplot(scoreAll,
             'voe',
             'Volume Difference Error [points]',
             markers=markers,
             labels=labels,
             loc=0)
    dataplot(scoreAll,
             'vd',
             'Total Volume Difference [points]',
             markers=markers,
             labels=labels,
             loc=0)

    dataplot(scoreAll,
             'maxd',
             'MaxD [mm]',
             markers=markers,
             labels=labels,
             loc=0)
    dataplot(scoreAll,
             'avgd',
             'AvgD [mm]',
             markers=markers,
             labels=labels,
             loc=0)
    dataplot(scoreAll,
             'rmsd',
             'RMSD [mm]',
             markers=markers,
             labels=labels,
             loc=0)

    vd_mn, tmp = sumplot(scoreAll, 'vd', 'Total Volume Difference', expn,
                         expn_labels)
    voe_mn, tmp = sumplot(scoreAll, 'voe', 'Volume Difference Error', expn,
                          expn_labels)
    avgd_mn, tmp = sumplot(scoreAll, 'avgd', 'Average Distance', expn,
                           expn_labels)
    maxd_mn, tmp = sumplot(scoreAll, 'maxd', 'Maxiamal Distance', expn,
                           expn_labels)
    rmsd_mn, tmp = sumplot(scoreAll, 'rmsd', 'Square Distance', expn,
                           expn_labels)

    # scoreTotal, scoreMetrics, scoreAll =
    # volumetry_evaluation.sliverScoreAll(data)
    scoreTotal, scoreMetrics, scoreAll = sliverScoreAll(data)
    print 'Score total: ', scoreTotal

    plot_total(scoreMetrics, labels=labels, err_scale=0.05)
    return df
コード例 #44
0
ファイル: liver_surgery.py プロジェクト: Jhilbertxtu/lisa
def main():

    #logger = logging.getLogger(__name__)
    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    # input parser
    parser = argparse.ArgumentParser(
        description='Segment vessels from liver \n\
                    \npython organ_segmentation.py\n\
                    \npython organ_segmentation.py -mroi -vs 0.6')
    parser.add_argument('-dd',
                        '--dcmdir',
                        default=None,
                        help='path to data dir')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='run in debug mode')
    parser.add_argument('-vs',
                        '--voxelsize_mm',
                        default='3',
                        type=str,
                        help='Insert working voxelsize. It can be number or \
            array of three numbers. \n \
            -vs 3 \n \
            -vs [3,3,5]')
    parser.add_argument('-mroi',
                        '--manualroi',
                        action='store_true',
                        help='manual crop before data processing')
    parser.add_argument(
        '-iparams',
        '--iparams',
        default=None,
        help='filename of ipars file with stored interactivity')
    parser.add_argument('-t',
                        '--tests',
                        action='store_true',
                        help='run unittest')
    parser.add_argument('-tx',
                        '--textureanalysis',
                        action='store_true',
                        help='run with texture analysis')
    parser.add_argument('-exd',
                        '--exampledata',
                        action='store_true',
                        help='run unittest')
    parser.add_argument('-ed',
                        '--editdata',
                        action='store_true',
                        help='Run data editor')
    parser.add_argument('-so',
                        '--show_output',
                        action='store_true',
                        help='Show output data in viewer')
    parser.add_argument('-ss',
                        '--segmentation_smoothing',
                        action='store_true',
                        help='Smoothing of output segmentation',
                        default=False)
    args = parser.parse_args()

    # voxelsize_mm can be number or array
    args.voxelsize_mm = np.array(eval(args.voxelsize_mm))

    if args.debug:
        logger.setLevel(logging.DEBUG)

    if args.tests:
        # hack for use argparse and unittest in one module
        sys.argv[1:] = []
        unittest.main()
        sys.exit()

    if args.exampledata:

        args.dcmdir = '../sample_data/\
                matlab/examples/sample_data/DICOM/digest_article/'

    if args.iparams is not None:
        args.iparams = misc.obj_from_file(args.iparams)
    #else:
    #dcm_read_from_dir('/home/mjirik/data/medical/data_orig/46328096/')
    #data3d, metadata = dcmreaddata.dcm_read_from_dir()

    oseg = OrganSegmentation(args.dcmdir,
                             working_voxelsize_mm=args.voxelsize_mm,
                             manualroi=args.manualroi,
                             texture_analysis=args.textureanalysis,
                             edit_data=args.editdata,
                             smoothing=args.action_segmentation_smoothing,
                             iparams=args.iparams)

    oseg.interactivity()

    #igc = pycut.ImageGraphCut(data3d, zoom = 0.5)
    #igc.interactivity()

    #igc.make_gc()
    #igc.show_segmentation()

    # volume
    #volume_mm3 = np.sum(oseg.segmentation > 0) * np.prod(oseg.voxelsize_mm)

    print("Volume " + str(oseg.get_segmented_volume_size_mm3() / 1000000.0) +
          ' [l]')
    #pyed = sed3.sed3(oseg.data3d, contour =
    # oseg.segmentation)
    #pyed.show()

    if args.show_output:
        oseg.show_output()

    savestring = raw_input('Save output data? (y/n): ')
    #sn = int(snstring)
    if savestring in ['Y', 'y']:

        data = oseg.export()

        misc.obj_to_file(data, "organ.pkl", filetype='pickle')
        misc.obj_to_file(oseg.get_ipars(), 'ipars.pkl', filetype='pickle')
    #output = segmentation.vesselSegmentation(oseg.data3d,
    # oseg.orig_segmentation)

    def checkSegData(self):
        if self.segmentation_data is None:
            self.statusBar().showMessage('No SEG data!')
            return
        nzs = self.segmentation_data.nonzero()
        nn = nzs[0].shape[0]
        if nn > 0:
            aux = ' voxels = %d, volume = %.2e mm3' % (nn,
                                                       nn * self.voxel_volume)
            self.setLabelText(self.text_seg_data, aux)
            self.setLabelText(self.text_mesh_in, 'segmentation data')
            self.statusBar().showMessage('Ready')

        else:
            self.statusBar().showMessage('Zero SEG data!')

    def autoSeg(self):
        if self.dcm_3Ddata is None:
            self.statusBar().showMessage('No DICOM data!')
            return
        igc = pycut.ImageGraphCut(self.dcm_3Ddata,
                                  voxelsize=self.voxel_size_mm)

        pyed = QTSeedEditor(self.dcm_3Ddata,
                            seeds=self.segmentation_seeds,
                            modeFun=igc.interactivity_loop,
                            voxelVolume=self.voxel_volume)
        pyed.exec_()

        self.segmentation_data = pyed.getContours()
        self.segmentation_seeds = pyed.getSeeds()
        self.checkSegData()
コード例 #45
0
ファイル: organ_segmentation.py プロジェクト: vlukes/lisa
def main():

    #logger = logging.getLogger(__name__)
    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    print 'version: ', qmisc.getVersionString()
###
# Configuration is has three sources:
#  * Default function values
#  * Config file 'organ_segmentation.config' in directory with application
#  * Config file 'organ_segmentation.config' in output data directory
#
# It is read in this order so the last one has highest priority

###
## read confguraton from file, use default values from OrganSegmentation
    cfgplus = {
        'datapath': None,
        'viewermax': 300,
        'viewermin': -100,
        'output_datapath': os.path.expanduser("~/lisa_data"),
        'lisa_operator_identifier': "",
        'experiment_caption': ''
    }

    cfg = config.get_default_function_config(OrganSegmentation.__init__)
    cfg.update(cfgplus)
    # now is in cfg default values

    cfg = config.get_config("organ_segmentation.config", cfg)
# read user defined config in user data
    cfg = config.get_config(
        os.path.join(cfg['output_datapath'], "organ_segmentation.config"),
        cfg
    )

    # input parser
    parser = argparse.ArgumentParser(
        description='Segment vessels from liver \n\
                \npython organ_segmentation.py\n\
                \npython organ_segmentation.py -mroi -vs 0.6')
    parser.add_argument('-dd', '--datapath',
                        default=cfg["datapath"],
                        help='path to data dir')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='run in debug mode')
    parser.add_argument(
        '-vs', '--working_voxelsize_mm',
        default=cfg["working_voxelsize_mm"],
        type=eval,  # type=str,
        help='Insert working voxelsize. It can be number or \
        array of three numbers. It is possible use original \n \
        resolution or half of original resolution. \n \
        -vs 3 \n \
        -vs [3,3,5] \n \
        -vs orig \n \
        -vs orig*2 \n \
        -vs orig*4 \n \
        '
    )
    parser.add_argument('-mroi', '--manualroi', action='store_true',
                        help='manual crop before data processing',
                        default=cfg["manualroi"])

    parser.add_argument('-op', '--output_datapath',
                        default=cfg["output_datapath"],
                        help='path for output data')

    parser.add_argument('-ol', '--output_label', default=1,
                        help='label for segmented data')
    parser.add_argument(
        '--slab',
        default=cfg["slab"],
        type=eval,
        help='labels for segmentation,\
            example -slab "{\'liver\':1, \'lesions\':6}"')
    parser.add_argument(
        '-acr', '--autocrop',
        help='automatic crop after data processing',
        default=cfg["autocrop"])
    parser.add_argument(
        '-iparams', '--iparams',
        default=None,
        help='filename of ipars file with stored interactivity')
    parser.add_argument(
        '-sp', '--segparams', type=eval,
        default=cfg["segparams"],
        help='params for segmentation,\
            example -sp "{\'pairwise_alpha_per_mm2\':90}"')
    parser.add_argument(
        '-tx', '--texture_analysis', action='store_true',
        help='run with texture analysis')
    parser.add_argument('-exd', '--exampledata', action='store_true',
                        help='run unittest')
    parser.add_argument('-ed', '--edit_data', action='store_true',
                        help='Run data editor')
    parser.add_argument(
        '-vmax', '--viewermax', type=eval,  # type=int,
        help='Maximum of viewer window, set None for automatic maximum.',
        default=cfg["viewermax"])
    parser.add_argument(
        '-vmin', '--viewermin', type=eval,  # type=int,
        help='Minimum of viewer window, set None for automatic minimum.',
        default=cfg["viewermin"])
    parser.add_argument(
        '-so', '--show_output', action='store_true',
        help='Show output data in viewer')
    parser.add_argument('-a', '--arg', nargs='+', type=float)
    parser.add_argument(
        '-ec', '--experiment_caption', type=str,  # type=int,
        help='Short caption of experiment. No special characters.',
        default=cfg["experiment_caption"])
    parser.add_argument(
        '-oi', '--lisa_operator_identifier', type=str,  # type=int,
        help='Identifier of Lisa operator.',
        default=cfg["experiment_caption"])
    parser.add_argument(
        '-ss',
        '--segmentation_smoothing',
        action='store_true',
        help='Smoothing of output segmentation',
        default=cfg["segmentation_smoothing"]
    )
    args_obj = parser.parse_args()
    args = vars(args_obj)
    #print args["arg"]
    oseg_argspec_keys = config.get_function_keys(OrganSegmentation.__init__)

    # voxelsize_mm can be number or array
    #if args.voxelsize_mm != 'orig':
#TODO easy way to set half of resolution
#    if isinstance(args["working_voxelsize_mm"], numbers.Number)
#        if args["working_voxelsize_mm"] == -1:
#            args["working_voxelsize_mm"] = 'orig'
## todo and so on
#    if not args["working_voxelsize_mm"].startswith('orig'):
#        #import pdb; pdb.set_trace()
#        args["working_voxelsize_mm"] = eval(args["working_voxelsize_mm"])

    #
    #args["segparams"] = eval(args["segparams"])
    #args["slab"] = eval(args["slab"])

    #args["viewermin"] = eval(args["viewermin"])
    #args["viewermax"] = eval(args["viewermax"])

    if args["debug"]:
        logger.setLevel(logging.DEBUG)

    if args["exampledata"]:

        args["datapath"] = '../sample_data/\
                matlab/examples/sample_data/DICOM/digest_article/'

    if args["iparams"] is not None:
        iparams = misc.obj_from_file(args["iparams"], filetype='pickle')
        oseg = OrganSegmentation(**iparams)

    else:
    #else:
    #dcm_read_from_dir('/home/mjirik/data/medical/data_orig/46328096/')
        #data3d, metadata = dcmreaddata.dcm_read_from_dir()
        data3d, metadata, qt_app = readData3d(args["datapath"])
        args['datapath'] = metadata['datadir']

        oseg_params = config.subdict(args, oseg_argspec_keys)
        oseg_params["data3d"] = data3d
        oseg_params["metadata"] = metadata
        oseg_params['qt_app'] = qt_app
        oseg = OrganSegmentation(**oseg_params)

    oseg.interactivity(args["viewermin"], args["viewermax"])

    #igc = pycut.ImageGraphCut(data3d, zoom = 0.5)
    #igc.interactivity()

    #igc.make_gc()
    #igc.show_segmentation()
    # volume
    #volume_mm3 = np.sum(oseg.segmentation > 0) * np.prod(oseg.voxelsize_mm)

    audiosupport.beep()
    print(
        "Volume " +
        str(oseg.get_segmented_volume_size_mm3() / 1000000.0) + ' [l]')
    #pyed = py3DSeedEditor.py3DSeedEditor(oseg.data3d, contour =
    # oseg.segmentation)
    #pyed.show()
    print("Total time: " + str(oseg.processing_time))

    if args["show_output"]:
        oseg.show_output()

    #print savestring
    save_outputs(args, oseg, qt_app)
#    import pdb; pdb.set_trace()
    return
コード例 #46
0
ファイル: show_segmentation.py プロジェクト: Trineon/lisa
    # input parser
    parser = argparse.ArgumentParser(
        description='\
            3D visualization of segmentation\n\
            \npython show_segmentation.py\n\
            \npython show_segmentation.py -i resection.pkl -l 2 3 4 -d 4')
    parser.add_argument(
        '-i', '--inputfile',
        default='organ.pkl',
        help='input file')
    parser.add_argument(
        '-d', '--degrad', type=int,
        default=4,
        help='data degradation, default 4')
    parser.add_argument(
        '-l', '--label', type=int, metavar='N', nargs='+',
        default=[1],
        help='segmentation labels, default 1')
    args = parser.parse_args()

    data = misc.obj_from_file(args.inputfile, filetype='pickle')
    # args.label = np.array(eval(args.label))
    # print args.label
    # import pdb; pdb.set_trace()
    ds = np.zeros(data['segmentation'].shape, np.bool)
    for i in range(0, len(args.label)):
        ds = ds | (data['segmentation'] == args.label[i])

    showSegmentation(ds, degrad=args.degrad)
コード例 #47
0
ファイル: volumetry_evaluation.py プロジェクト: kunesj/lisa
def eval_all_from_dataset_metadata(inputdata, visualization=False,
                                   special_evaluation_function=None):
    """
    set metadata
    """
    evaluation_all = {
        'file1': [],
        'file2': [],
        'volume1_mm3': [],
        'volume2_mm3': [],
        'err1_mm3': [],
        'err2_mm3': [],
        'err1_percent': [],
        'err2_percent': [],
        'voe': [],
        'vd': [],
        'avgd': [],
        'rmsd': [],
        'processing_time': [],
        'organ_interactivity_counter': [],
        'maxd': []

    }
    for i in range(0, len(inputdata['data'])):

        reader = datareader.DataReader()
        data3d_a_path = os.path.join(inputdata['basedir'],
                                     inputdata['data'][i]['sliverseg'])
        data3d_a, metadata_a = reader.Get3DData(data3d_a_path)
        print "inputdata ", inputdata['data'][i].values()
        try:
            # if there is defined overlay
            data3d_a = reader.GetOverlay()[inputdata['data'][i][
                'overlay_number']]
            logger.info('overlay loaded')
            print 'overlay loaded'
        except:
            logger.debug("overlay not loaded")
            pass

        logger.debug('data A shape ' + str(data3d_a.shape))

        data3d_b_path = os.path.join(inputdata['basedir'],
                                     inputdata['data'][i]['ourseg'])
        obj_b = misc.obj_from_file(data3d_b_path, filetype='pickle')
        # data_b, metadata_b = reader.Get3DData(data3d_b_path)

        if 'crinfo' in obj_b.keys():
            data3d_b = qmisc.uncrop(obj_b['segmentation'],
                                    obj_b['crinfo'], data3d_a.shape)
        else:
            data3d_b = obj_b['segmentation']

        # import pdb; pdb.set_trace()
        # data3d_a = (data3d_a > 1024).astype(np.int8)
        data3d_a = (data3d_a > 0).astype(np.int8)
        data3d_b = (data3d_b > 0).astype(np.int8)

        if visualization:
            pyed = sed3.sed3(data3d_a,  # + (4 * data3d_b)
                             contour=data3d_b)
            pyed.show()

        evaluation_one = compare_volumes(data3d_a, data3d_b,
                                         metadata_a['voxelsize_mm'])
        if special_evaluation_function is not None:
            evaluation_one.update(
                special_evaluation_function(
                    data3d_a, data3d_b, metadata_a['voxelsize_mm']
                ))
        evaluation_all['file1'].append(data3d_a_path)
        evaluation_all['file2'].append(data3d_b_path)
        for key in evaluation_one.keys():
            if key not in evaluation_all.keys():
                evaluation_all[key] = []

            evaluation_all[key].append(evaluation_one[key])
        # evaluation_all['volume1_mm3'].append(evaluation_one['volume1_mm3'])
        # evaluation_all['volume2_mm3'].append(evaluation_one['volume2_mm3'])
        # evaluation_all['err1_mm3'].append(evaluation_one['err1_mm3'])
        # evaluation_all['err2_mm3'].append(evaluation_one['err2_mm3'])
        # evaluation_all['err1_percent'].append(evaluation_one['err1_percent'])
        # evaluation_all['err2_percent'].append(evaluation_one['err2_percent'])
        # evaluation_all['voe'].append(evaluation_one['voe'])
        # evaluation_all['vd'].append(evaluation_one['vd'])
        # evaluation_all['avgd'].append(evaluation_one['avgd'])
        # evaluation_all['rmsd'].append(evaluation_one['rmsd'])
        # evaluation_all['maxd'].append(evaluation_one['maxd'])
        if 'processing_time' in obj_b.keys():
            # this is only for compatibility with march2014 data
            processing_time = obj_b['processing_time']
            organ_interactivity_counter = obj_b['organ_interactivity_counter']
        else:
            try:
                processing_time = obj_b['processing_information']['organ_segmentation']['processing_time']  # noqa
                organ_interactivity_counter = obj_b['processing_information']['organ_segmentation'][
                    'organ_interactivity_counter']  # noqa
            except:
                processing_time = 0
                organ_interactivity_counter = 0
        evaluation_all['processing_time'].append(processing_time)
        evaluation_all['organ_interactivity_counter'].append(
            organ_interactivity_counter)

    return evaluation_all
コード例 #48
0
ファイル: resection.py プロジェクト: Trineon/lisa
        win.add(vbox)

        fig = Figure()
        canvas = FigureCanvas(fig)  # a gtk.DrawingArea
        ax = fig.add_subplot(111, projection='3d')

        a = np.array([[0,0],[10,0],[10,10],[0,10]])
        p = Polygon(a,fill=True)
        ax.add_patch(p)
        art3d.pathpatch_2d_to_3d(p, z=3)

        ax.set_xlim3d(0, 20)
        ax.set_ylim3d(0, 20)
        ax.set_zlim3d(0, 20)

        vbox.pack_start(canvas)
        win.show_all()

# Run the Gtk mainloop
        gtk.main()

if __name__ == "__main__":
    data = misc.obj_from_file("vessels.pickle", filetype = 'pickle')
    #ds = data['segmentation'] == data['slab']['liver']
    #pyed = sed3.sed3(data['segmentation'])
    #pyed.show()
    resection(data)

#    SectorDisplay2__()