Example #1
0
    def test_real_data(self):

        self.depth_example, _ = load_pfm(
            os.path.join('..', 'docs', 'img', 'pens.pfm'))

        # test case with real data
        plot_point_cloud(disp_arr=self.depth_example,
                         rgb_img=None,
                         down_scale=4,
                         show_axes=True)
        plt.show()
Example #2
0
    def plot(self):

        import matplotlib.pyplot as plt

        fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
        ax1.set_title('disparity map')
        ax1.imshow(self.disp_l, cmap='gray')
        ax2.set_title('ground truth')
        ax2.imshow(self.gt_l, cmap='gray')
        ax3.set_title('difference')
        ax3.imshow(self.disp_l - self.gt_l, cmap='gray')
        plt.show()

        plot_point_cloud(disp_arr=self.disp_l, rgb_img=self.img_l, down_scale=4)
        plt.show()
Example #3
0
    def plot_point_cloud(self,
                         rgb_img=None,
                         down_scale: int = 4,
                         view_angles: (int, int) = (50, 70),
                         s: float = 0.5,
                         ax: Axes3D = None) -> Axes3D:

        # use valid central view if rgb image is missing
        rgb_img = self.central_view if rgb_img is None and self.central_view is not None else rgb_img

        # downsample via interpolation
        if down_scale >= 1:
            rgb_img = img_resize(rgb_img.copy(), x_scale=1. /
                                 down_scale) if rgb_img is not None else None
            dpt_map = img_resize(self.depth_map.copy(),
                                 x_scale=1. / down_scale)
        else:
            warnings.warn(
                'Downscale parameter has to be a positive integer greater than zero.'
            )
            dpt_map = self.depth_map.copy()

        if self.depth_map is not None:
            ax = plot_point_cloud(dpt_map,
                                  rgb_img=rgb_img,
                                  down_scale=1,
                                  view_angles=view_angles,
                                  s=s,
                                  ax=ax)
        else:
            self.sta.status_msg(msg='Depth map variable is empty')
            ax = Axes3D(fig=plt.figure())

        return ax
Example #4
0
    def test_point_cloud(self):

        # test invalid downscale parameters
        for i in range(-1, 1):
            try:
                plot_point_cloud(disp_arr=None, rgb_img=None, down_scale=i)
            except IndexError as e:
                self.assertTrue(e, IndexError)

        # test case where rgb image missing
        plot_point_cloud(disp_arr=np.ones([3, 3]), rgb_img=None, down_scale=1)

        # test case for image dimension mismatch
        plot_point_cloud(disp_arr=np.ones([6, 6]),
                         rgb_img=np.ones([3, 3, 3]),
                         down_scale=1)

        # test valid case
        plot_point_cloud(disp_arr=np.ones([6, 6]),
                         rgb_img=np.ones([6, 6, 3]),
                         down_scale=2)

        # test invalid rgb values
        plot_point_cloud(disp_arr=np.ones([6, 6]),
                         rgb_img=np.ones([6, 6, 3]) * -1,
                         down_scale=2)

        # test Axes3D argument
        fig, ax = plt.figure(), plt.axes(projection='3d')
        ax_type = type(ax)
        ax = plot_point_cloud(disp_arr=np.ones([6, 6]),
                              rgb_img=np.ones([6, 6, 3]),
                              view_angles=(50, 70),
                              ax=ax)
        self.assertEqual(type(ax),
                         ax_type,
                         msg='Expected %s type, but got %s' %
                         (ax_type, type(ax)))
Example #5
0
    values = [float(v) / 1000 for v in list(range(5, 16, 1))]
    fig, axs = plt.subplots(1, len(values), figsize=(20, 5))
    for i in range(len(values)):
        res, _ = primal_dual_algo(cisparity,
                                  lambda_rof=0,
                                  theta=3,
                                  tau=values[i])
        axs[i].imshow(res, cmap='gray')
        axs[i].set_title(str(values[i]))
    plt.show()

    # plot results
    fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20, 5))
    ax1.imshow(Normalizer(lf_img_arr[lf_c, lf_c, ...]).type_norm(),
               cmap='gray')
    ax2.imshow(Normalizer(cisparity).type_norm(), cmap='gray')
    ax3.imshow(Normalizer(sisparity).type_norm(), cmap='gray')
    plt.show()

    plot_point_cloud(disp_arr=sisparity,
                     rgb_img=lf_img_arr[lf_c, lf_c, ...],
                     down_scale=4)
    plt.show()

    # save results
    plt.imsave('depth.png', cisparity, cmap='gray')
    save_pfm(sisparity, file_path='./depth.pfm', scale=1)

    pts = disp2pts(sisparity, rgb_img=lf_img_arr[lf_c, lf_c, ...])
    save_ply(pts, file_path='depth_1.ply')