예제 #1
0
def combine(src,src_path):
    if a.b_dir is None:
        raise Exception("missing b_dir")
    basename,_ = os.path.splitext(os.path.basename(src_path)) #取出b的name
    for ext in ['.jpg','.png']:
        sibling_path = os.path.join(a.b_dir,basename + ext) #b完整文件名
        if os.path.existing(sibling_path):
            sibling = im.load(sibing_path) #如果sibling_path存在,下载该文件
            break
        else:
            raise Exception("could not find sibling image for" + src_path)
    height,width,_ = src.shape
    if sibling.shape[0] != height or sibling.shape[1] != width: #如果A,B图像size不一样,保存
        raise Exception("differing sizes")

    if src.shape[2] == 1: #若果为grayimage,转为rgb
        src = im.grayscale_to_rgb(images = src)

    if sibling.shape[2] == 1:
        sibling = im.grayscale_to_rgb(images = sibling)

    if src.shape[2] == 4:
        src = src[:,:,3]

    if sibling.shape[2] == 4:
        sibling = sibling[:,:,3]

    return np.concatenate([src,sibling],axis=1) #返回二者合并项
예제 #2
0
def combine(src, src_path):
    if a.b_dir is None:
        raise Exception("missing b_dir")

    # find corresponding file in b_dir, could have a different extension
    basename, _ = os.path.splitext(os.path.basename(src_path))
    for ext in [".png", ".jpg"]:
        sibling_path = os.path.join(a.b_dir, basename + ext)
        if os.path.exists(sibling_path):
            sibling = im.load(sibling_path)
            break
    else:
        raise Exception("could not find sibling image for " + src_path)

    # make sure that dimensions are correct
    height, width, _ = src.shape
    if height != sibling.shape[0] or width != sibling.shape[1]:
        raise Exception("differing sizes")

    # convert both images to RGB if necessary
    if src.shape[2] == 1:
        src = im.grayscale_to_rgb(images=src)

    if sibling.shape[2] == 1:
        sibling = im.grayscale_to_rgb(images=sibling)

    # remove alpha channel
    if src.shape[2] == 4:
        src = src[:, :, :3]

    if sibling.shape[2] == 4:
        sibling = sibling[:, :, :3]

    return np.concatenate([src, sibling], axis=1)
예제 #3
0
def combine(pairing, A_path, B_path, dst_path):
    # clear output path
    if os.path.exists(dst_path):
        shutil.rmtree(dst_path)
    os.mkdir(dst_path)
    with tf.Session() as sess:
        for imgA_name, imgB_name in pairing.items():
            imgA = im.load(os.path.join(A_path, imgA_name))
            imgB = im.load(os.path.join(B_path, imgB_name))

            # make sure that dimensions are correct
            height, width, _ = imgA.shape
            if height != imgB.shape[0] or width != imgB.shape[1]:
                raise Exception("differing sizes")

            # convert both images to RGB if necessary
            if imgA.shape[2] == 1:
                imgA = im.grayscale_to_rgb(images=imgA)

            if imgB.shape[2] == 1:
                imgB = im.grayscale_to_rgb(images=imgB)

            # remove alpha channel
            if imgA.shape[2] == 4:
                imgA = imgA[:, :, :3]

            if imgB.shape[2] == 4:
                imgB = imgB[:, :, :3]

            imgC = np.concatenate([imgA, imgB], axis=1)
            im.save(imgC, os.path.join(dst_path, imgA_name))
예제 #4
0
def combine(src, src_path):
    if a.b_dir is None:
        raise Exception("missing b_dir")

    # find corresponding file in b_dir, could have a different extension
    basename, _ = os.path.splitext(os.path.basename(src_path))
    for ext in [".png", ".jpg"]:
        sibling_path = os.path.join(a.b_dir, basename + ext)
        if os.path.exists(sibling_path):
            sibling = im.load(sibling_path)
            break
    else:
        raise Exception("could not find sibling image for " + src_path)

    # make sure that dimensions are correct
    height, width, _ = src.shape
    if height != sibling.shape[0] or width != sibling.shape[1]:
        raise Exception("differing sizes")

    # convert both images to RGB if necessary
    if src.shape[2] == 1:
        src = im.grayscale_to_rgb(images=src)

    if sibling.shape[2] == 1:
        sibling = im.grayscale_to_rgb(images=sibling)

    # remove alpha channel
    if src.shape[2] == 4:
        src = src[:, :, :3]

    if sibling.shape[2] == 4:
        sibling = sibling[:, :, :3]

    return np.concatenate([src, sibling], axis=1)
예제 #5
0
def combine(src, src_path):
    if args.b1_dir is None:
        raise Exception("missing b1_dir")
    elif args.b2_dir is None:
        raise Exception("missing b2_dir")

    # find corresponding file in b_dir, could have a different extension
    # b_dir에서 해당 파일 탐색, 다른 확장자를 가질 수도 있음
    # 입력받은 한글 이미지(src_path)의 확장자를 뺀 이름만 가져와
    # 해당 이름을 가진 스켈레톤 이미지의 경로를 얻음(여기서는 sibling-형제-으로 표현)
    basename, _ = os.path.splitext(os.path.basename(src_path))
    for ext in [".png", ".jpg"]:
        sibling_path1 = os.path.join(args.b1_dir, basename + ext)
        if os.path.exists(sibling_path1):
            sibling1 = im.load(sibling_path1)
            break
    else:
        raise Exception("could not find sibling1 image for " + src_path)

    for ext in [".png", ".jpg"]:
        sibling_path2 = os.path.join(args.b2_dir, basename + ext)
        if os.path.exists(sibling_path2):
            sibling2 = im.load(sibling_path2)
            break
    else:
        raise Exception("could not find sibling2 image for " + src_path)

    # make sure that dimensions are correct
    # 한글 이미지의 크기와 스켈레톤 이미지의 크기가 같은지 확인
    height, width, _ = src.shape
    if height != sibling1.shape[0] or width != sibling1.shape[
            1] or height != sibling2.shape[0] or width != sibling2.shape[1]:
        raise Exception("differing sizes")

    # convert all images to RGB if necessary
    # 두 이미지가 만일 그레이스케일 이미지라면 RGB로 변환
    if src.shape[2] == 1:
        src = im.grayscale_to_rgb(images=src)

    if sibling1.shape[2] == 1:
        sibling1 = im.grayscale_to_rgb(images=sibling1)

    if sibling2.shape[2] == 1:
        sibling2 = im.grayscale_to_rgb(images=sibling2)

    # remove alpha channel
    # 두 이미지의 알파 채널(투명도)를 삭제함
    if src.shape[2] == 4:
        src = src[:, :, :3]

    if sibling1.shape[2] == 4:
        sibling1 = sibling1[:, :, :3]

    if sibling2.shape[2] == 4:
        sibling2 = sibling2[:, :, :3]

    # 두 이미지를 하나로 합쳐 리턴
    return np.concatenate([src, sibling1, sibling2], axis=1)
예제 #6
0
def split(src1, src2):

    # make sure that dimensions are correct
    height, width, _ = src1.shape

    width_cutoff = int(width / 2)

    # convert both images to RGB if necessary
    if src1.shape[2] == 1:
        src1 = im.grayscale_to_rgb(images=src1)
        src2 = im.grayscale_to_rgb(images=src2)

    # remove alpha channel
    if src2.shape[2] == 4:
        src1 = src1[:, :, :3]
        src2 = src2[:, :, :3]

    im1 = src1[:, :width_cutoff]
    im2 = src2[:, width_cutoff:]

    im_dest = np.concatenate([im1, im2], axis=1)

    return im_dest
예제 #7
0
def grayscale(src):
    return im.grayscale_to_rgb(images=im.rgb_to_grayscale(images=src))
예제 #8
0
def combine_MultiView(src, src_path):
    if a.b_dir is None:
        raise Exception("missing b_dir")

    if a.c_dir is None:
        raise Exception("missing c_dir")

    # find corresponding file in b_dir, could have a different extension
    basename, _ = os.path.splitext(os.path.basename(src_path))

    basename_c = basename

    # Frizy : added
    basename_right = basename.replace('left', 'right')
    basename_right = basename_right.rsplit('_', 1)
    basename_right = basename_right[0] + '_1'

    for ext in [".png", ".jpg"]:
        sibling_path = os.path.join(a.b_dir, basename_right + ext)
        if os.path.exists(sibling_path):
            sibling = im.load(sibling_path)
            break
        else:
            raise Exception("could not find sibling image for " + src_path)

    for ext in [".png", ".jpg"]:
        sibling_path_c = os.path.join(a.c_dir, basename_c + ext)
        if os.path.exists(sibling_path_c):
            sibling_c = im.load(sibling_path_c)
            break
        else:
            raise Exception("could not find sibling_c image for " + src_path)

    # make sure that dimensions are correct
    height, width, _ = src.shape
    if height != sibling.shape[0] or width != sibling.shape[1]:
        raise Exception("differing sizes")

    if height != sibling_c.shape[0] or width != sibling_c.shape[1]:
        raise Exception("differing sizes")

    # convert both images to RGB if necessary
    if src.shape[2] == 1:
        src = im.grayscale_to_rgb(images=src)

    if sibling.shape[2] == 1:
        sibling = im.grayscale_to_rgb(images=sibling)

    if sibling_c.shape[2] == 1:
        sibling_c = im.grayscale_to_rgb(images=sibling_c)

    # remove alpha channel
    if src.shape[2] == 4:
        src = src[:, :, :3]

    if sibling.shape[2] == 4:
        sibling = sibling[:, :, :3]

    if sibling_c.shape[2] == 4:
        sibling_c = sibling_c[:, :, :3]

    return np.concatenate([src, sibling, sibling_c], axis=1)
예제 #9
0
def grayscale(src):
    return im.grayscale_to_rgb(images=im.rgb_to_grayscale(images=src))