示例#1
0
def test_lbp_names():
    f = np.random.random(size=(64, 72))
    f *= 255
    f = f.astype(np.uint8)

    for radius, points in [(8, 6), (8, 8), (6, 6), (8, 4), (12, 6)]:
        assert len(lbp(f, radius, points)) == len(lbp_names(radius, points))
示例#2
0
def test_lbp_names():
    f = np.random.random(size=(64,72))
    f *= 255
    f = f.astype(np.uint8)

    for radius,points in [(8,6),
            (8,8),(6,6),(8,4),(12,6)]:
        assert len(lbp(f, radius, points)) == len(lbp_names(radius, points))
示例#3
0
def main():
    sys.stderr.write(mh.citation(print_out=False, short=True))
    sys.stderr.write('\n\n')
    parser = argparse.ArgumentParser(
        description='Compute features using mahotas')
    parser.add_argument('fnames',
                        metavar='input_file_name',
                        nargs='+',
                        type=str,
                        help='Image files names')
    parser.add_argument('--output',
                        default='features.tsv',
                        type=str,
                        help='Output file for feature files')
    parser.add_argument('--clobber',
                        default=False,
                        action='store_true',
                        help='Overwrite output file (if it exists)')
    parser.add_argument(
        '--convert-to-bw',
        default='no',
        help=
        'Convert color images to greyscale.\nAcceptable values:\n\tno: raises an error (default)'
        + '\n\tmax: use max projection' + '\n\tyes: use rgb2gray')
    parser.add_argument(
        '--no-color',
        default=False,
        action='store_true',
        help='Do not print in color (for error and warning messages)')
    parser.add_argument('--haralick',
                        default=False,
                        action='store_true',
                        help='Compute Haralick features')
    parser.add_argument('--lbp',
                        default=False,
                        action='store_true',
                        help='Compute LBP (linear binary patterns) features')
    parser.add_argument('--lbp-radius',
                        default=8,
                        action='store',
                        type=int,
                        help='Radius to use for LBP features')
    parser.add_argument('--lbp-points',
                        default=6,
                        action='store',
                        type=int,
                        help='Nr of points to use for LBP features')
    args = parser.parse_args()
    if not (args.haralick or args.lbp):
        sys.stderr.write('''\
No features selected. Doing nothing.

For example, use --haralick switch to compute Haralick features\n''')
        sys.exit(1)

    if not args.clobber and path.exists(args.output):
        print_error(
            'Output file ({}) already exists. Refusing to overwrite results without --clobber argument.'
            .format(args.output))
        sys.exit(2)

    output = open(args.output, 'w')
    colnames = []
    if args.haralick:
        hlabels = mh.features.texture.haralick_labels[:-1]
        colnames.extend(["mean:{}".format(ell) for ell in hlabels])
        colnames.extend(["ptp:{}".format(ell) for ell in hlabels])
    if args.lbp:
        from mahotas.features.lbp import lbp_names
        colnames.extend(lbp_names(args.lbp_radius, args.lbp_points))
    _write_row(output, colnames)

    for fname in args.fnames:
        cur = []
        im = read_bw(fname, args)
        if args.haralick:
            har = mh.features.haralick(im, return_mean_ptp=True)
            cur.append(har)
        if args.lbp:
            cur.append(mh.features.lbp(im, args.lbp_radius, args.lbp_points))

        _write_row(output, chain.from_iterable(cur), fname)
    output.close()
示例#4
0
def main():
    sys.stderr.write(mh.citation(print_out=False, short=True))
    sys.stderr.write('\n\n')
    parser = argparse.ArgumentParser(
            description='Compute features using mahotas')
    parser.add_argument(
                    'fnames', metavar='input_file_name', nargs='+', type=str,
                            help='Image files names')
    parser.add_argument(
                    '--output', default='features.tsv', type=str,
                            help='Output file for feature files')
    parser.add_argument(
                    '--clobber', default=False, action='store_true',
                            help='Overwrite output file (if it exists)')
    parser.add_argument(
                    '--convert-to-bw', default='no',
                    help='Convert color images to greyscale.\nAcceptable values:\n\tno: raises an error (default)' +
                        '\n\tmax: use max projection' +
                        '\n\tyes: use rgb2gray')
    parser.add_argument(
                    '--no-color', default=False, action='store_true',
                            help='Do not print in color (for error and warning messages)')
    parser.add_argument(
                    '--haralick', default=False, action='store_true',
                            help='Compute Haralick features')
    parser.add_argument(
                    '--lbp', default=False, action='store_true',
                            help='Compute LBP (linear binary patterns) features')
    parser.add_argument(
                    '--lbp-radius', default=8, action='store', type=int,
                            help='Radius to use for LBP features')
    parser.add_argument(
                    '--lbp-points', default=6, action='store', type=int,
                            help='Nr of points to use for LBP features')
    args = parser.parse_args()
    if not (args.haralick or args.lbp):
        sys.stderr.write('''\
No features selected. Doing nothing.

For example, use --haralick switch to compute Haralick features\n''')
        sys.exit(1)

    if not args.clobber and path.exists(args.output):
        print_error('Output file ({}) already exists. Refusing to overwrite results without --clobber argument.'.format(args.output))
        sys.exit(2)

    output = open(args.output, 'w')
    colnames = []
    if args.haralick:
        hlabels = mh.features.texture.haralick_labels[:-1]
        colnames.extend(["mean:{}".format(ell) for ell in hlabels])
        colnames.extend(["ptp:{}".format(ell) for ell in hlabels])
    if args.lbp:
        from mahotas.features.lbp import lbp_names
        colnames.extend(lbp_names(args.lbp_radius, args.lbp_points))
    _write_row(output, colnames)

    for fname in args.fnames:
        cur = []
        im = read_bw(fname, args)
        if args.haralick:
            har = mh.features.haralick(im, return_mean_ptp=True)
            cur.append(har)
        if args.lbp:
            cur.append(mh.features.lbp(im, args.lbp_radius, args.lbp_points))

        _write_row(output, chain.from_iterable(cur), fname)
    output.close()