nifti1_io
|
main collection of nifti1 i/o routines More...
Functions | |
void | nifti_disp_lib_hist (void) |
void | nifti_disp_lib_version (void) |
nifti_image * | nifti_image_read_bricks (const char *hname, int nbricks, const int *blist, nifti_brick_list *NBL) |
int | nifti_update_dims_from_array (nifti_image *nim) |
int | nifti_image_load_bricks (nifti_image *nim, int nbricks, const int *blist, nifti_brick_list *NBL) |
void | nifti_free_NBL (nifti_brick_list *NBL) |
int | valid_nifti_brick_list (nifti_image *nim, int nbricks, const int *blist, int disp_error) |
int | nifti_disp_matrix_orient (const char *mesg, mat44 mat) |
char * | nifti_strdup (const char *str) |
char * | nifti_datatype_string (int dt) |
int | nifti_is_inttype (int dt) |
char * | nifti_units_string (int uu) |
char * | nifti_xform_string (int xx) |
char * | nifti_intent_string (int ii) |
char * | nifti_slice_string (int ss) |
char * | nifti_orientation_string (int ii) |
void | nifti_datatype_sizes (int datatype, int *nbyper, int *swapsize) |
mat44 | nifti_quatern_to_mat44 (float qb, float qc, float qd, float qx, float qy, float qz, float dx, float dy, float dz, float qfac) |
void | nifti_mat44_to_quatern (mat44 R, float *qb, float *qc, float *qd, float *qx, float *qy, float *qz, float *dx, float *dy, float *dz, float *qfac) |
mat44 | nifti_mat44_inverse (mat44 R) |
mat44 | nifti_make_orthog_mat44 (float r11, float r12, float r13, float r21, float r22, float r23, float r31, float r32, float r33) |
mat33 | nifti_mat33_inverse (mat33 R) |
float | nifti_mat33_determ (mat33 R) |
float | nifti_mat33_rownorm (mat33 A) |
float | nifti_mat33_colnorm (mat33 A) |
mat33 | nifti_mat33_mul (mat33 A, mat33 B) |
mat33 | nifti_mat33_polar (mat33 A) |
void | nifti_mat44_to_orientation (mat44 R, int *icod, int *jcod, int *kcod) |
void | nifti_swap_2bytes (size_t n, void *ar) |
void | nifti_swap_4bytes (size_t n, void *ar) |
void | nifti_swap_8bytes (size_t n, void *ar) |
void | nifti_swap_16bytes (size_t n, void *ar) |
void | nifti_swap_Nbytes (size_t n, int siz, void *ar) |
void | swap_nifti_header (struct nifti_1_header *h, int is_nifti) |
int | nifti_swap_as_analyze (nifti_analyze75 *h) |
void | old_swap_nifti_header (struct nifti_1_header *h, int is_nifti) |
int | nifti_get_filesize (const char *pathname) |
size_t | nifti_get_volsize (const nifti_image *nim) |
int | nifti_fileexists (const char *fname) |
int | nifti_is_complete_filename (const char *fname) |
int | nifti_validfilename (const char *fname) |
char * | nifti_find_file_extension (const char *name) |
int | nifti_is_gzfile (const char *fname) |
int | nifti_compiled_with_zlib (void) |
char * | nifti_makebasename (const char *fname) |
void | nifti_set_debug_level (int level) |
void | nifti_set_skip_blank_ext (int skip) |
void | nifti_set_allow_upper_fext (int allow) |
char * | nifti_findhdrname (const char *fname) |
char * | nifti_findimgname (const char *fname, int nifti_type) |
char * | nifti_makehdrname (const char *prefix, int nifti_type, int check, int comp) |
char * | nifti_makeimgname (const char *prefix, int nifti_type, int check, int comp) |
int | nifti_set_filenames (nifti_image *nim, const char *prefix, int check, int set_byte_order) |
int | nifti_type_and_names_match (nifti_image *nim, int show_warn) |
int | is_valid_nifti_type (int nifti_type) |
int | nifti_is_valid_datatype (int dtype) |
int | nifti_set_type_from_names (nifti_image *nim) |
int | is_nifti_file (const char *hname) |
int | disp_nifti_1_header (const char *info, const nifti_1_header *hp) |
nifti_image * | nifti_convert_nhdr2nim (struct nifti_1_header nhdr, const char *fname) |
znzFile | nifti_image_open (const char *hname, char *opts, nifti_image **nim) |
Read in NIFTI-1 or ANALYZE-7.5 file (pair) header information into a nifti_image struct. More... | |
nifti_1_header * | nifti_read_header (const char *hname, int *swapped, int check) |
int | nifti_hdr_looks_good (const nifti_1_header *hdr) |
nifti_image * | nifti_image_read (const char *hname, int read_data) |
Read a nifti header and optionally the data, creating a nifti_image. More... | |
nifti_image * | nifti_read_ascii_image (znzFile fp, char *fname, int flen, int read_data) |
int | nifti_add_extension (nifti_image *nim, const char *data, int len, int ecode) |
int | valid_nifti_extensions (const nifti_image *nim) |
int | nifti_is_valid_ecode (int ecode) |
int | nifti_image_load (nifti_image *nim) |
Load the image blob into a previously initialized nifti_image. More... | |
size_t | nifti_read_buffer (znzFile fp, void *dataptr, size_t ntot, nifti_image *nim) |
void | nifti_image_unload (nifti_image *nim) |
void | nifti_image_free (nifti_image *nim) |
int | nifti_free_extensions (nifti_image *nim) |
void | nifti_image_infodump (const nifti_image *nim) |
size_t | nifti_write_buffer (znzFile fp, const void *buffer, size_t numbytes) |
int | nifti_write_all_data (znzFile fp, nifti_image *nim, const nifti_brick_list *NBL) |
nifti_image * | nifti_simple_init_nim (void) |
nifti_1_header * | nifti_make_new_header (const int arg_dims[], int arg_dtype) |
nifti_image * | nifti_make_new_nim (const int dims[], int datatype, int data_fill) |
struct nifti_1_header | nifti_convert_nim2nhdr (const nifti_image *nim) |
int | nifti_copy_extensions (nifti_image *nim_dest, const nifti_image *nim_src) |
int | nifti_extension_size (nifti_image *nim) |
void | nifti_set_iname_offset (nifti_image *nim) |
znzFile | nifti_image_write_hdr_img (nifti_image *nim, int write_data, const char *opts) |
znzFile | nifti_image_write_hdr_img2 (nifti_image *nim, int write_opts, const char *opts, znzFile imgfile, const nifti_brick_list *NBL) |
znzFile | nifti_write_ascii_image (nifti_image *nim, const nifti_brick_list *NBL, const char *opts, int write_data, int leave_open) |
void | nifti_image_write (nifti_image *nim) |
void | nifti_image_write_bricks (nifti_image *nim, const nifti_brick_list *NBL) |
nifti_image * | nifti_copy_nim_info (const nifti_image *src) |
char * | nifti_image_to_ascii (const nifti_image *nim) |
int | nifti_short_order (void) |
nifti_image * | nifti_image_from_ascii (const char *str, int *bytes_read) |
int | nifti_nim_is_valid (nifti_image *nim, int complain) |
int | nifti_nim_has_valid_dims (nifti_image *nim, int complain) |
int | nifti_read_collapsed_image (nifti_image *nim, const int dims [8], void **data) |
int | nifti_read_subregion_image (nifti_image *nim, int *start_index, int *region_size, void **data) |
int * | nifti_get_intlist (int nvals, const char *str) |
int | nifti_datatype_from_string (const char *name) |
char * | nifti_datatype_to_string (int dtype) |
int | nifti_datatype_is_valid (int dtype, int for_nifti) |
int | nifti_test_datatype_sizes (int verb) |
int | nifti_disp_type_list (int which) |
main collection of nifti1 i/o routines
The library history can be viewed via "nifti_tool -nifti_hist".
The library version can be viewed via "nifti_tool -nifti_ver".
#define ERREX | ( | msg | ) |
#define ERREX | ( | msg | ) |
#define ERREX | ( | msg | ) |
#define QSTR | ( | nam, | |
ml | |||
) |
int disp_nifti_1_header | ( | const char * | info, |
const nifti_1_header * | hp | ||
) |
display the contents of the nifti_1_header (send to stdout)
info | if non-NULL, print this character string |
hp | pointer to nifti_1_header |
int is_nifti_file | ( | const char * | hname | ) |
Determine if this is a NIFTI-formatted file.
int is_valid_nifti_type | ( | int | nifti_type | ) |
check whether the given type is on the "approved" list
The code is valid if it is non-negative, and does not exceed NIFTI_MAX_FTYPE.
int nifti_add_extension | ( | nifti_image * | nim, |
const char * | data, | ||
int | len, | ||
int | ecode | ||
) |
nifti_add_extension - add an extension, with a copy of the data
Add an extension to the nim->ext_list array. Fill this extension with a copy of the data, noting the length and extension code.
nim | - nifti_image to add extension to |
data | - raw extension data |
length | - length of raw extension data |
ecode | - extension code |
int nifti_compiled_with_zlib | ( | void | ) |
return whether the given library was compiled with HAVE_ZLIB set
nifti_image* nifti_convert_nhdr2nim | ( | struct nifti_1_header | nhdr, |
const char * | fname | ||
) |
convert a nifti_1_header into a nift1_image
struct nifti_1_header nifti_convert_nim2nhdr | ( | const nifti_image * | nim | ) |
convert a nifti_image structure to a nifti_1_header struct
No allocation is done, this should be used via structure copy. As in:
nifti_1_header my_header; my_header = nifti_convert_nim2nhdr(my_nim_pointer);
nifti_image* nifti_copy_nim_info | ( | const nifti_image * | src | ) |
copy the nifti_image structure, without data
Duplicate the structure, including fname, iname and extensions. Leave the data pointer as NULL.
int nifti_datatype_from_string | ( | const char * | name | ) |
Given a NIFTI_TYPE string, such as "NIFTI_TYPE_INT16", return the corresponding integral type code. The type code is the macro value defined in nifti1.h.
int nifti_datatype_is_valid | ( | int | dtype, |
int | for_nifti | ||
) |
Determine whether dtype is a valid NIFTI_TYPE.
DT_UNKNOWN is considered invalid
The only difference 'for_nifti' makes is that DT_BINARY should be invalid for a NIfTI dataset.
void nifti_datatype_sizes | ( | int | datatype, |
int * | nbyper, | ||
int * | swapsize | ||
) |
Given a datatype code, set number of bytes per voxel and the swapsize.
datatype | nifti1 datatype code |
nbyper | pointer to return value: number of bytes per voxel |
swapsize | pointer to return value: size of swap blocks |
The swapsize is set to 0 if this datatype doesn't ever need swapping.
char* nifti_datatype_string | ( | int | dt | ) |
Return a pointer to a string holding the name of a NIFTI datatype.
dt | NIfTI-1 datatype |
char* nifti_datatype_to_string | ( | int | dtype | ) |
Given a NIFTI_TYPE value, such as NIFTI_TYPE_INT16, return the corresponding macro label as a string. The dtype code is the macro value defined in nifti1.h.
void nifti_disp_lib_hist | ( | void | ) |
display the nifti library module history (via stdout)
void nifti_disp_lib_version | ( | void | ) |
display the nifti library version (via stdout)
int nifti_disp_matrix_orient | ( | const char * | mesg, |
mat44 | mat | ||
) |
display the orientation from the quaternian fields
mesg | if non-NULL, display this message first |
mat | the matrix to convert to "nearest" orientation |
int nifti_disp_type_list | ( | int | which | ) |
Display the nifti_type_list table.
if which == 1 : display DT_* if which == 2 : display NIFTI_TYPE* else : display all
int nifti_extension_size | ( | nifti_image * | nim | ) |
compute the total size of all extensions
Note that each esize includes 4 bytes for ecode, 4 bytes for esize, and the bytes used for the data. Each esize also needs to be a multiple of 16, so it may be greater than the sum of its 3 parts.
int nifti_fileexists | ( | const char * | fname | ) |
simple check for file existence
char* nifti_find_file_extension | ( | const char * | name | ) |
check the end of the filename for a valid nifti extension
Valid extensions are currently .nii, .hdr, .img, .nia, or any of them followed by .gz. Note that '.' is part of the extension.
Uppercase extensions are also valid, but not mixed case.
char* nifti_findhdrname | ( | const char * | fname | ) |
check current directory for existing header file
If fname has an uppercase extension, check for uppercase files.
NB: it allocates memory for hdrname which should be freed when no longer required
char* nifti_findimgname | ( | const char * | fname, |
int | nifti_type | ||
) |
check current directory for existing image file
fname | filename to check for nifti_type for dataset - this determines whether to first check for ".nii" or ".img" (since both may exist) |
If fname has a valid, uppercase extension, apply all extensions as uppercase.
NB: it allocates memory for the image filename, which should be freed when no longer required
int nifti_free_extensions | ( | nifti_image * | nim | ) |
free the nifti extensions
void nifti_free_NBL | ( | nifti_brick_list * | NBL | ) |
nifti_free_NBL - free all pointers and clear structure
note: this does not presume to free the structure pointer
int nifti_get_filesize | ( | const char * | pathname | ) |
return the size of a file, in bytes
changed to return int, -1 means no file or error 20 Dec 2004 [rickr]
int* nifti_get_intlist | ( | int | nvals, |
const char * | str | ||
) |
Get an integer list in the range 0..(nvals-1), from the character string str. If we call the output pointer fred, then fred[0] = number of integers in the list (> 0), and fred[i] = i-th integer in the list for i=1..fred[0]. If on return, fred == NULL or fred[0] == 0, then something is wrong, and the caller must deal with that.
Syntax of input string:
(borrowed, with permission, from thd_intlist.c)
size_t nifti_get_volsize | ( | const nifti_image * | nim | ) |
return the total volume size, in bytes
This is computed as nvox * nbyper.
int nifti_hdr_looks_good | ( | const nifti_1_header * | hdr | ) |
decide if this nifti_1_header structure looks reasonable
Check dim[0], dim[1], sizeof_hdr, and datatype. Check magic string for "n+1". Maybe more tests will follow.
void nifti_image_free | ( | nifti_image * | nim | ) |
free 'everything' about a nifti_image struct (including the passed struct)
free (only fields which are not NULL):
nifti_image* nifti_image_from_ascii | ( | const char * | str, |
int * | bytes_read | ||
) |
Take an XML-ish ASCII string and create a NIFTI image header to match.
NULL is returned if enough information isn't present in the input string.
void nifti_image_infodump | ( | const nifti_image * | nim | ) |
Print to stdout some info about a nifti_image struct.
int nifti_image_load | ( | nifti_image * | nim | ) |
Load the image blob into a previously initialized nifti_image.
This function is used to read the image from disk. It should be used after a function such as nifti_image_read(), so that the nifti_image structure is already initialized.
nim | pointer to a nifti_image (previously initialized) |
int nifti_image_load_bricks | ( | nifti_image * | nim, |
int | nbricks, | ||
const int * | blist, | ||
nifti_brick_list * | NBL | ||
) |
Load the image data from disk into an already-prepared image struct.
nim | - initialized nifti_image, without data |
nbricks | - the length of blist (must be 0 if blist is NULL) |
blist | - an array of xyz volume indices to read (can be NULL) |
NBL | - pointer to struct where resulting data will be stored |
If blist is NULL, read all sub-bricks.
NOTE: it is likely that another function will copy the data pointers out of NBL, in which case the only pointer the calling function will want to free is NBL->bricks (not each NBL->bricks[i]).
znzFile nifti_image_open | ( | const char * | hname, |
char * | opts, | ||
nifti_image ** | nim | ||
) |
Read in NIFTI-1 or ANALYZE-7.5 file (pair) header information into a nifti_image struct.
znzFile nifti_image_open( char *hname, char *opts , nifti_image **nim)
hname | filename of dataset .hdr or .nii file |
opts | options string for opening the header file |
nim | pointer to pointer to nifti_image struct (this routine allocates the nifti_image struct) |
nifti_image* nifti_image_read | ( | const char * | hname, |
int | read_data | ||
) |
Read a nifti header and optionally the data, creating a nifti_image.
hname | filename of the nifti dataset |
read_data | Flag, true=read data blob, false=don't read blob. |
nifti_image* nifti_image_read_bricks | ( | const char * | hname, |
int | nbricks, | ||
const int * | blist, | ||
nifti_brick_list * | NBL | ||
) |
nifti_image_read_bricks - read nifti data as array of bricks
13 Dec 2004 [rickr]
hname | - filename of dataset to read (must be valid) |
nbricks | - number of sub-bricks to read (if blist is valid, nbricks must be > 0) |
blist | - list of sub-bricks to read (can be NULL; if NULL, read complete dataset) |
NBL | - pointer to empty nifti_brick_list struct (must be a valid pointer) |
By default, this function will read the nifti dataset and break the data into a list of nt*nu*nv*nw sub-bricks, each having size nx*ny*nz elements. That is to say, instead of reading the entire dataset as a single array, break it up into sub-bricks (volumes), each of size nx*ny*nz elements.
Note: in the returned nifti_image, nu, nv and nw will always be 1. The intention of this function is to collapse the dataset into a single array of volumes (of length nbricks or nt*nu*nv*nw).
If 'blist' is valid, it is taken to be a list of sub-bricks, of length 'nbricks'. The data will still be separated into sub-bricks of size nx*ny*nz elements, but now 'nbricks' sub-bricks will be returned, of the caller's choosing via 'blist'.
E.g. consider a dataset with 12 sub-bricks (numbered 0..11), and the following code:
{ nifti_brick_list NB_orig, NB_select; nifti_image * nim_orig, * nim_select; int blist[5] = { 7, 0, 5, 5, 9 };
nim_orig = nifti_image_read_bricks("myfile.nii", 0, NULL, &NB_orig); nim_select = nifti_image_read_bricks("myfile.nii", 5, blist, &NB_select); }
Here, nim_orig gets the entire dataset, where NB_orig.nbricks = 12. But nim_select has NB_select.nbricks = 5.
Note that the first case is not quite the same as just calling the nifti_image_read function, as here the data is separated into sub-bricks.
Note that valid blist elements are in [0..nt*nu*nv*nw-1], or written [ 0 .. (dim[4]*dim[5]*dim[6]*dim[7] - 1) ].
Note that, as is the case with all of the reading functions, the data will be allocated, read in, and properly byte-swapped, if necessary.
char* nifti_image_to_ascii | ( | const nifti_image * | nim | ) |
Dump the information in a NIFTI image header to an XML-ish ASCII string that can later be converted back into a NIFTI header in nifti_image_from_ascii().
The resulting string can be free()-ed when you are done with it.
Strings that we don't control (filenames, etc.) that might contain "weird" characters (like quotes) are "escaped":
void nifti_image_unload | ( | nifti_image * | nim | ) |
Unload the data in a nifti_image struct, but keep the metadata.
void nifti_image_write | ( | nifti_image * | nim | ) |
Write a nifti_image to disk.
Since data is properly byte-swapped upon reading, it is assumed to be in the byte-order of the current CPU at write time. Thus, nim->byte_order should match that of the current CPU. Note that the nifti_set_filenames() function takes the flag, set_byte_order.
The following fields of nim affect how the output appears:
void nifti_image_write_bricks | ( | nifti_image * | nim, |
const nifti_brick_list * | NBL | ||
) |
similar to nifti_image_write, but data is in NBL struct, not nim->data
znzFile nifti_image_write_hdr_img | ( | nifti_image * | nim, |
int | write_data, | ||
const char * | opts | ||
) |
write the nifti_image dataset to disk, optionally including data
This is just a front-end for nifti_image_write_hdr_img2.
nim | nifti_image to write to disk |
write_data | write options (see nifti_image_write_hdr_img2) |
opts | file open options ("wb" from nifti_image_write) |
znzFile nifti_image_write_hdr_img2 | ( | nifti_image * | nim, |
int | write_opts, | ||
const char * | opts, | ||
znzFile | imgfile, | ||
const nifti_brick_list * | NBL | ||
) |
This writes the header (and optionally the image data) to file
If the image data file is left open it returns a valid znzFile handle. It also uses imgfile as the open image file is not null, and modifies it inside.
nim | nifti_image to write to disk |
write_opts | flags whether to write data and/or close file (see below) |
opts | file-open options, probably "wb" from nifti_image_write() |
imgfile | optional open znzFile struct, for writing image data (may be NULL) |
NBL | optional nifti_brick_list, containing the image data (may be NULL) |
Values for write_opts mode are based on two binary flags ( 0/1 for no-write/write data, and 0/2 for close/leave-open files ) :
char* nifti_intent_string | ( | int | ii | ) |
Return a pointer to a string holding the name of a NIFTI intent type.
ii | NIfTI-1 intent code |
int nifti_is_complete_filename | ( | const char * | fname | ) |
return whether the filename is valid
Note: uppercase extensions are now valid. 27 Apr 2009 [rickr]
The name is considered valid if the file basename has length greater than zero, AND one of the valid nifti extensions is provided.
"myimage" | 0 | "myimage.tif" | 0 | "myimage.tif.gz" | 0 | "myimage.nii" | 1 | ".nii" | 0 | ".myhiddenimage" | 0 | ".myhiddenimage.nii" | 1 |
int nifti_is_gzfile | ( | const char * | fname | ) |
return whether the filename ends in ".gz"
int nifti_is_inttype | ( | int | dt | ) |
Determine if the datatype code dt is an integer type (1=YES, 0=NO).
int nifti_is_valid_datatype | ( | int | dtype | ) |
int nifti_is_valid_ecode | ( | int | ecode | ) |
check whether the extension code is valid
nifti_1_header* nifti_make_new_header | ( | const int | arg_dims[], |
int | arg_dtype | ||
) |
basic initialization of a nifti_1_header struct (with given dimensions)
Return an allocated nifti_1_header struct, based on the given dimensions and datatype.
arg_dims | : optional dim[8] array (default {3,1,1,1,0,0,0,0}) |
arg_dtype | : optional datatype (default DT_FLOAT32) |
nifti_image* nifti_make_new_nim | ( | const int | dims[], |
int | datatype, | ||
int | data_fill | ||
) |
basic creation of a nifti_image struct
Create a nifti_image from the given dimensions and data type. Optinally, allocate zero-filled data.
dims | : optional dim[8] (default {3,1,1,1,0,0,0,0}) |
datatype | : optional datatype (default DT_FLOAT32) |
data_fill | : if flag is set, allocate zero-filled data for image |
mat44 nifti_make_orthog_mat44 | ( | float | r11, |
float | r12, | ||
float | r13, | ||
float | r21, | ||
float | r22, | ||
float | r23, | ||
float | r31, | ||
float | r32, | ||
float | r33 | ||
) |
Input 9 floats and make an orthgonal mat44 out of them.
Each row is normalized, then nifti_mat33_polar() is used to orthogonalize them. If row #3 (r31,r32,r33) is input as zero, then it will be taken to be the cross product of rows #1 and #2.
This function can be used to create a rotation matrix for transforming an oblique volume to anatomical coordinates. For this application:
The first 2 rows can be taken from the DICOM attribute (0020,0037) "Image Orientation (Patient)".
After forming the rotation matrix, the complete affine transformation from (i,j,k) grid indexes to (x,y,z) spatial coordinates can be computed by multiplying each column by the appropriate grid spacing:
and by then placing the center (x,y,z) coordinates of voxel (0,0,0) into the column #4 (R.m[0][3],R.m[1][3],R.m[2][3]).
char* nifti_makebasename | ( | const char * | fname | ) |
duplicate the filename, while clearing any extension
This allocates memory for basename which should eventually be freed.
char* nifti_makehdrname | ( | const char * | prefix, |
int | nifti_type, | ||
int | check, | ||
int | comp | ||
) |
creates a filename for storing the header, based on nifti_type
prefix | - this will be copied before the suffix is added |
nifti_type | - determines the extension, unless one is in prefix |
check | - check for existence (fail condition) |
comp | - add .gz for compressed name |
Note that if prefix provides a file suffix, nifti_type is not used.
NB: this allocates memory which should be freed
char* nifti_makeimgname | ( | const char * | prefix, |
int | nifti_type, | ||
int | check, | ||
int | comp | ||
) |
creates a filename for storing the image, based on nifti_type
prefix | - this will be copied before the suffix is added |
nifti_type | - determines the extension, unless provided by prefix |
check | - check for existence (fail condition) |
comp | - add .gz for compressed name |
Note that if prefix provides a file suffix, nifti_type is not used.
NB: it allocates memory which should be freed
float nifti_mat33_colnorm | ( | mat33 | A | ) |
compute the max column norm of a 3x3 matrix
float nifti_mat33_determ | ( | mat33 | R | ) |
compute the determinant of a 3x3 matrix
polar decomposition of a 3x3 matrix
This finds the closest orthogonal matrix to input A (in both the Frobenius and L2 norms).
Algorithm is that from NJ Higham, SIAM J Sci Stat Comput, 7:1160-1174.
float nifti_mat33_rownorm | ( | mat33 | A | ) |
compute the max row norm of a 3x3 matrix
Compute the inverse of a bordered 4x4 matrix.
You can check for this by examining the [3][3] element, which will be 1.0 for the normal case and 0.0 for the bad case.
The input matrix should have the form: [ r11 r12 r13 v1 ] [ r21 r22 r23 v2 ] [ r31 r32 r33 v3 ] [ 0 0 0 1 ]
void nifti_mat44_to_orientation | ( | mat44 | R, |
int * | icod, | ||
int * | jcod, | ||
int * | kcod | ||
) |
compute the (closest) orientation from a 4x4 ijk->xyz tranformation matrix
Input: 4x4 matrix that transforms (i,j,k) indexes to (x,y,z) coordinates, where +x=Right, +y=Anterior, +z=Superior. (Only the upper-left 3x3 corner of R is used herein.) Output: 3 orientation codes that correspond to the closest "standard" anatomical orientation of the (i,j,k) axes. Method: Find which permutation of (x,y,z) has the smallest angle to the (i,j,k) axes directions, which are the columns of the R matrix. Errors: The codes returned will be zero.
For example, an axial volume might get return values of *icod = NIFTI_R2L (i axis is mostly Right to Left) *jcod = NIFTI_P2A (j axis is mostly Posterior to Anterior) *kcod = NIFTI_I2S (k axis is mostly Inferior to Superior)
void nifti_mat44_to_quatern | ( | mat44 | R, |
float * | qb, | ||
float * | qc, | ||
float * | qd, | ||
float * | qx, | ||
float * | qy, | ||
float * | qz, | ||
float * | dx, | ||
float * | dy, | ||
float * | dz, | ||
float * | qfac | ||
) |
Given the 3x4 upper corner of the matrix R, compute the quaternion parameters that fit it.
int nifti_nim_has_valid_dims | ( | nifti_image * | nim, |
int | complain | ||
) |
validate nifti dimensions
rely on dim[] as the master
int nifti_nim_is_valid | ( | nifti_image * | nim, |
int | complain | ||
) |
validate the nifti_image
char* nifti_orientation_string | ( | int | ii | ) |
Return a pointer to a string holding the name of a NIFTI orientation.
ii | orientation code |
mat44 nifti_quatern_to_mat44 | ( | float | qb, |
float | qc, | ||
float | qd, | ||
float | qx, | ||
float | qy, | ||
float | qz, | ||
float | dx, | ||
float | dy, | ||
float | dz, | ||
float | qfac | ||
) |
Given the quaternion parameters (etc.), compute a transformation matrix.
See comments in nifti1.h for details.
If qx=qy=qz=0, dx=dy=dz=1, then the output is a rotation matrix. For qfac >= 0, the rotation is proper. For qfac < 0, the rotation is improper.
nifti_image* nifti_read_ascii_image | ( | znzFile | fp, |
char * | fname, | ||
int | flen, | ||
int | read_data | ||
) |
nifti_read_ascii_image - process as a type-3 .nia image file
return NULL on failure
NOTE: this is NOT part of the NIFTI-1 standard
size_t nifti_read_buffer | ( | znzFile | fp, |
void * | dataptr, | ||
size_t | ntot, | ||
nifti_image * | nim | ||
) |
read ntot bytes of data from an open file and byte swaps if necessary
note that nifti_image is required for information on datatype, bsize (for any needed byte swapping), etc.
This function does not allocate memory, so dataptr must be valid.
int nifti_read_collapsed_image | ( | nifti_image * | nim, |
const int | dims[8], | ||
void ** | data | ||
) |
read a nifti image, collapsed across dimensions according to dims[8]
This function may be used to read parts of a nifti dataset, such as the time series for a single voxel, or perhaps a slice. It is similar to nifti_image_load(), though the passed 'data' parameter is used for returning the image, not nim->data.
nim | given nifti_image struct, corresponding to the data file |
dims | given list of dimensions (see below) |
data | pointer to data pointer (if *data is NULL, data will be allocated, otherwise not) |
Example: given nim->dim[8] = { 4, 64, 64, 21, 80, 1, 1, 1 } (4-D dataset)
if dims[8] = { 0, 5, 4, 17, -1, -1, -1, -1 } -> read time series for voxel i,j,k = 5,4,17
if dims[8] = { 0, -1, -1, -1, 17, -1, -1, -1 } -> read single volume at time point 17
Example: given nim->dim[8] = { 6, 64, 64, 21, 80, 4, 3, 1 } (6-D dataset)
if dims[8] = { 0, 5, 4, 17, -1, 2, 1, 0 } -> read time series for the voxel i,j,k = 5,4,17, and dim 5,6 = 2,1
if dims[8] = { 0, 5, 4, -1, -1, 0, 0, 0 } -> read time series for slice at i,j = 5,4, and dim 5,6,7 = 0,0,0 (note that dims[7] is not relevant, but must be 0 or -1)
If *data is NULL, then *data will be set as a pointer to new memory, allocated here for the resulting collapsed image data.
e.g. { int dims[8] = { 0, 5, 4, 17, -1, -1, -1, -1 }; void * data = NULL; ret_val = nifti_read_collapsed_image(nim, dims, &data); if( ret_val > 0 ){ process_time_series(data); if( data != NULL ) free(data); } }
NOTE: If *data is not NULL, then it will be assumed that it points to valid memory, sufficient to hold the results. This is done for speed and possibly repeated calls to this function.
e.g. { int dims[8] = { 0, -1, -1, -1, -1, -1, -1, -1 }; void * data = NULL; for( zslice = 0; zslice < nzslices; zslice++ ){ dims[3] = zslice; ret_val = nifti_read_collapsed_image(nim, dims, &data); if( ret_val > 0 ) process_slice(zslice, data); } if( data != NULL ) free(data); }
nifti_1_header* nifti_read_header | ( | const char * | hname, |
int * | swapped, | ||
int | check | ||
) |
return an allocated and filled nifti_1_header struct
Read the binary header from disk, and swap bytes if necessary.
hname | name of file containing header |
swapped | if not NULL, return whether header bytes were swapped |
check | flag to check for invalid nifti_1_header |
int nifti_read_subregion_image | ( | nifti_image * | nim, |
int * | start_index, | ||
int * | region_size, | ||
void ** | data | ||
) |
read an arbitrary subregion from a nifti image
This function may be used to read a single arbitary subregion of any rectangular size from a nifti dataset, such as a small 5x5x5 subregion around the center of a 3D image.
nim | given nifti_image struct, corresponding to the data file |
start_index | the index location of the first voxel that will be returned |
region_size | the size of the subregion to be returned |
data | pointer to data pointer (if *data is NULL, data will be allocated, otherwise not) |
Example: given nim->dim[8] = {3, 64, 64, 64, 1, 1, 1, 1 } (3-D dataset)
if start_index[7] = { 29, 29, 29, 0, 0, 0, 0 } and region_size[7] = { 5, 5, 5, 1, 1, 1, 1 } -> read 5x5x5 region starting with the first voxel location at (29,29,29)
NOTE: If *data is not NULL, then it will be assumed that it points to valid memory, sufficient to hold the results. This is done for speed and possibly repeated calls to this function.
void nifti_set_allow_upper_fext | ( | int | allow | ) |
set nifti's global allow_upper_fext flag 28 Apr 2009 [rickr]
explicitly set to 0 or 1
void nifti_set_debug_level | ( | int | level | ) |
set nifti's global debug level, for status reporting
int nifti_set_filenames | ( | nifti_image * | nim, |
const char * | prefix, | ||
int | check, | ||
int | set_byte_order | ||
) |
create and set new filenames, based on prefix and image type
nim | pointer to nifti_image in which to set filenames |
prefix | (required) prefix for output filenames |
check | check for previous existence of filename (existence is an error condition) |
set_byte_order | flag to set nim->byteorder here (this is probably a logical place to do so) |
void nifti_set_iname_offset | ( | nifti_image * | nim | ) |
set the nifti_image iname_offset field, based on nifti_type
void nifti_set_skip_blank_ext | ( | int | skip | ) |
set nifti's global skip_blank_ext flag 5 Sep 2006 [rickr]
explicitly set to 0 or 1
int nifti_set_type_from_names | ( | nifti_image * | nim | ) |
set the nifti_type field based on fname and iname
Note that nifti_type is changed only when it does not match the filenames.
int nifti_short_order | ( | void | ) |
get the byte order for this CPU
nifti_image* nifti_simple_init_nim | ( | void | ) |
basic initialization of a nifti_image struct (to a 1x1x1 image)
char* nifti_slice_string | ( | int | ss | ) |
Return a pointer to a string holding the name of a NIFTI slice_code.
ss | NIfTI-1 slice order code |
char* nifti_strdup | ( | const char * | str | ) |
duplicate the given string (alloc length+1)
void nifti_swap_16bytes | ( | size_t | n, |
void * | ar | ||
) |
swap 16 bytes at a time from the given list of n sets of 16 bytes
void nifti_swap_2bytes | ( | size_t | n, |
void * | ar | ||
) |
swap each byte pair from the given list of n pairs
Due to alignment of structures at some architectures (e.g. on ARM), stick to char varaibles. Fixes http://bugs.debian.org/446893 Yaroslav debia n@on eruss ian. com
void nifti_swap_4bytes | ( | size_t | n, |
void * | ar | ||
) |
swap 4 bytes at a time from the given list of n sets of 4 bytes
void nifti_swap_8bytes | ( | size_t | n, |
void * | ar | ||
) |
swap 8 bytes at a time from the given list of n sets of 8 bytes
perhaps use this style for the general Nbytes, as Yaroslav suggests
int nifti_swap_as_analyze | ( | nifti_analyze75 * | h | ) |
Byte swap as an ANALYZE 7.5 header
return non-zero on failure
void nifti_swap_Nbytes | ( | size_t | n, |
int | siz, | ||
void * | ar | ||
) |
based on siz, call the appropriate nifti_swap_Nbytes() function
int nifti_test_datatype_sizes | ( | int | verb | ) |
Only as a test, verify that the new nifti_type_list table matches the the usage of nifti_datatype_sizes (which could be changed to use the table, if there were interest).
return the number of errors (so 0 is success, as usual)
int nifti_type_and_names_match | ( | nifti_image * | nim, |
int | show_warn | ||
) |
check whether nifti_type matches fname and iname for the nifti_image
nim | given nifti_image |
show_warn | if set, print a warning message for any mis-match |
char* nifti_units_string | ( | int | uu | ) |
Return a pointer to a string holding the name of a NIFTI units type.
uu | NIfTI-1 unit code |
int nifti_update_dims_from_array | ( | nifti_image * | nim | ) |
nifti_update_dims_from_array - update nx, ny, ... from nim->dim[]
Fix all the dimension information, based on a new nim->dim[].
Note: we assume that dim[0] will not increase.
Check for updates to pixdim[], dx,..., nx,..., nvox, ndim, dim[0].
int nifti_validfilename | ( | const char * | fname | ) |
return whether the filename is valid
Allow uppercase extensions as valid. 27 Apr 2009 [rickr] Any .gz extension case must match the base extension case.
The name is considered valid if its length is positive, excluding any nifti filename extension.
"myimage" | 1 | "myimage" "myimage.tif" | 1 | "myimage.tif" "myimage.tif.gz" | 1 | "myimage.tif" "myimage.nii" | 1 | "myimage" ".nii" | 0 | <ERROR - basename has zero length> ".myhiddenimage" | 1 | ".myhiddenimage" ".myhiddenimage.nii | 1 | ".myhiddenimage"
int nifti_write_all_data | ( | znzFile | fp, |
nifti_image * | nim, | ||
const nifti_brick_list * | NBL | ||
) |
write the nifti_image data to file (from nim->data or from NBL)
If NBL is not NULL, write the data from that structure. Otherwise, write it out from nim->data. No swapping is done here.
fp | : File pointer |
nim | : nifti_image corresponding to the data |
NBL | : optional source of write data (if NULL use nim->data) |
Note: the nifti_image byte_order is set as that of the current CPU. This is because such a conversion was made to the data upon reading, while byte_order was not set (so the programs would know what format the data was on disk). Effectively, since byte_order should match what is on disk, it should bet set to that of the current CPU whenever new filenames are assigned.
znzFile nifti_write_ascii_image | ( | nifti_image * | nim, |
const nifti_brick_list * | NBL, | ||
const char * | opts, | ||
int | write_data, | ||
int | leave_open | ||
) |
write a nifti_image to disk in ASCII format
char* nifti_xform_string | ( | int | xx | ) |
Return a pointer to a string holding the name of a NIFTI transform type.
xx | NIfTI-1 xform code |
void old_swap_nifti_header | ( | struct nifti_1_header * | h, |
int | is_nifti | ||
) |
OLD VERSION of swap_nifti_header (left for undo/compare operations)
Byte swap NIFTI-1 file header in various places and ways.
If is_nifti is nonzero, will also swap the NIFTI-specific components of the header; otherwise, only the components common to NIFTI and ANALYZE will be swapped.
void swap_nifti_header | ( | struct nifti_1_header * | h, |
int | is_nifti | ||
) |
Byte swap NIFTI-1 file header in various places and ways.
If is_nifti, swap all (even UNUSED) fields of NIfTI header. Else, swap as a nifti_analyze75 struct.
int valid_nifti_brick_list | ( | nifti_image * | nim, |
int | nbricks, | ||
const int * | blist, | ||
int | disp_error | ||
) |
valid_nifti_brick_list - check sub-brick list for image
This function verifies that nbricks and blist are appropriate for use with this nim, based on the dimensions.
nim | nifti_image to check against |
nbricks | number of brick indices in blist |
blist | list of brick indices to check in nim |
disp_error | if this flag is set, report errors to user |
int valid_nifti_extensions | ( | const nifti_image * | nim | ) |
for each extension, check code, size and data pointer