Sampling

Utilities.sampling.deformed_intensities(deformed_points, intensities, extent)[source]

Sample an image from a tensor of deformed points. Taken and adapted from https://gitlab.icm-institute.org/aramislab/deformetrica/blob/master/numpy/core/observations/deformable_objects/image.py

Utilities.sampling.deformed_intensities3d(deformed_points, intensities, affine)[source]

Sample a 3D image from a tensor of deformed points. Taken and adapted from https://gitlab.icm-institute.org/aramislab/deformetrica/blob/master/numpy/core/observations/deformable_objects/image.py

Utilities.sampling.interpolate_image(image, size=None, scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None)[source]

Simple wrapper around torch.nn.functional.interpolate() for 2D images.

Utilities.sampling.load_and_sample_greyscale(filename, threshold=0.0, centered=False, normalise_weights=True)[source]

Load a greyscale and sample points from it.

Utilities.sampling.load_greyscale_image(filename, origin='lower', dtype=None, device=None)[source]

Load grescale image from disk as an array of normalised float values.

Parameters
  • filename (str) – Filename of the image to load.

  • dtype (torch.dtype) – dtype of the returned image tensor.

  • device (torch.device) – Device on which the image tensor will be loaded.

Returns

[width, height] shaped tensor representing the loaded image.

Return type

torch.Tensor

Utilities.sampling.mask_to_indices(mask)[source]
Utilities.sampling.sample_from_greyscale(image, threshold, centered=False, normalise_weights=False, normalise_position=True)[source]
Sample points from a greyscale image.

Points are defined as a (position, weight) tuple.

imagetorch.Tensor

Tensor of shape [width, height] representing the image from which we will sample the points.

thresholdfloat

Minimum pixel value (i.e. point weight).

centeredbool, default=False

If true, center the sampled points.

normalise_weightsbool, default=False

If true, normalise weight values, such that :math:’lpha_i =

rac{lpha_i}{sum_k lpha_k}’
normalise_positionbool, default=True

If true, normalise point position such that all points live in the unit square.

torch.Tensor, torch.Tensor

Two tensors representing point position (of shape [N, dim]) and weight (of shape [N]), in this order, with :math:’N’ the number of points.