def build_outputs(self):

        # store depthmaps

        self.depthmap_left = expand_dims(self.depthmap, 0)

        self.depthmap_right = expand_dims(self.depthmap, 1)

        if self.mode == 'test':
            return

        # generate disparities

        self.disparity_left = depth_to_disparity(self.depthmap_left, self.baseline, self.focal_length)

        self.disparity_right = depth_to_disparity(self.depthmap_right, self.baseline, self.focal_length)

        # generate estimates of left and right images

        self.left_est = spatial_transformation([self.right, self.disparity_left], -1)

        self.right_est = spatial_transformation([self.left, self.disparity_right], 1)

        # generate left - right consistency

        self.right_to_left_disparity = spatial_transformation([self.disparity_right, self.disparity_left], -1)

        self.left_to_right_disparity = spatial_transformation([self.disparity_left, self.disparity_right], 1)

        self.disparity_diff_left = disparity_difference([self.disparity_left, self.right_to_left_disparity])

        self.disparity_diff_right = disparity_difference([self.disparity_right, self.left_to_right_disparity])
Exemple #2
0
from layers import spatial_transformation
import matplotlib.image as mpimg
import numpy as np
from keras import backend as K
from image_loader import get_stereo_image_generators
import matplotlib.pyplot as plt

img_rows, img_cols = 128, 512

train_gen, test_gen, train_samples, test_samples = get_stereo_image_generators(
    'data/train/', 'data/test', batch_size=1, shuffle=True)
img = train_gen.__next__()

# spatial transformation lambda layer test

left_image = img[0][0]
disparity = 0.1 * np.ones((1, img_rows, img_cols, 1))

disparity = K.variable(disparity)
left_image = K.variable(left_image)

right_image = spatial_transformation([left_image, disparity], 1, '')

im_right = K.eval(right_image)
plt.imshow(im_right[0])
plt.show()

# TODO: add tests for remaining layers: expand_dims, depth_to_disparity, disparity_difference