Esempio n. 1
0
    def __getitem__(self, idx):
        input_data = {}

        # left
        left_fname = self.left_data[idx]
        left = np.array(Image.open(left_fname)).astype(np.uint8)
        input_data['left'] = left

        # right
        right_fname = self.right_data[idx]
        right = np.array(Image.open(right_fname)).astype(np.uint8)
        input_data['right'] = right

        # disp
        if not self.split == 'test':  # no disp for test files
            disp_fname = self.disp_data[idx]

            disp = np.array(Image.open(disp_fname)).astype(np.float) / 256.
            input_data['disp'] = disp
            input_data['occ_mask'] = np.zeros_like(disp).astype(np.bool)

            if self.split == 'train':
                input_data = random_crop(200, 640, input_data, self.split)

            input_data = augment(input_data, self.transformation)
        else:
            input_data = normalization(**input_data)

        return input_data
Esempio n. 2
0
    def __getitem__(self, idx):
        input_data = {}

        # left
        left_fname = os.path.join(self.datadir, self.left_data[idx])
        left = np.array(Image.open(left_fname)).astype(np.uint8)
        input_data['left'] = left

        # right
        right_fname = os.path.join(self.datadir, self.right_data[idx])
        right = np.array(Image.open(right_fname)).astype(np.uint8)
        input_data['right'] = right

        if not self.split == 'test':  # no disp for test files
            # occ
            occ_left_fname = os.path.join(self.datadir,
                                          self.occ_left_data[idx])
            occ_right_fname = os.path.join(self.datadir,
                                           self.occ_right_data[idx])
            occ_left = np.array(Image.open(occ_left_fname)) == 128
            occ_right = np.array(Image.open(occ_right_fname)) == 128

            # disp
            disp_left_fname = os.path.join(self.datadir,
                                           self.disp_left_data[idx])
            disp_right_fname = os.path.join(self.datadir,
                                            self.disp_right_data[idx])

            disp_left, _ = readPFM(disp_left_fname)
            disp_right, _ = readPFM(disp_right_fname)

            if self.split == 'train':
                # horizontal flip
                input_data['left'], input_data['right'], input_data['occ_mask'], input_data['occ_mask_right'], \
                input_data['disp'], \
                input_data['disp_right'] = horizontal_flip(input_data['left'], input_data['right'], occ_left, occ_right,
                                                           disp_left,
                                                           disp_right, self.split)
                # random crop
                input_data = random_crop(360, 640, input_data, self.split)
            else:
                input_data['occ_mask'] = occ_left
                input_data['occ_mask_right'] = occ_right
                input_data['disp'] = disp_left
                input_data['disp_right'] = disp_right
            input_data = augment(input_data, self.transformation)
        else:
            input_data = normalization(**input_data)

        return input_data
Esempio n. 3
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(
            np.uint8)[..., :3]

        right_fname = left_fname.replace('left', 'right')
        result['right'] = np.array(Image.open(right_fname)).astype(
            np.uint8)[..., :3]

        occ_right_fname = self.occ_data[idx].replace('left', 'right')
        occ_left = np.array(Image.open(self.occ_data[idx])).astype(np.bool)
        occ_right = np.array(Image.open(occ_right_fname)).astype(np.bool)

        disp_left_fname = left_fname.replace('frame_finalpass',
                                             'disparity').replace(
                                                 '.png', '.pfm')
        disp_right_fname = right_fname.replace('frame_finalpass',
                                               'disparity').replace(
                                                   '.png', '.pfm')
        disp_left, _ = readPFM(disp_left_fname)
        disp_right, _ = readPFM(disp_right_fname)

        if self.split == "train":
            # horizontal flip
            result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
                = horizontal_flip(result['left'], result['right'], occ_left, occ_right, disp_left, disp_right,
                                  self.split)
            result['disp'] = np.nan_to_num(disp, nan=0.0)
            result['disp_right'] = np.nan_to_num(disp_right, nan=0.0)

            # random crop
            result = random_crop(360, 640, result, self.split)
        else:
            result['occ_mask'] = occ_left
            result['occ_mask_right'] = occ_right
            result['disp'] = disp_left
            result['disp_right'] = disp_right

        result = augment(result, self.transformation)

        return result
Esempio n. 4
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(
            np.uint8)[..., :3]

        right_fname = left_fname.replace('left', 'right')
        result['right'] = np.array(Image.open(right_fname)).astype(
            np.uint8)[..., :3]

        occ_left_fname = left_fname.replace("image_clean",
                                            "disparity_occlusions")
        occ_right_fname = right_fname.replace("image_clean",
                                              "disparity_occlusions")

        #occ_right_fname = self.occ_data[idx].replace('left', 'right')
        occ_left = np.array(Image.open(occ_left_fname)).astype(np.bool)
        occ_right = np.array(Image.open(occ_right_fname)).astype(np.bool)

        disp_left_fname = left_fname.replace('image_clean',
                                             'disparity').replace(
                                                 '.png', '.pfm')
        disp_right_fname = right_fname.replace('image_clean',
                                               'disparity').replace(
                                                   '.png', '.pfm')
        disp_left, _ = readPFM(disp_left_fname)
        disp_right, _ = readPFM(disp_right_fname)

        imgleft = np.array(result["left"])
        np.save("./leftimg", imgleft)

        disp_out = np.array(disp_left)
        np.save("./displeft_out", disp_out)

        disp_outr = np.array(disp_right)
        np.save("./dispright_out", disp_outr)

        occleft = np.array(occ_left)
        np.save("./occleft", occleft)

        occright = np.array(occ_right)
        np.save("./occright", occright)

        if self.split == "train":
            # horizontal flip
            #result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
            #    = horizontal_flip(result['left'], result['right'], occ_left, occ_right, disp_left, disp_right, self.split)

            result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
                =result['left'], result['right'], occ_left, occ_right, disp_left, disp_right

            result['disp'] = np.nan_to_num(disp, nan=0.0)
            result['disp_right'] = np.nan_to_num(disp_right, nan=0.0)

            # random crop
            result = random_crop(360, 640, result, self.split)
        else:
            result['occ_mask'] = occ_left
            result['occ_mask_right'] = occ_right
            result['disp'] = disp_left
            result['disp_right'] = disp_right

        result = augment(result, self.transformation)
        #cc=result["disp"]
        return result