ants.core.ants_image_io
Image IO
Functions
|
Create a copy of the given ANTsImage with the same data and info, possibly with a different data type for the image data. |
|
Create a copy of the given ANTsImage with the same data and info, possibly with a different data type for the image data. |
|
Read a set of dicom files in a directory into a single ANTsImage. |
|
Create an ANTsImage object from a numpy array |
|
|
|
Clone an ANTsImage |
|
Read file info from image header |
|
Read an ANTsImage from file |
|
Write an ANTsImage to file |
|
Make an image with given size and voxel values or fill a mask with a vector of voxel values. |
|
Create a new ANTsImage with the same header information, but with a new image array. |
|
Read metadata dictionary from image file. |
- dicom_read(directory, pixeltype='float')[source]
Read a set of dicom files in a directory into a single ANTsImage. The origin of the resulting 3D image will be the origin of the first dicom image read.
- Parameters:
directory (
str) – folder in which all the dicom images exist- Return type:
ants.core.ANTsImage
Example
>>> import ants >>> img = ants.dicom_read('~/desktop/dicom-subject/')
- from_numpy(data, origin=None, spacing=None, direction=None, has_components=False, is_rgb=False)[source]
Create an ANTsImage object from a numpy array
ANTsR function: as.antsImage
- Parameters:
data (
numpy.ndarray) – image data arrayorigin (
tuple/list) – image originspacing (
tuple/list) – image spacingdirection (
list/ndarray) – image directionhas_components (
bool) – whether the image has vector components.is_rgb (
bool) – whether the image is RGB. This implies has_components=True.
- Returns:
image with given data and any given information
- Return type:
ants.core.ANTsImage
- image_clone(image, pixeltype=None)[source]
Clone an ANTsImage
ANTsR function: antsImageClone
- Parameters:
image (
ants.core.ANTsImage) – image to clonepixeltype (
string (optional)) – new datatype for image
- Return type:
ants.core.ANTsImage
- image_header_info(filename)[source]
Read file info from image header
ANTsR function: antsImageHeaderInfo
- image_read(filename, dimension=None, pixeltype='float', reorient=False)[source]
Read an ANTsImage from file
ANTsR function: antsImageRead
- Parameters:
filename (
str) – Name of the file to read the image from.dimension (
int) – Number of dimensions of the image read. This need not be the same as the dimensions of the image in the file. Allowed values: 2, 3, 4. If not provided, the dimension is obtained from the image filepixeltype (
str) – C++ datatype to be used to represent the pixels read. This datatype need not be the same as the datatype used in the file. Options: unsigned char, unsigned int, float, double. Use pixeltype=None to use the datatype in the file if supported. Unsupported datatypes will be converted to float.reorient (
boolean | string) –if True, the image will be reoriented to RPI if it is 3D if False, nothing will happen if string, this should be the 3-letter orientation to which the
input image will reoriented if 3D.
if the image is 2D, this argument is ignored
- Return type:
ants.core.ANTsImage
- image_write(image, filename, ri=False)[source]
Write an ANTsImage to file
ANTsR function: antsImageWrite
- Parameters:
image (
ants.core.ANTsImage) – image to save to filefilename (
str) – name of file to which image will be savedri (
bool) –- if True, return image. This allows for using this function in a pipeline:
>>> img2 = img.smooth_image(2.).image_write(file1, ri=True).threshold_image(0,20).image_write(file2, ri=True)
if False, do not return image
- make_image(shape, voxval=0, spacing=None, origin=None, direction=None, has_components=False, pixeltype='float')[source]
Make an image with given size and voxel values or fill a mask with a vector of voxel values.
ANTsR function: makeImage
- Parameters:
shape (
tuple/ANTsImage) – input image shape (tuple) or a mask (ANTsImage). If a mask, the output image has the same shape as the mask, and the number of voxel values invoxvalshould match the number of positive voxels in the mask. If a tuple, the number of voxel values invoxvalshould match the product of the dimensions in the tuple.voxval (
scalar) – input image value. Either a scalar (single value) to be placed in all voxels, or a vector of with length matching the number of voxels required by the shape argument.spacing (
tuple/list) – image spatial resolution.origin (
tuple/list) – image spatial origin.direction (
list/ndarray) – direction matrix to convert from index to physical space.components (
bool) – whether there are components per pixel or not.pixeltype (
str) – a supported pixel type for ANTsImage.
- Return type:
ants.core.ANTsImage
- new_image_like(image, data)[source]
Create a new ANTsImage with the same header information, but with a new image array.
- Parameters:
data (
numpy.ndarrayorpy::capsule) – New array or pointer for the image. It must have the same shape as the current image data.- Return type:
ants.core.ANTsImage