Пример #1
0
    line, row = gray.shape
    # http://stackoverflow.com/a/13004147
    for pos in product(range(line), range(row)):
        rgb = (img.item(pos + (2, )), img.item(pos + (1, )),
               img.item(pos + (0, )))
        gray[pos] = conv(rgb)
    cv2.imwrite(add_to_file_name(imagename, '_gray'), gray)


def add_to_file_name(old_name, addition):
    fragments = path.splitext(old_name)
    return fragments[0] + addition + fragments[1]


palettes = dict()
palettes['tillscale'] = colorscale.TillPalette()


def main():
    parser = argparse.ArgumentParser(
        description='Convert an image saved as false color to grayscale')
    parser.add_argument('imagename',
                        metavar='IMAGEFILE',
                        help='The image to convert')
    parser.add_argument('-s',
                        '--colorscale',
                        choices=palettes.keys(),
                        help='Desired color scale',
                        required=True)
    args = parser.parse_args()
    convert(args.imagename, palettes[args.colorscale])
    elif backend == 'cv2':
        from .to_color_scale_cv2 import open_image, convert, save_img_as
    else:
        raise NotImplementedError('No such backend: ' + backend)
    img = open_image(imagename)
    img = convert(img, cscale)
    save_img_as(img, add_to_file_name(imagename, '_color'))


def add_to_file_name(old_name, addition):
    fragments = path.splitext(old_name)
    return fragments[0] + addition + fragments[1]


palettes = {
    'tillscale': colorscale.TillPalette(),
}


def main():
    parser = argparse.ArgumentParser(
        description='Convert an image saved as false color to grayscale')
    parser.add_argument('imagename',
                        metavar='IMAGEFILE',
                        help='The image to convert')
    parser.add_argument('-s',
                        '--colorscale',
                        choices=palettes.keys(),
                        help='Desired color scale',
                        required=True)
    parser.add_argument('-b',