예제 #1
0
def crop(data):
    def rect_for_img(idx):
        rect = None
        if idx < 11:
            rect = (426, 204, 582, 397)
        elif 11 <= idx < 22:
            rect = (357, 117, 628, 395)
        elif 22 <= idx < 33:
            rect = (322, 1, 606, 396)
        elif 33 <= idx < 44:
            rect = (412, 179, 586, 397)
        return rect

    names = ['images', 'img_corrected_1']
    img, gts_left = data
    for name in names:
        dir_name = f'./projector_test/projector1/{name}'
        idx = int(img[:-4]) - 1
        image = fu.load_png(img, dir_name, '', mask_cube=False)
        rect = rect_for_img(idx)
        if rect is None:
            continue
        cropped = pu.crop(image, rect, False)
        cropped = cv2.resize(cropped, (1000, 1000))
        cv2.imwrite(
            f'./projector_test/projector1_cropped_resized/{name}/{idx + 1}.png',
            cv2.cvtColor(cropped, cv2.COLOR_RGB2BGR))
예제 #2
0
def process_and_save(name):
    make_mask = True
    path = './data'
    folder = 'relighted'
    print(name)
    image, gt = fu.load_png(name, path=path,
                            directory=f'{folder}/images'), fu.load_png(
                                name, path=path, directory=f'{folder}/gt')
    if make_mask:
        filename = f"{path}/{folder}/gt_mask/{name}"
        mask = gu.get_mask_from_gt(gt)
        cv2.imwrite(filename, mask)
    corrected = create_corrected_image(image, gt, mask).astype(int)
    r, g, b = cv2.split(corrected)
    corrected = np.dstack((b, g, r))
    filename = f"{path}/{folder}/img_corrected_1/{name}"
    cv2.imwrite(filename, corrected)
예제 #3
0
def correct(data):
    dir_name = './projector_test/projector2/images'
    img, gts_left = data
    idx = int(img[:-4]) - 1
    image = fu.load_png(img, dir_name, '', mask_cube=False)
    gt = np.clip(gts_left[idx], 1, 255) / 255
    image = iu.color_correct_single(image, gt, c_ill=1 / 3)
    cv2.imwrite(f'./projector_test/projector2/img_corrected_1/{idx + 1}.png',
                cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
예제 #4
0
def main_process(data):
    img, gt1, gt2 = data
    image_path = './data/custom'
    masks_path = f'./data/masks/{img}'
    masks = os.listdir(masks_path)
    gt1 = [0.83529411765, 0.67450980392, 0.36470588235]
    gt2 = [0.58431372549, 0.65882352941, 0.64705882353]
    gts = [(gt1, gt2), (gt2, gt1), (gt2, gt1)]
    # gts = [(gt2[img - 1], gt1[img - 1]),(gt2[img - 1], gt1[img - 1]),(gt2[img - 1], gt1[img - 1])]

    image = fu.load_png(str(img) + '.jpg',
                        path=image_path,
                        directory='',
                        mask_cube=False)
    mask = list(
        map(
            lambda x: fu.load_png(
                x, path=masks_path, directory='', mask_cube=False), masks))
    cor = process_and_visualize(image, mask, gts, img)
예제 #5
0
def par_create(data):
    idx, img, gts_left, gts_right, dir = data
    # dir = 'G:\\fax\\diplomski\\Datasets\\third\\ambient2'
    dir_name = f'{dir}/both/images'
    dir_name_left = f'{dir}/ambient/images'
    dir_name_right = f'{dir}/direct/images'

    image = fu.load_png(img, dir_name, '', mask_cube=False)
    image_left = fu.load_png(img, dir_name_left, '', mask_cube=False)
    image_right = fu.load_png(img, dir_name_right, '', mask_cube=False)
    image = cv2.resize(image, (0, 0), fx=1 / 5, fy=1 / 5)
    image_left = cv2.resize(image_left, (0, 0), fx=1 / 5, fy=1 / 5)
    image_right = cv2.resize(image_right, (0, 0), fx=1 / 5, fy=1 / 5)
    gt_left = np.clip(gts_left[idx], 1, 255) / 255
    gt_right = np.clip(gts_right[idx], 1, 255) / 255
    gt_mask, ir, il, r = pu.create_gt_mask(image, image_right, image_left,
                                           gt_right, gt_left)
    ggt_mask = gt_mask  #pu.denoise_mask(gt_mask)
    saveImage(ggt_mask.astype(np.uint8), f'{dir}/gt_mask/', idx + 1)
예제 #6
0
def main_process(data):
    use_corrected_masks = True
    image_path = '../MultiIlluminant-Utils/data/test/whatsapp/images'
    mask_path = '../MultiIlluminant-Utils/data/test/whatsapp/pmasks-custom'
    ext = '.png' if use_corrected_masks else '.jpg'
    img, gt1, gt2 = data

    image = fu.load_png(img, path=image_path, directory='', mask_cube=False)
    mask = fu.load_png(img[:-4] + ext,
                       path=mask_path,
                       directory='',
                       mask_cube=False)
    cor = process_and_visualize(image,
                                img,
                                gt1,
                                gt2,
                                mask,
                                title=img,
                                use_estimation=True)
예제 #7
0
def main_process2(data):
    use_corrected_masks = True
    # image_path = '../MultiIlluminant-Utils/data/test/whatsapp/images'
    # mask_path = '../MultiIlluminant-Utils/data/test/whatsapp/pmasks'
    image_path = '../MultiIlluminant-Utils/data/dataset_relighted/valid/images'
    mask_path = '../MultiIlluminant-Utils/data/dataset_relighted/valid/pmasks'  #if use_corrected_masks else './data/custom_mask_nocor'
    gt_mask_path = '../MultiIlluminant-Utils/data/dataset_relighted/valid/gt_mask'  # if use_corrected_masks else './data/custom_mask_nocor'
    gt_path = '../MultiIlluminant-Utils/data/dataset_relighted/valid/gt'
    ext = '.png' if use_corrected_masks else '.jpg'
    img, gt1, gt2 = data

    image = fu.load_png(img, path=image_path, directory='', mask_cube=False)
    mask = fu.load_png(img, path=mask_path, directory='', mask_cube=False)
    gt_mask = fu.load_png(img,
                          path=gt_mask_path,
                          directory='',
                          mask_cube=False)
    gt = fu.load_png(img, path=gt_path, directory='', mask_cube=False)
    process_with_real_and_predicted(image, img, mask, gt_mask, gt)
예제 #8
0
def find_gt(fax=False):
    if fax:
        dir = "/media/donik/Disk/ambient3"
    else:
        dir = 'G:\\fax\\diplomski\\Datasets\\third\\ambient3'
    dir_name = f'{dir}/both'
    dir_name_left = f'{dir}/ambient'
    dir_name_right = f'{dir}/direct'
    images = os.listdir(dir_name)
    images = list(filter(lambda x: str(x).lower().endswith('.png'), images))
    images_del = list(
        filter(lambda x: str(x).lower().startswith('cup-'), images))
    images = list(
        filter(lambda x: not str(x).lower().startswith('cup-'), images))

    gts_left, gts_right = [], []
    for idx, img in enumerate(images):
        img_idx = int(img[-5])
        img_name_base = img[:-5]
        image = fu.load_png(img, dir_name, '', mask_cube=False)
        image = iu.process_image(image, depth=16, blacklevel=0)
        image_r = fu.load_png(img_name_base + str(img_idx + 2) + '.png',
                              dir_name_right,
                              '',
                              mask_cube=False)
        image_r = iu.process_image(image_r, depth=16, blacklevel=0)
        image_l = fu.load_png(img_name_base + str(img_idx + 1) + '.png',
                              dir_name_left,
                              '',
                              mask_cube=False)
        image_l = iu.process_image(image_l, depth=16, blacklevel=0)
        gt_left, gt_right = np.zeros(3), np.zeros(3)
        n = 20
        for i in range(n):
            for j in range(n):
                if idx >= 40:
                    x1, y1 = 967, 1688
                    x2, y2 = 4598, 1573
                else:
                    x1, y1 = 770, 1672  #1379, 2336 #3241, 1955#3861, 1912#1200, 2450
                    x2, y2 = 4723, 1535  #3803, 2481#3092, 1974#1368, 2217 #1350, 2450
                # if idx < 39 or idx > 43:
                #     x1, y1 = 1152, 1812
                #     x2, y2 = 4278, 1647
                # else:
                #     x1, y1 = 1089, 362
                #     x2, y2 = 2494, 351
                gt_left = gt_left + np.clip(image_l[y1 + i, x1 + j], 1, 255)
                gt_right = gt_right + np.clip(image_r[y2 + i, x2 + j], 1, 255)
        gt_left, gt_right = gt_left / n / n, gt_right / n / n
        # image = cv2.resize(image, (0, 0), fx = 1/5, fy = 1/5)
        gts_left.append(gt_left)
        gts_right.append(gt_right)
        saveImage(image, f'{dir}/both/images', idx + 1)
        saveImage(image_l, f'{dir}/ambient/images', idx + 1)
        saveImage(image_r, f'{dir}/direct/images', idx + 1)
    np.savetxt(f'{dir}/gt_left.txt',
               np.array(gts_left, dtype=np.uint8),
               fmt='%d')
    np.savetxt(f'{dir}/gt_right.txt',
               np.array(gts_right, dtype=np.uint8),
               fmt='%d')
예제 #9
0
import cv2
import utils.file_utils as fu
import utils.plotting_utils as pu

names = [17, 18, 3, 5, 7, 10, 21, 9, 2]
names = [2]
names = list(map(lambda x: str(x) + '.jpg', names))
for name in names:
    image = fu.load_png(name, './data', 'custom_mask_nocor')

    rotated = cv2.flip(image, 0)
    pu.visualize([image, rotated])
    cv2.imwrite(f'./data/custom_mask_nocor/{name}', rotated)
exit(0)
예제 #10
0
def process_and_visualize(image, idx, gts, title=None, draw=True):
    # rgb = img
    gt = gts[idx - 1]
    gt = gt / np.linalg.norm(gt)
    corrected = iu.color_correct_single(image, gt, 1 / np.sqrt(3))

    if draw:
        pu.visualize([
            image,
            corrected,
        ], title=title)
    return corrected


if __name__ == '__main__':
    gt = GroundtruthLoader('custom_gt.txt', path='./data')
    image_path = './data/custom'
    image_names = os.listdir(image_path)
    images = range(1, len(image_names) + 1)
    images = [23]

    for img in images:
        image = fu.load_png(str(img) + '.jpg',
                            path=image_path,
                            directory='',
                            mask_cube=False)
        cor = process_and_visualize(image, img, gt, title=img)
        cv2.imwrite(f'./data/custom_relighted/{str(img)}.png',
                    cv2.cvtColor(cor, cv2.COLOR_RGB2BGR))