Ejemplo n.º 1
0
def from_origin_and_columns(origin, colvectors, shape, output_coords):
    """
    Return a CoordinateMap representing a slice based on a given origin, 
    a pair of direction vectors which span the slice, and a shape.

    :Parameters:
        origin : the corner of the output coordinates, i.e. the [0]*ndimin
                 point
        colvectors : the steps in each voxel direction
        shape : how many steps in each voxel direction
        output_coords : a CoordinateSystem for the output

    :Returns: `CoordinateMap`
    """
    colvectors = np.asarray(colvectors)
    nout = colvectors.shape[1]
    nin = colvectors.shape[0]

    f = np.zeros((nout+1,nin+1))
    for i in range(nin):
        f[0:nout,i] = colvectors[i]
    f[0:nout,-1] = origin
    f[nout, nin] = 1.

    input_coords = CoordinateSystem(['i%d' % d for d in range(len(shape))], 
                                    'slice', output_coords.coord_dtype)

    g = Affine(f, input_coords, output_coords)
    return ArrayCoordMap.from_shape(g, shape)
Ejemplo n.º 2
0
def bounding_box(coordmap, shape):
    """
    Determine a valid bounding box from a CoordinateMap
    and a shape.

    Parameters
    ----------
    coordmap : CoordinateMap or AffineTransform
       Containing mapping between voxel coordinates implied by `shape` and
       physical coordinates.
    shape : sequence of int
       shape implying array

    Returns
    -------
    limits : (N,) tuple of (2,) tuples of float
       minimum and maximum coordinate values in output space (range) of
       `coordmap`. N is given by coordmap.ndim[1].

    Examples
    --------
    >>> A = AffineTransform.from_start_step('ijk', lps_output_coordnames, [2,4,6], [1,3,5])
    >>> bounding_box(A, (30,40,20))
    ((2.0, 31.0), (4.0, 121.0), (6.0, 101.0))
    """
    e = ArrayCoordMap.from_shape(coordmap, shape)
    return tuple([(r.min(), r.max()) for r in e.transposed_values])
Ejemplo n.º 3
0
def bounding_box(coordmap, shape):
    """
    Determine a valid bounding box from a CoordinateMap 
    and a shape.

    Parameters
    ----------
    coordmap : CoordinateMap or AffineTransform

    shape : (int)
       Tuple of ints.
       
    Returns
    -------

    limits : (float)
       Tuple of floats.


    Examples
    --------

    >>> A = AffineTransform.from_start_step('ijk', lps_output_coordnames, [2,4,6], [1,3,5])
    >>> bounding_box(A, (30,40,20))
    ([2.0, 31.0], [4.0, 121.0], [6.0, 101.0])
    >>> 

    """
    e = ArrayCoordMap.from_shape(coordmap, shape)
    return tuple([[r.min(), r.max()] for r in e.transposed_values])
Ejemplo n.º 4
0
def bounding_box(coordmap, shape):
    """
    Determine a valid bounding box from a CoordinateMap instance.

    :Parameters:
        coordmap : `CoordinateMap`

    """
    e = ArrayCoordMap.from_shape(coordmap, shape)
    return [[r.min(), r.max()] for r in e.transposed_values]
Ejemplo n.º 5
0
def get_coordmap_array(coordmap, shape):
    '''
    See: http://nipy.org/nipy/stable/api/generated/nipy.core.reference.array_coords.html?highlight=grid#nipy.core.reference.array_coords.Grid
    '''
    return ArrayCoordMap(coordmap, shape)