Utilities used by wiimatch
¶
This module provides utility functions for use by wiimatch
module.
Author: | Mihai Cara (contact: help@stsci.edu) |
---|---|
License: | LICENSE |
-
wiimatch.utils.
create_coordinate_arrays
(image_shape, center=None, image2world=None, center_cs='image')[source]¶ Create a list of coordinate arrays/grids for each dimension in the image shape. This function is similar to
numpy.indices
except it returns the list of arrays in reversed order. In addition, it can center image coordinates to a providedcenter
and also convert image coordinates to world coordinates using providedimage2world
function.Parameters: - image_shape : sequence of int
The shape of the image/grid.
- center : iterable, None, optional
An iterable of length equal to the number of dimensions in
image_shape
that indicates the center of the coordinate system in image coordinates whencenter_cs
is'image'
otherwise center is assumed to be in world coordinates (whencenter_cs
is'world'
). Whencenter
isNone
thencenter
is set to the middle of the “image” ascenter[i]=image_shape[i]//2
. Ifimage2world
is notNone
andcenter_cs
is'image'
, then supplied center will be converted to world coordinates.- image2world : function, None, optional
Image-to-world coordinates transformation function. This function must be of the form
f(x,y,z,...)
and accept a number of argumentsnumpy.ndarray
arguments equal to the dimensionality of images.- center_cs : {‘image’, ‘world’}, optional
Indicates whether
center
is in image coordinates or in world coordinates. This parameter is ignored whencenter
is set toNone
: it is assumed to beFalse
.center_cs
cannot be'world'
whenimage2world
isNone
unlesscenter
isNone
.
Returns: - coord_arrays : list
A list of
numpy.ndarray
coordinate arrays each ofimage_shape
shape.- eff_center : tuple
A tuple of coordinates of the effective center as used in generating coordinate arrays.
- coord_system : {‘image’, ‘world’}
Coordinate system of the coordinate arrays and returned
center
value.
Examples
>>> import wiimatch >>> wiimatch.utils.create_coordinate_arrays((3, 5, 4)) # doctest: +FLOAT_CMP ((array([[[-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.]], [[-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.]], [[-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.], [-1., 0., 1., 2.]]]), array([[[-2., -2., -2., -2.], [-1., -1., -1., -1.], [ 0., 0., 0., 0.], [ 1., 1., 1., 1.], [ 2., 2., 2., 2.]], [[-2., -2., -2., -2.], [-1., -1., -1., -1.], [ 0., 0., 0., 0.], [ 1., 1., 1., 1.], [ 2., 2., 2., 2.]], [[-2., -2., -2., -2.], [-1., -1., -1., -1.], [ 0., 0., 0., 0.], [ 1., 1., 1., 1.], [ 2., 2., 2., 2.]]]), array([[[-2., -2., -2., -2.], [-2., -2., -2., -2.], [-2., -2., -2., -2.], [-2., -2., -2., -2.], [-2., -2., -2., -2.]], [[-1., -1., -1., -1.], [-1., -1., -1., -1.], [-1., -1., -1., -1.], [-1., -1., -1., -1.], [-1., -1., -1., -1.]], [[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]]])), (1.0, 2.0, 2.0), 'image')