Image

packnet_sfm.utils.image.flip_lr(image)[source]

Flip image horizontally

Parameters

image (torch.Tensor [B,3,H,W]) – Image to be flipped

Returns

image_flipped – Flipped image

Return type

torch.Tensor [B,3,H,W]

packnet_sfm.utils.image.flip_model(model, image, flip)[source]

Flip input image and flip output inverse depth map

Parameters
  • model (nn.Module) – Module to be used

  • image (torch.Tensor [B,3,H,W]) – Input image

  • flip (bool) – True if the flip is happening

Returns

inv_depths – List of predicted inverse depth maps

Return type

list of torch.Tensor [B,1,H,W]

packnet_sfm.utils.image.gradient_x(image)[source]

Calculates the gradient of an image in the x dimension :param image: Input image :type image: torch.Tensor [B,3,H,W]

Returns

gradient_x – Gradient of image with respect to x

Return type

torch.Tensor [B,3,H,W-1]

packnet_sfm.utils.image.gradient_y(image)[source]

Calculates the gradient of an image in the y dimension :param image: Input image :type image: torch.Tensor [B,3,H,W]

Returns

gradient_y – Gradient of image with respect to y

Return type

torch.Tensor [B,3,H-1,W]

packnet_sfm.utils.image.image_grid(B, H, W, dtype, device, normalized=False)[source]

Create an image grid with a specific resolution

Parameters
  • B (int) – Batch size

  • H (int) – Height size

  • W (int) – Width size

  • dtype (torch.dtype) – Meshgrid type

  • device (torch.device) – Meshgrid device

  • normalized (bool) – True if grid is normalized between -1 and 1

Returns

grid – Image grid containing a meshgrid in x, y and 1

Return type

torch.Tensor [B,3,H,W]

packnet_sfm.utils.image.interpolate_image(image, shape, mode='bilinear', align_corners=True)[source]

Interpolate an image to a different resolution

Parameters
  • image (torch.Tensor [B,?,h,w]) – Image to be interpolated

  • shape (tuple (H, W)) – Output shape

  • mode (str) – Interpolation mode

  • align_corners (bool) – True if corners will be aligned after interpolation

Returns

image – Interpolated image

Return type

torch.Tensor [B,?,H,W]

packnet_sfm.utils.image.interpolate_scales(images, shape=None, mode='bilinear', align_corners=False)[source]

Interpolate list of images to the same shape

Parameters
  • images (list of torch.Tensor [B,?,?,?]) – Images to be interpolated, with different resolutions

  • shape (tuple (H, W)) – Output shape

  • mode (str) – Interpolation mode

  • align_corners (bool) – True if corners will be aligned after interpolation

Returns

images – Interpolated images, with the same resolution

Return type

list of torch.Tensor [B,?,H,W]

packnet_sfm.utils.image.load_image(path)[source]

Read an image using PIL

Parameters

path (str) – Path to the image

Returns

image – Loaded image

Return type

PIL.Image

packnet_sfm.utils.image.match_scales(image, targets, num_scales, mode='bilinear', align_corners=True)[source]

Interpolate one image to produce a list of images with the same shape as targets

Parameters
  • image (torch.Tensor [B,?,h,w]) – Input image

  • targets (list of torch.Tensor [B,?,?,?]) – Tensors with the target resolutions

  • num_scales (int) – Number of considered scales

  • mode (str) – Interpolation mode

  • align_corners (bool) – True if corners will be aligned after interpolation

Returns

images – List of images with the same resolutions as targets

Return type

list of torch.Tensor [B,?,?,?]

packnet_sfm.utils.image.meshgrid(B, H, W, dtype, device, normalized=False)[source]

Create meshgrid with a specific resolution

Parameters
  • B (int) – Batch size

  • H (int) – Height size

  • W (int) – Width size

  • dtype (torch.dtype) – Meshgrid type

  • device (torch.device) – Meshgrid device

  • normalized (bool) – True if grid is normalized between -1 and 1

Returns

  • xs (torch.Tensor [B,1,W]) – Meshgrid in dimension x

  • ys (torch.Tensor [B,H,1]) – Meshgrid in dimension y