Skip to content

cvtkit.common

A suite of common utility functions.

This module includes general utility functions used by the sub-packages of the CVTkit library.

build_coords_list(H, W, batch_size, device)

Constructs an batched index list of pixel coordinates.

Parameters:

Name Type Description Default
H int

Height of the pixel grid.

required
W int

Width of the pixel grid.

required
batch_size int

Number of batches.

required
device str

GPU device identifier.

required

Returns:

Type Description
Tensor

The index list of shape [batch_size, H*W, 2]

build_depth_pyramid(depth, levels)

build_labels(depth, hypotheses)

cosine_similarity(t1, t2)

Computes the cosine similarity between two tensors.

Parameters:

Name Type Description Default
t1 Tensor

First tensor.

required
t2 Tensor

Second tensor.

required

Returns:

Type Description
Tensor

The cosine similarity between the two tensors.

crop_image(image, crop_row, crop_col, scale)

freeze_model_weights(model)

gaussian(window_size, sigma)

groupwise_correlation(t1, t2, num_groups)

Computes the Group-Wise Correlation (GWC) between two tensors.

Parameters:

Name Type Description Default
t1 Tensor

First tensor.

required
t2 Tensor

Second tensor.

required
num_groups int

Number of groups.

required

Returns:

Type Description
Tensor

The Group-Wise Correlation (GWC) between the two tensors.

laplacian_pyramid(image)

Computes the Laplacian pyramid of an image.

Parameters:

Name Type Description Default
image Tensor

2D map to compute Laplacian over.

required
tau

Laplacian region threshold.

required

Returns:

Type Description
Tensor

The map of the Laplacian regions.

laplacian_pyramid_th(image, tau)

Computes the Laplacian pyramid of an image.

Parameters:

Name Type Description Default
image Tensor

2D map to compute Laplacian over.

required
tau float

Laplacian region threshold.

required

Returns:

Type Description
Tensor

The map of the Laplacian regions.

non_zero_std(maps, device, dim=1, keepdim=False)

Computes the standard deviation of all non-zero values in an input Tensor along the given dimension.

Parameters:

Name Type Description Default
maps Tensor
required
device str
required
keepdim bool
False

Returns:

Type Description
Tensor

The standard deviation of the non-zero elements of the input map.

normalize(data, min_val=None, max_val=None)

parameters_count(net, name, do_print=True)

Parameters:

Returns:

print_gpu_mem()

Prints the current unallocated memory of the GPU.

round_nearest(num, decimal=0)

Rounds a floating point number to the nearest decimal place.

Parameters:

Name Type Description Default
num float

Float to be rounded.

required
decimal int

Decimal place to round to.

0

Returns:

Type Description
int

The given number rounded to the nearest decimal place.

Examples:

>>> round_nearest(11.1)
11
>>> round_nearest(15.7)
16
>>> round_nearest(2.5)
2
>>> round_nearest(3.5)
3
>>> round_nearest(14.156, 1)
14.2
>>> round_nearest(15.156, 1)
15.2
>>> round_nearest(15.156, 2)
15.16

scale_camera(cam, scale=1.0)

Scales a camera intrinsic parameters.

Parameters:

Name Type Description Default
cam ndarray

Input camera to be scaled.

required
scale float

Scale factor.

1.0

Returns:

Type Description
ndarray

The scaled camera.

scale_image(image, scale=1.0, interpolation='linear')

Scales an input pixel grid.

Parameters:

Name Type Description Default
image ndarray

Input image to be scaled.

required
scale float

Scale factor.

1.0
interpolation str

Interpolation technique to be used.

'linear'

Returns:

Type Description
NDArray[float32]

The scaled image.

scale_mvs_data(depths, confs, cams, scale=1.0, interpolation='linear')

Scales input depth maps, confidence maps, and cameras.

Parameters:

Name Type Description Default
depths ndarray

Input depth maps to be scaled.

required
confs ndarray

Input confidence maps to be scaled.

required
cams ndarray

Input cameras to be scaled

required
scale float

Scale factor.

1.0
interpolation str

Interpolation technique.

'linear'

Returns:

Name Type Description
scaled_depths ndarray

The scaled depth maps.

scaled_confs ndarray

The scaled confidence maps.

cams ndarray

The scaled cameras.

set_random_seed(seed)

Parameters:

Returns:

to_gpu(data, device)

Loads a dictionary of elements onto the GPU device.

Parameters:

Name Type Description Default
data dict

Dictionary to be loaded.

required
device str

GPU device identifier.

required

y_axis_rotation(P, theta)

Applies a rotation to the given camera extrinsics matrix along the y-axis.

Parameters:

Name Type Description Default
P ndarray

Initial extrinsics camera matrix.

required
theta float

Angle (in radians) to rotate the camera.

required

Returns:

Type Description
ndarray

The rotated extrinsics matrix for the camera.