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.
-
format_orientation
(orientation, inverse=False, default=None)[source]¶ Convert orientation to standard format.
Arguments
- orientationtuple or str
The orientation specification.
- inversebool
If True, invert orientation.
- defaultobject
The default value if orientation is None;
Returns
- orientationtuple of ints
The orientation sequence.
See also
None()
-
inverse_orientation
(orientation)[source]¶ Returns the inverse orientation taking axis inversions into account.
Arguments
- orientationtuple or str
The orientation specification.
Returns
- orientationtuple
The inverse orientation sequence.
See also
None()
-
orient_resolution
(resolution, orientation, inverse=False)[source]¶ Permutes a resolution tuple according to the given orientation.
Arguments
- resolutiontuple
The resolution specification.
- orientationtuple or str
The orientation specification.
- inversebool
If True, invert the orientation.
Returns
- resolutiontuple
The re-oriented resolution sequence.
See also
None()
-
orient_shape
(shape, orientation, inverse=False)[source]¶ Permutes a shape according to the given orientation.
Arguments
- shapetuple
The shape specification.
- orientationtuple or str
The orientation specification.
- inversebool
If True, invert the orientation.
Returns
- shapetuple
The oriented shape tuple.
See also
None()
-
orientation_to_permuation
(orientation, inverse=False)[source]¶ Extracts the permuation from an orientation.
Arguments
- orientationtuple or str
The orientation specification.
- inversebool
If True, return inverse permutation.
Returns
- permuationtuple of ints
The premutation sequence.
See also
None()
-
resample
(source, sink=None, orientation=None, sink_shape=None, source_resolution=None, sink_resolution=None, interpolation='linear', axes_order=None, method='shared', processes=None, verbose=True)[source]¶ Resample data of source in new shape/resolution and orientation.
Arguments
- sourcestr or array
The source to be resampled.
- sinkstr or None
The sink for the resampled image.
- orientationtuple or None:
The orientation specified by permuation and change in sign of (1,2,3).
- sink_shapetuple or None
The target shape of the resampled sink.
- source_resolutiontuple or None
The resolution of the source (in length per pixel).
- sink_resolutiontuple or None
The resolution of the resampled source (in length per pixel).
- interpolationstr
The method to use for interpolating to the resmapled array.
- axis_orderstr, list of tuples of int or None
The axes pairs along which to resample the data at each step. If None, this is detertmined 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 resmapling step. If ‘order’ the axis order is chosed 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 avaialable, if ‘serial’ process in serial.
- verbosebool
If True, display progress information.
Returns
- sinkarray 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: permuation 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. source_shape and sink_shape.
The resampling is done by iterating two dimensional resampling steps.
-
resample_factor
(source_shape, sink_shape=None, source_resolution=None, sink_resolution=None, orientation=None)[source]¶ Calculate scaling factors for resampling.
Arguments
- source_shapetuple
The shape the source.
- sink_shapetuple or None
The shape of the resmapled sink.
- source_resolutiontuple or None
The resolution of the source.
- sink_resolutiontuple or None
The resolution of the sink.
- orientationtuple or str
The re-orientation specification.
Returns
- factortuple
The resampling factor along the axes of the source.
See also
None()
-
resample_inverse
(source, sink=None, resample_source=None, resample_sink=None, orientation=None, source_shape=None, source_resolution=None, sink_shape=None, sink_resolution=None, axes_order=None, method='memmap', interpolation='linear', processes=None, verbose=True, **args)[source]¶ Resample data inversely to
resample()
routine.Arguments
- sourcestr, array
Source to be inversly resampled (e.g. sink in
resample()
).- sinkstr or None
Sink to write the inversly resampled image to.
- resample_sourcestr, array or None
Optional source in
resample()
.- resmaple_sink: str, array or None
Optional sink used in
resample()
.- orientationtuple
Orientation as specified as in
resample()
.- source_shapetuple or None
Optional value of source_shape as in
resample()
.- source_resolutiontuple or None
Optional value of source_resolution as in
resample()
.- sink_resolutiontuple or None
Optional value of sink_resolution as in
resample()
.- processing_directorystr or None
Optional directory in which to perform resmapling in parallel. If None, a temporary directry will be created.
- axis_orderlist of tuples of int or None
The axes pairs along which to resample the data as in
resample()
.- method‘shared’ or ‘memmap’
Method to handle intermediate resampling results. If ‘shared’ use shared memory, otherwise use a memory map on disk.
- interpolationstr
Method to use for interpolating to the resmapled image.
- processes int or None
Number of processes to use for parallel resampling.
- verbosebool
If True, print progress information.
Returns
- resampledarray or str
Data or file name of inversly resampled image.
Notes
All arguments, except source and sink should be passed as
resample()
to invert the resmapling.
-
resample_points
(source, sink=None, resample_source=None, resample_sink=None, orientation=None, source_shape=None, sink_shape=None, source_resolution=None, sink_resolution=None, **args)[source]¶ Resample points from original coordiantes to resampled ones.
Arguments
- sourcestr or array
Points to be resampled.
- sinkstr or None
Sink for the resmapled point coordinates.
- orientationtuple
Orientation as specified in
resample()
.- resample_sourcestr, array or None
Optional source as in
resample()
.- resample_sink: str, array or None
Optional sink used in
resample()
.- source_shapetuple or None
Optional value of source_shape as in
resample()
.- source_resolutiontuple or None
Optional value of source_resolution as in
resample()
.- sink_resolutiontuple or None
Optional value of sink_resolution as in
resample()
.
Returns
- resmapledarray or str
Sink for the resampled point coordinates.
Notes
The resampling of points here corresponds to he resampling of an image in
resample()
.The arguments should be passed exactly as in
resample()
except soure and sink that point to the point sources. Use resample_source and resmaple_sink to pass the source and sink values used inresample()
.
-
resample_points_inverse
(source, sink=None, resample_source=None, resample_sink=None, orientation=None, source_shape=None, sink_shape=None, source_resolution=None, sink_resolution=None, **args)[source]¶ Resample points from original coordiantes to resampled ones.
Arguments
- sourcestr or array
Points to be resampled inversely.
- sinkstr or None
Sink for the inversly resmapled points.
- resample_sourcestr, array or None
Optional source as in
resample()
.- resample_sink: str, array or None
Optional sink used in
resample()
.- orientationtuple
Orientation as specified in
resample()
.- source_shapetuple or None
Optional value of source_shape as in
resample()
.- source_resolutiontuple or None
Optional value of source_resolution as in
resample()
.- sink_resolutiontuple or None
Optional value of sink_resolution as in
resample()
.
Returns
- resmapledarray or str
Sink for the inversly resampled point coordinates.
Notes
The resampling of points here corresponds to the inverse resampling of an image in
resample()
, i.e. to func:resample_inverseThe arguments should be passed exactly as in
resample()
except source and sink that point to the point sources. Use resample_source and resmaple_sink to pass the source and sink values used inresample()
.
-
resample_shape
(source_shape, sink_shape=None, source_resolution=None, sink_resolution=None, orientation=None)[source]¶ Calculate scaling factors and data shapes for resampling.
Arguments
- source_shapetuple
The shape the source.
- sink_shapetuple or None
The shape of the resmapled sink.
- source_resolutiontuple or None
The resolution of the source.
- sink_resolutiontuple or None
The resolution of the sink.
- orientationtuple or str
The re-orientation specification.
Returns
- source_shapetuple
The shape of the source.
- sink_shapetuple
The shape of the sink.
- source_resolutiontuple or None
The resolution of the source.
- sink_resolutiontuple or None
The resolution of the sink.
See also
None()