nerfbaselines.cameras

nerfbaselines.cameras.get_image_pixels(image_sizes: TTensor) TTensor[source]

Get the pixel coordinates of all pixels of an image. The output is flattened array of all pixel coordinates in all images (shape [num_pixels, 2]).

Parameters:

image_sizes – [batch…, 2]

Returns:

Coordinates (x,y) in flattened format [num_pixels, 2]

nerfbaselines.cameras.get_rays(cameras: GenericCameras[TTensor], xy: TTensor) Tuple[TTensor, TTensor][source]

Gets correctly projected rays from pixel coordinates. This function is useful for raymarching. The function is similar to unproject but it offsets the pixel coordinates by 0.5 to get the center of the pixel. The shape of the output rays is the broadcasted shape of the input pixel coordinates and the camera poses:

  • For cameras and xy shapes () and (N, 2), the outputs shapes are (N, 3).

  • For cameras and xy shapes (N) and (N, 2), the outputs shapes are (N, 3).

  • For cameras and xy shapes (B…, N) and (B…, N, 2), the outputs shapes are (B…, N, 3).

Parameters:
  • cameras – Cameras

  • xy – Pixel coordinates

Returns:

A tuple of ray origins and ray directions.

nerfbaselines.cameras.interpolate_bilinear(image: TTensor, xy: TTensor) TTensor[source]

Interpolates an image at pixel coordinates using bilinear interpolation.

Parameters:
  • image – Image tensor [H, W, C]

  • xy – Pixel coordinates [H, W, 2]

Returns:

Interpolated image [H, W, C]

nerfbaselines.cameras.project(cameras: GenericCameras[TTensor], xyz: TTensor) TTensor[source]

Project 3D points to pixel coordinates. The shape of the output pixel coordinates is the broadcasted shape of the input 3D points and the camera poses:

  • For cameras and xyz shapes () and (N, 3), the output has shape (N, 2).

  • For cameras and xyz shapes (N) and (N, 3), the output has shape (N, 2).

  • For cameras and xyz shapes (B…, N) and (B…, N, 3), the output has shape (B…, N, 2).

Parameters:
  • cameras – Cameras

  • xyz – 3D points

Returns:

Pixel coordinates

nerfbaselines.cameras.undistort_camera(camera: Cameras)[source]

Undistort cameras.

Parameters:

camera – Cameras

Returns:

Pinhole cameras

nerfbaselines.cameras.unproject(cameras: GenericCameras[TTensor], xy: TTensor) Tuple[TTensor, TTensor][source]

Unproject pixel coordinates to rays in world coordinates. The shape of the output rays is the broadcasted shape of the input pixel coordinates and the camera poses:

  • For cameras and xy shapes () and (N, 2), the outputs shapes are (N, 3).

  • For cameras and xy shapes (N) and (N, 2), the outputs shapes are (N, 3).

  • For cameras and xy shapes (B…, N) and (B…, N, 2), the outputs shapes are (B…, N, 3).

Parameters:
  • cameras – Cameras

  • xy – Pixel coordinates

Returns:

A tuple of ray origins and ray directions.

nerfbaselines.cameras.warp_image_between_cameras(cameras1: GenericCameras[ndarray], cameras2: GenericCameras[ndarray], images: ndarray)[source]

Warp an image from cameras1 to cameras2 by mapping pixels from cameras2 to cameras1.

Parameters:
  • cameras1 – Cameras

  • cameras2 – Cameras

  • images – Images tensor

Returns:

Warped images