Resampling#

This module provides methods to resample and reorient data.

Resampling the data is usually necessary as the first step to match the resolution and orientation of the reference object.

class OrientationTransformation(orientation=None, shape=None, inverse=None)[source]#

Bases: TransformationBase

to_dict() dict[source]#
transform_data(source, sink=None, inverse=False)[source]#
transform_points(source, sink=None, inverse=False, **kwargs)[source]#
transform_shape(shape, inverse=False, **kwargs)[source]#
ttype = 'Orientation'#
class ResamplingTransformation(ttype='Resampling', inverse=False, original_resolution=None, resampled_resolution=None, original_shape=None, resampled_shape=None, original=None, resampled=None, orientation=None)[source]#

Bases: TransformationBase

resample_factor()[source]#
resample_kwargs()[source]#
to_dict() dict[source]#
transform_data(source, sink=None, inverse=False, **kwargs)[source]#
transform_points(source, sink=None, inverse=False, **kwargs)[source]#
transform_shape(shape, inverse=False, **kwargs)[source]#
all_not_none(*args)[source]#
original_resolution_from_shape(original_shape, resampled_shape, resampled_resolution, orientation=None)[source]#

Calculate the original resolution given shape information.

Arguments

original_shapetuple

Shape of the data array to be resampled.

resampled_shapetuple

Resolution of the resampled data array.

resampled_resolutiontuple

Resolution of the resampled data array.

orientationtuple

Orientation specifications.

Returns

resampled_resolutiontuple or None

The resolution of the resampled data array.

original_shape_from_resolution(resampled_shape, original_resolution, resampled_resolution, orientation=None, discretize=True)[source]#

Calculate the original shape given resolution information.

Arguments

resampled_shapetuple

Shape of the resampled data array.

original_resolutiontuple

Resolution of the data array to be resampled.

resampled_resolutiontuple

Resolution of the resampled data array.

orientationtuple

Orientation specifications.

discretizebool

If True, return next largest integer values.

Returns

resampled_shapetuple or None

The shape of the resampled data array.

resample(original, resampled=None, original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, orientation=None, interpolation='linear', axes_order=None, method='shared', processes=None, workspace=None, verbose=True)[source]#

Resample data of source in new shape/resolution and orientation.

Arguments

originalstr, array or None

Data array source to be resampled.

resampled: str, array or None

Optional sink for the resampled data.

original_shapetuple or None

Optional value for the shape of the data array to be resampled. Determined by the shape of the original source by default.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

orientationtuple or None

Orientation specification.

interpolationstr

Interpolation method to use. Available methods are ‘linear’, ‘nearest’, ‘area’.

axes_orderlist of tuples of int or None

The axes pairs along which to resample the data at each step. If None, this is determined automatically. For a FileList source, setting the first tuple should point to axis not indicating files. If ‘size’ the axis order is determined automatically to maximally reduce the size of the array in each resampling step. If ‘order’ the axis order is chosen automatically to optimize io speed.

method‘shared’ or ‘memmap’

Method to handle intermediate resampling results. If ‘shared’ use shared memory, otherwise use a memory map on disk.

processesint, None or ‘serial’

Number of processes to use for parallel resampling, if None use maximal processes available, if ‘serial’ process in serial.

verbosebool

If True, display progress information.

Deprecated since version 2.1.0: The following arguments are deprecated and will be removed in version 3.0.0:

  • source (now original)

  • sink (now resampled)

  • source_shape (now original_shape)

  • sink_shape (now resampled_shape)

  • source_resolution (now original_resolution)

  • sink_resolution (now resampled_resolution)

Returns

resampledarray or str

The data or filename of resampled sink.

Notes

  • Resolutions are assumed to be given for the axes of the intrinsic orientation of the data and reference (as when viewed by ImageJ).

  • Orientation: permutation of 1,2,3 with potential sign, indicating which axes map onto the reference axes, a negative sign indicates reversal of that particular axes.

  • Only a minimal set of information to determine the resampling parameter has to be given, e.g. original_shape or the original source and resampled_shape.

  • The resampling is done by iterating two-dimensional resampling steps.

resample_factor(original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None, discretize=True, consistent=True)[source]#

Calculate scaling factors for the resampling.

Arguments

original_shapetuple or None

Optional value of the shape of the data array to be resampled.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalstr, array or None

Optional source to be resampled used to determine missing resampling information.

resampled: str, array or None

Optional source of the resampled data used to determine missing resampling information.

orientationtuple

Orientation as specified.

discretizebool

If True and sufficient shape information is given, discretize the shapes.

consistent:

If True, recalculate resolutions to match the discrete shapes.

Deprecated since version 2.1.0: The following arguments are deprecated and will be removed in version 3.0.0:

  • source (now original)

  • sink (now resampled)

  • source_shape (now original_shape)

  • sink_shape (now resampled_shape)

  • source_resolution (now original_resolution)

  • sink_resolution (now resampled_resolution)

Returns

original_resolutiontuple or None

Value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Value of the resolution of the resampled data array.

See also

resample

For more details.

ClearMap.Alignment.orientation

resample_information(original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None, discretize=True, consistent=True)[source]#

Convert resampling information to standard form.

This function takes in various optional parameters related to the original and resampled data, and returns a tuple containing the original shape, resampled shape, original resolution, resampled resolution, and orientation in a standard format.

Arguments

original_shapetuple or None

Optional value of the shape of the data array to be resampled.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalstr, array or None

Optional source to be resampled used to determine missing resampling information.

resampled: str, array or None

Optional source of the resampled data used to determine missing resampling information.

orientationtuple

Orientation as specified.

discretizebool

If True and sufficient shape information is given, discretize the shapes.

consistent:

If True, recalculate resolutions to match the discrete shapes.

Returns

original_shapetuple or None

Value of the shape of the data array to be resampled

resampled_shapetuple or None

Value of the shape of the resampled data array.

original_resolutiontuple or None

Value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Value of the resolution of the resampled data array.

orientationtuple

Orientation in standard formatting.

See also

resample

Function that performs the actual resampling based on the information provided.

resample_inverse(resampled, original=None, original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, orientation=None, axes_order=None, method='memmap', interpolation='linear', processes=None, verbose=True, workspace=None)[source]#

Resample data inversely to resample() routine.

Arguments

resampled: str, array or None

Data array to be inversely resampled.

originalstr, array or None

Optional sink for the inversely resampled array.

original_shapetuple or None

Optional value for the shape of the original data array.

resampled_shapetuple or None

Optional value of the shape of the resampled data array. Determined by the shape of the resampled source by default.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

orientationtuple or None

Orientation specification.

interpolationstr

Interpolation method to use. Available methods are ‘linear’, ‘nearest’, ‘area’.

axes_orderlist of tuples of int or None

The axes pairs along which to resample the data at each step. If None, this is determined automatically. For a FileList source, setting the first tuple should point to axis not indicating files. If ‘size’ the axis order is determined automatically to maximally reduce the size of the array in each resampling step. If ‘order’ the axis order is chosen automatically to optimize io speed.

method‘shared’ or ‘memmap’

Method to handle intermediate resampling results. If ‘shared’ use shared memory, otherwise use a memory map on disk.

processesint, None or ‘serial’

Number of processes to use for parallel resampling, if None use maximal processes available, if ‘serial’ process in serial.

verbosebool

If True, display progress information.

Returns

resampledarray or str

Data or file name of inversely resampled image.

Notes

  • All arguments, except source and sink should be passed as resample() to invert the resampling.

resample_points(original_points, resampled_points=None, original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None)[source]#

Transform point coordinates according to resampling specifications.

Arguments

original_pointsstr, array or None

Data array source to be resampled.

resampled_points: str, array or None

Optional sink for the resampled points

original_shapetuple or None

Optional value for the shape of the data array to be resampled. Determined by the shape of the original source by default.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalarray or str

Optional original source data used to infer resampling specifications.

resampledarray or str

Optional resampled source data used to infer resampling specifications.

orientationtuple or None

Orientation specification.

Deprecated since version 2.1.0: The following arguments are deprecated and will be removed in version 3.0.0:

  • source (now original_points)

  • sink (now resampled_points)

  • source_shape (now original_shape)

  • sink_shape (now resampled_shape)

  • source_resolution (now original_resolution)

  • sink_resolution (now resampled_resolution)

Returns

resampledarray or str

The array or filename of resampled points.

Notes

  • The resampling of points here corresponds to he resampling of a data array in resample().

  • The arguments should be passed exactly as in resample() except for the additional original_points and resampled_points.

resample_points_inverse(resampled_points, original_points=None, original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None)[source]#

Transform point coordinates inversely according to resampling specifications.

Arguments

resampled_points: str, array or None

Optional source of the resampled points to be resampled inversely.

original_pointsstr, array or None

Data array sink for inversely resampled points.

original_shapetuple or None

Optional value for the shape of the data array to be resampled. Determined by the shape of the original source by default.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalarray or str

Optional original source data used to infer resampling specifications.

resampledarray or str

Optional resampled source data used to infer resampling specifications.

orientationtuple or None

Orientation specification.

Returns

resampledarray or str

The array or filename of resampled points.

Notes

  • The resampling of points here corresponds to he resampling of a data array in resample().

  • The arguments should be passed exactly as in resample() except for the additional original_points and resampled_points.

resample_resolution(original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None, discretize=True, consistent=True)[source]#

Calculate resolutions for original and resampled data.

Arguments

original_shapetuple or None

Optional value of the shape of the data array to be resampled.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalstr, array or None

Optional source to be resampled used to determine missing resampling information.

resampled: str, array or None

Optional source of the resampled data used to determine missing resampling information.

orientationtuple

Orientation as specified.

discretizebool

If True and sufficient shape information is given, discretize the shapes.

consistent:

If True, recalculate resolutions to match the discrete shapes.

Returns

original_resolutiontuple or None

Value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Value of the resolution of the resampled data array.

See also

resample

For more details.

ClearMap.Alignment.orientation

resample_resolution_from_shape(original_shape, resampled_shape, original_resolution, orientation=None)[source]#

Calculate the resampled resolution given shape information.

Arguments

original_shapetuple

Shape of the data array to be resampled.

resampled_shapetuple

Resolution of the resampled data array.

original_resolutiontuple

Resolution of the data array to be resampled.

orientationtuple

Orientation specifications.

Returns

resampled_resolutiontuple or None

The resolution of the resampled data array.

resample_shape(original_shape=None, resampled_shape=None, original_resolution=None, resampled_resolution=None, original=None, resampled=None, orientation=None, consistent=True)[source]#

Calculate the resampled shape.

Arguments

original_shapetuple or None

Optional value of the shape of the data array to be resampled.

resampled_shapetuple or None

Optional value of the shape of the resampled data array.

original_resolutiontuple or None

Optional value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Optional value of the resolution of the resampled data array.

originalstr, array or None

Optional source to be resampled used to determine missing resampling information.

resampled: str, array or None

Optional source of the resampled data used to determine missing resampling information.

orientationtuple

Orientation as specified.

consistent:

If True, recalculate resolutions to match the discrete shapes.

Returns

original_shapetuple or None

Value of the shape of the data array to be resampled

resampled_shapetuple or None

Value of the shape of the resampled data array.

original_resolutiontuple or None

Value of the resolution of the data array to be resampled.

resampled_resolutiontuple or None

Value of the resolution of the resampled data array.

See also

resample

For more details.

ClearMap.Alignment.orientation

resample_shape_from_resolution(original_shape, original_resolution, resampled_resolution, orientation=None, discretize=True)[source]#

Calculate the resampled shape given resolution information.

Arguments

original_shapetuple

Shape of the data array to be resampled.

original_resolutiontuple

Resolution of the data array to be resampled.

resampled_resolutiontuple

Resolution of the resampled data array.

orientationtuple

Orientation specifications.

discretizebool

If True, return next largest integer values.

Returns

resampled_shapetuple or None

The shape of the resampled data array.