Beispiel #1
0
def disp_to_normal(ifname, ofname, height):
    gray_img = cu.cv_load(ifname)
    if len(gray_img.shape) == 3:
        h, w, ch = gray_img.shape[:3]
        gray_img = gray_img[:, :, 0]
    else:
        h, w = gray_img.shape[:2]
        ch = 1

    gray_img = gray_img.astype('float32')
    gray_img *= height

    nml_img = np.zeros((h, w, 3), dtype='float32')

    for y in range(1, h - 1):
        for x in range(1, w - 1):
            dzdx = (gray_img[y, x + 1] - gray_img[y, x - 1]) / 2.0
            dzdy = (gray_img[y + 1, x] - gray_img[y - 1, x]) / 2.0
            d = (-dzdx, dzdy, 1.0)
            n = normalize_vector(d)
            nml_img[y, x] = n * 0.5 + 0.5
    nml_img *= 255
    nml_img = nml_img.astype('uint8')
    nml_img = cv2.cvtColor(nml_img, cv2.COLOR_RGB2BGR)
    cu.cv_save(ofname, nml_img)
Beispiel #2
0
def f_new():
    shape = (200, 300, 3)
    dtype = 'uint8'
    bgr = (255, 0, 0)

    img = cu.cv_create_img(shape, dtype, bgr)

    fname = f'new_3_{dtype}.png'
    cu.cv_save(fname, img)
Beispiel #3
0
def img_show(fname, size):
    img = cu.cv_load(fname)

    oimg = cu.cv_fit_img(img, size)

    cv2.imshow(f"{fname}, {img.shape} {img.dtype}", oimg)

    key = cv2.waitKey()
    if key == 115: # 's'
        fn = tu.FileName(fname)
        ofname = f"small_{fn.name()}.png"
        cu.cv_save(ofname, oimg)
Beispiel #4
0
def f_conv_images(files, args):
    dst_size = (args.width, args.height)

    for ifname in files:
        fname = tu.FileName(ifname)
        name = fname.name()
        ofname = f"{name}.{args.ext}"
        if os.path.isfile(ofname) == True and not args.force:
            print(f"file is already existed: {ofname}")
            continue

        try:
            img = cu.cv_load(ifname)

            if args.srgb_to_linear:
                img = cu.cv_srgb_to_linear(img)

            if args.thumbnail > 0:
                thmb_size = (args.thumbnail, args.thumbnail)
                img = cu.cv_fit_img(img, thmb_size)
                img = cu.cv_crop_img(img, (0, 0), thmb_size, True)
            else:
                img = cu.cv_resize_img(img, dst_size)
                img = cu.cv_cvt_channels(img, args.channels)
                img = cu.cv_cvt_dtype(img, args.dtype)
                img = cu.cv_mult_img(img, args.mult)
                img = cu.cv_brightness_contrast_img(img, args.brightness,
                                                    args.contrast)
                if args.crop_size != [0, 0]:
                    img = cu.cv_crop_img(img, args.crop_pos, args.crop_size,
                                         args.crop_centering)

            if args.linear_to_srgb:
                img = cu.cv_linear_to_srgb(img)

            cu.cv_save(ofname, img)
        except Exception as e:
            print(f'fail to convert ... {ifname} {e}')
Beispiel #5
0
                        type=float,
                        nargs='+',
                        default=[1.0, 1.0, 1.0],
                        help='set bgr color')

    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()

    w = args.size[0]
    h = args.size[1]
    c = args.channels

    shape = (h, w, c)
    dtype = args.dtype
    bgr0 = cu.cv_color(args.bgr0, dtype)
    bgr1 = cu.cv_color(args.bgr1, dtype)

    if args.action == 'new':
        img = cu.cv_create_img(shape, dtype, bgr0)
    elif args.action == 'hgrad':
        img = cu.cv_create_hgrad_img(shape, dtype, bgr0, bgr1)
    elif args.action == 'vgrad':
        img = cu.cv_create_vgrad_img(shape, dtype, bgr0, bgr1)
    elif args.action == 'check':
        img = cu.cv_create_check_img(shape, dtype, bgr0, bgr1, args.nelm)

    cu.cv_save(args.ofname, img)
Beispiel #6
0
                        action='help',
                        help="show this help message and exit")
    parser.add_argument('-o',
                        '--output',
                        type=str,
                        default='tile.png',
                        help="set output file name")
    parser.add_argument('-c',
                        '--cols',
                        type=int,
                        default=2,
                        help="set columns")
    parser.add_argument('-h',
                        '--htile',
                        action='store_true',
                        help="input files are in horizontal order")
    parser.add_argument('files', type=str, nargs='+', help='input files')

    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()

    if args.htile:
        img = make_htile(args.cols, args.files)
    else:
        img = make_vtile(args.cols, args.files)

    cu.cv_save(args.output, img)
Beispiel #7
0
 def save(self, fname):
     cu.cv_save(fname, self.img)