Ejemplo n.º 1
0
def prepared_texture_features_by_string(names):
    """
    There are two possible feature_fcn formats
     * method
     * object with method 'features' and attribute 'description'
    """
    gf = tfeat.GaborFeatures()  # noqa
    glcmf = tfeat.GlcmFeatures()  # noqa
    haralick = tfeat.HaralickFeatures()  # noqa
    hist_gf = tfeat.FeaturesCombinedFeatures(feat_hist, gf.feats_gabor)
    hist_glcm = tfeat.FeaturesCombinedFeatures(feat_hist, glcmf.feats_glcm)
    hist_glcm_gf = tfeat.FeaturesCombinedFeatures(feat_hist, glcmf.feats_glcm,
                                                  gf.feats_gabor)

    dict_of_feature_fcn = {
        'hist': [feat_hist, []],
        'gf': [gf.feats_gabor, []],
        'glcm': [glcmf.feats_glcm, []],
        'haralick': [haralick.feats_haralick, [True]],
        'hist_gf': [hist_gf, []],
        'hist_glcm': [hist_glcm, []],
        'hist_glcm_gf': [hist_glcm_gf, []],
    }

    selected_classifiers = [dict_of_feature_fcn[name] for name in names]
    return selected_classifiers
Ejemplo n.º 2
0
def main():

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

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

    # logger.debug('input params')

    parser = argparse.ArgumentParser(
        description='Compute features on liver and other tissue.')
    parser.add_argument('-tr',
                        '--training_yaml_path',
                        help='Input yaml file.' +
                        " You can check sample with -si parameter.",
                        default="20130919_liver_statistics.yaml")
    parser.add_argument('-te',
                        '--testing_yaml_path',
                        help='Input yaml file.' +
                        " You can check sample with -si parameter.",
                        default=None)
    parser.add_argument('-si',
                        '--sampleInput',
                        action='store_true',
                        help='generate sample intput data',
                        default=False)
    parser.add_argument('-v',
                        '--visualization',
                        action='store_true',
                        help='Turn on visualization',
                        default=False)
    parser.add_argument('-fc',
                        '--features_classifs',
                        action='store_true',
                        help='Read features and classifs list from file',
                        default=False)
    parser.add_argument('-o',
                        '--output',
                        help='output file',
                        default="20130919_liver_statistics_results.pkl")
    parser.add_argument('-t',
                        '--train',
                        help='Training',
                        default=False,
                        action='store_true')
    parser.add_argument(
        '-cl',
        '--classifers',
        help='classifer by string: "SVC", or "GaussianNB", ...',
        nargs='+',
        type=str,
        default=['SVC'])
    parser.add_argument('-fe',
                        '--features',
                        help='features by string: "hist", or "glcm", ...',
                        nargs='+',
                        type=str,
                        default=['hist'])
    args = parser.parse_args()

    if args.sampleInput:
        sample_input_data()
    # input parser
    # path_to_yaml = os.path.join(path_to_script, args.input)
    # training_yaml_path = args.training_yaml_path
    # testing_yaml_path = args.testing_yaml_path
    if args.testing_yaml_path is None:
        print('testing is same as training')
        args.testing_yaml_path = args.training_yaml_path

    # write_csv(fvall)
    gf = tfeat.GaborFeatures()  # noqa
    glcmf = tfeat.GlcmFeatures()  # noqa
    haralick = tfeat.HaralickFeatures()  # noqa

    list_of_feature_fcn = prepared_texture_features_by_string(args.features)

    list_of_classifiers = prepared_classifiers_by_string(args.classifers)
    tile_shape = [10, 50, 50]

    if args.features_classifs:
        import features_classifs
        featrs_plus_classifs = features_classifs.fc
    else:
        featrs_plus_classifs = make_product_list(list_of_feature_fcn,
                                                 list_of_classifiers)

    result = experiment(args.training_yaml_path,
                        args.testing_yaml_path,
                        featrs_plus_classifs,
                        tile_shape=tile_shape,
                        use_voxelsize_norm=True,
                        working_voxelsize_mm=[1, 1, 1],
                        visualization=args.visualization,
                        train=args.train)

    # Ukládání výsledku do souboru
    output_file = os.path.join(path_to_script, args.output)
    misc.obj_to_file(result, output_file, filetype='pickle')