Пример #1
0
    def getExtent(self):
        """Returns the shape of the dataimage.

        :Returns:
          tuple: Tuple with the size in voxel/timepoints.
            The order of dimensions is (x,y,z,t,u,v,w). If the image has less
            dimensions than 7 the return tuple will be shortened accordingly.

            Please note that the order of dimensions is different from the tuple
            returned by calling `NiftiImage.data.shape`!

        .. seealso::
          :meth:`~nifti.format.NiftiFormat.getVolumeExtent`,
          :meth:`~nifti.format.NiftiFormat.getTimepoints`,
          :attr:`~nifti.format.NiftiFormat.extent`
        """
        # wrap dim array in nifti image struct
        dims_array = ncl.intArray_frompointer(self.__nimg.dim)
        dims = [ dims_array[i] for i in range(8) ]

        return tuple( dims[1:dims[0]+1] )
Пример #2
0
    def _updateNimgFromArray(self, val):
        """Update all relevant items in the nimg struct to match a given
        array's properties.

        We can only savely modify the respective nimg items since the data
        array is disconnected from the struct all the time.

        .. warning::
          This is an internal method. Neither its availability nor its API is
          guarenteed.
        """
        # convert dtype and store in struct
        self.raw_nimg.datatype = Ndtype2niftidtype(val)

        # wrap dims
        dim = ncl.intArray_frompointer(self.raw_nimg.dim)

        # make sure there are no zeros in the dim vector
        # especially not in #4 as FSLView doesn't like that
        target_dim = N.ones(7, dtype='int')

        # reverse the array shape
        target_dim[:len(val.shape)] = val.shape[::-1]

        # set number of dims
        dim[0] = len(val.shape)

        # assign remaining dim vector
        for i in range(7):
            dim[i+1] = target_dim[i]

        # expand dim vector
        self.raw_nimg.ndim = dim[0]
        self.raw_nimg.nx = dim[1]
        self.raw_nimg.ny = dim[2]
        self.raw_nimg.nz = dim[3]
        self.raw_nimg.nt = dim[4]
        self.raw_nimg.nu = dim[5]
        self.raw_nimg.nv = dim[6]
        self.raw_nimg.nw = dim[7]