Untitled
unknown
plain_text
9 months ago
2.1 kB
50
Indexable
def render_disparity_hypothesis(src: np.ndarray, dst: np.ndarray, offset: int, pad_size: int) -> np.ndarray: """Calculates the agreement between the shifted src image and the dst image. Args: src: one image taken from a camera, numpy array of shape [H x W x 3] dst: another image with camera only translate, numpy array of shape [H x W x 3] offset: an integer value by which the image is shifted pad_size: an integer value to pad the images for computation Returns: a numpy array of shape [H x W] containing the euclidean distance between RGB values of the shifted src and dst images. """ # Step 1: Pad necessary values to src and dst padded_src = np.pad(src, ((0, 0), (pad_size, pad_size), (0, 0)), mode='constant') padded_dst = np.pad(dst, ((0, 0), (pad_size, pad_size), (0, 0)), mode='constant') # Step 2: Compute the horizontally shifted source image if offset + src.shape[1] > padded_src.shape[1]: raise ValueError("Offset is too large, resulting in an out-of-bounds index.") shifted_src = padded_src[:, pad_size + offset:pad_size + offset + src.shape[1]] shifted_src = np.roll(padded_src, shift=-offset, axis=1) # Compute the disparity map diff = shifted_src - padded_dst disparity_map = np.sqrt(np.sum(diff ** 2, axis=2)) # Display images for debugging show_images_side_by_side( shifted_src[:, pad_size + offset: pad_size + src.shape[1]].astype(np.uint8), # Convert to uint8 for proper display padded_dst[:, pad_size + offset: pad_size + src.shape[1]].astype(np.uint8), disparity_map[:, pad_size: pad_size + src.shape[1]].astype(np.uint8), 'Shifted Source Image', 'Destination Image', 'Disparity Image' ) print('Dimensionen') print(src.shape) print(disparity_map[:, pad_size - offset:pad_size + src.shape[1] - offset ].shape) print(disparity_map[0, pad_size - offset - 1:pad_size + src.shape[1] + 1]) return disparity_map[:, pad_size - offset:pad_size + src.shape[1] ]
Editor is loading...
Leave a Comment