ants.utils.matrix_image
Functions
|
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations. |
|
Unmasks rows of a matrix and writes as images |
|
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations. |
|
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations. |
|
Unmasks rows of a matrix and writes as images |
|
converts a matrix to a ND image. |
|
Convert a timeseries image into a matrix. |
- image_list_to_matrix(image_list, mask=None, sigma=None, epsilon=0.5)
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
image_list (
listofANTsImage types) – images to convert to ndarraymask (
ANTsImage (optional)) – Mask image, voxels in the mask (>= epsilon) are placed in the matrix. If None, the first image in image_list is thresholded at its mean value to create a mask.sigma (
scaler (optional)) – smoothing factorepsilon (
scalar) – threshold for mask, values >= epsilon are included in the mask.
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- images_from_matrix(data_matrix, mask)
Unmasks rows of a matrix and writes as images
ANTsR function: matrixToImages
- Parameters:
data_matrix (
numpy.ndarray) – each row corresponds to an image array should have number of columns equal to non-zero voxels in the maskmask (
ants.core.ANTsImage) – image containing a binary mask. Rows of the matrix are unmasked and written as images. The mask defines the output image space
- Return type:
listofANTsImage types
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> msk = ants.get_mask( img ) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3], msk ) >>> ilist = ants.matrix_to_images( mat, msk )
- images_to_matrix(image_list, mask=None, sigma=None, epsilon=0.5)[source]
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
image_list (
listofANTsImage types) – images to convert to ndarraymask (
ANTsImage (optional)) – Mask image, voxels in the mask (>= epsilon) are placed in the matrix. If None, the first image in image_list is thresholded at its mean value to create a mask.sigma (
scaler (optional)) – smoothing factorepsilon (
scalar) – threshold for mask, values >= epsilon are included in the mask.
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- matrix_from_images(image_list, mask=None, sigma=None, epsilon=0.5)
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
image_list (
listofANTsImage types) – images to convert to ndarraymask (
ANTsImage (optional)) – Mask image, voxels in the mask (>= epsilon) are placed in the matrix. If None, the first image in image_list is thresholded at its mean value to create a mask.sigma (
scaler (optional)) – smoothing factorepsilon (
scalar) – threshold for mask, values >= epsilon are included in the mask.
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- matrix_to_images(data_matrix, mask)[source]
Unmasks rows of a matrix and writes as images
ANTsR function: matrixToImages
- Parameters:
data_matrix (
numpy.ndarray) – each row corresponds to an image array should have number of columns equal to non-zero voxels in the maskmask (
ants.core.ANTsImage) – image containing a binary mask. Rows of the matrix are unmasked and written as images. The mask defines the output image space
- Return type:
listofANTsImage types
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> msk = ants.get_mask( img ) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3], msk ) >>> ilist = ants.matrix_to_images( mat, msk )
- matrix_to_timeseries(image, matrix, mask=None)[source]
converts a matrix to a ND image.
ANTsR function: matrix2timeseries
- Parameters:
image (
reference ND image) –matrix (
matrixtoconverttoimage) –mask (
mask image defining voxelsofinterest) –
- Return type:
ants.core.ANTsImage
Example
>>> import ants >>> img = ants.make_image( (10,10,10,5 ) ) >>> mask = ants.ndimage_to_list( img )[0] * 0 >>> mask[ 4:8, 4:8, 4:8 ] = 1 >>> mat = ants.timeseries_to_matrix( img, mask = mask ) >>> img2 = ants.matrix_to_timeseries( img, mat, mask)
- timeseries_to_matrix(image, mask=None)[source]
Convert a timeseries image into a matrix.
ANTsR function: timeseries2matrix
- Parameters:
image (
image whose slices we converttoa matrix. E.g. a 3D imageofsize) – x by y by z will convert to a z by x*y sized matrixmask (
ANTsImage (optional)) – image containing binary mask. voxels in the mask are placed in the matrix
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
Example
>>> import ants >>> img = ants.make_image( (10,10,10,5 ) ) >>> mat = ants.timeseries_to_matrix( img )