def resize_depth_preserve(resize_tfm, depth):
    """
    Adapted from:
        https://github.com/TRI-ML/packnet-sfm_internal/blob/919ab604ae2319e4554d3b588877acfddf877f9c/packnet_sfm/datasets/augmentations.py#L93

    -------------------------------------------------------------------------------------------------------------------

    Resizes depth map preserving all valid depth pixels
    Multiple downsampled points can be assigned to the same pixel.
    Parameters
    ----------
    depth : np.array [h,w]
        Depth map
    shape : tuple (H,W)
        Output shape
    Returns
    -------
    depth : np.array [H,W,1]
        Resized depth map
    """
    assert depth.shape == (resize_tfm.h, resize_tfm.w)

    new_shape = (resize_tfm.new_h, resize_tfm.new_w)

    h, w = depth.shape
    x = depth.reshape(-1)
    # Create coordinate grid
    uv = np.mgrid[:h, :w].transpose(1, 2, 0).reshape(-1, 2)
    # Filters valid points
    idx = x > 0
    crd, val = uv[idx], x[idx]
    # Downsamples coordinates
    crd[:, 0] = (crd[:, 0] * (new_shape[0] / h)).astype(np.int32)
    crd[:, 1] = (crd[:, 1] * (new_shape[1] / w)).astype(np.int32)
    # Filters points inside image
    idx = (crd[:, 0] < new_shape[0]) & (crd[:, 1] < new_shape[1])
    crd, val = crd[idx], val[idx]
    # Creates downsampled depth image and assigns points
    resized_depth = np.zeros(new_shape)
    resized_depth[crd[:, 0], crd[:, 1]] = val
    return resized_depth

    Adapted from:
        https://github.com/TRI-ML/packnet-sfm_internal/blob/919ab604ae2319e4554d3b588877acfddf877f9c/packnet_sfm/datasets/augmentations.py#L93

    -------------------------------------------------------------------------------------------------------------------

    Resizes depth map preserving all valid depth pixels
    Multiple downsampled points can be assigned to the same pixel.
    Parameters
    ----------
    depth : np.array [h,w]
        Depth map
    shape : tuple (H,W)
        Output shape
    Returns
    -------
    depth : np.array [H,W,1]
        Resized depth map
    
tridet/data/augmentations/resize_transform.py