nifti1_io.h
来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· C头文件 代码 · 共 458 行 · 第 1/2 页
H
458 行
/** \file nifti1_io.h
\brief Data structures for using nifti1_io API.
- Written by Bob Cox, SSCC NIMH
- Revisions by Rick Reynolds, SSCC NIMH
*/
#ifndef _NIFTI_IO_HEADER_
#define _NIFTI_IO_HEADER_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#ifndef DONT_INCLUDE_ANALYZE_STRUCT
#define DONT_INCLUDE_ANALYZE_STRUCT /*** not needed herein ***/
#endif
#include "nifti1.h" /*** NIFTI-1 header specification ***/
#include <znzlib.h>
/*=================*/
#ifdef __cplusplus
extern "C" {
#endif
/*=================*/
/*****===================================================================*****/
/***** File nifti1_io.h == Declarations for nifti1_io.c *****/
/*****...................................................................*****/
/***** This code is released to the public domain. *****/
/*****...................................................................*****/
/***** Author: Robert W Cox, SSCC/DIRP/NIMH/NIH/DHHS/USA/EARTH *****/
/***** Date: August 2003 *****/
/*****...................................................................*****/
/***** Neither the National Institutes of Health (NIH), nor any of its *****/
/***** employees imply any warranty of usefulness of this software for *****/
/***** any purpose, and do not assume any liability for damages, *****/
/***** incidental or otherwise, caused by any use of this document. *****/
/*****===================================================================*****/
/*
Modified by: Mark Jenkinson (FMRIB Centre, University of Oxford, UK)
Date: July/August 2004
Mainly adding low-level IO and changing things to allow gzipped files
to be read and written
Full backwards compatability should have been maintained
Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
Date: December 2004
Modified and added many routines for I/O.
*/
/********************** Some sample data structures **************************/
typedef struct { /** 4x4 matrix struct **/
float m[4][4] ;
} mat44 ;
typedef struct { /** 3x3 matrix struct **/
float m[3][3] ;
} mat33 ;
/*...........................................................................*/
/*! \enum analyze_75_orient_code
* \brief Old-style analyze75 orientation
* codes.
*/
typedef enum _analyze75_orient_code {
a75_transverse_unflipped = 0,
a75_coronal_unflipped = 1,
a75_sagittal_unflipped = 2,
a75_transverse_flipped = 3,
a75_coronal_flipped = 4,
a75_sagittal_flipped = 5,
a75_orient_unknown = 6
} analyze_75_orient_code;
/*! \struct nifti_image
\brief High level data structure for open nifti datasets in the
nifti1_io API. Note that this structure is not part of the
nifti1 format definition; it is used to implement one API
for reading/writing formats in the nifti1 format.
*/
typedef struct { /*!< Image storage struct **/
int ndim ; /*!< last dimension greater than 1 (1..7) */
int nx ; /*!< dimensions of grid array */
int ny ; /*!< dimensions of grid array */
int nz ; /*!< dimensions of grid array */
int nt ; /*!< dimensions of grid array */
int nu ; /*!< dimensions of grid array */
int nv ; /*!< dimensions of grid array */
int nw ; /*!< dimensions of grid array */
int dim[8] ; /*!< dim[0]=ndim, dim[1]=nx, etc. */
size_t nvox ; /*!< number of voxels = nx*ny*nz*...*nw */
int nbyper ; /*!< bytes per voxel, matches datatype */
int datatype ; /*!< type of data in voxels: DT_* code */
float dx ; /*!< grid spacings */
float dy ; /*!< grid spacings */
float dz ; /*!< grid spacings */
float dt ; /*!< grid spacings */
float du ; /*!< grid spacings */
float dv ; /*!< grid spacings */
float dw ; /*!< grid spacings */
float pixdim[8] ; /*!< pixdim[1]=dx, etc. */
float scl_slope ; /*!< scaling parameter - slope */
float scl_inter ; /*!< scaling parameter - intercept */
float cal_min ; /*!< calibration parameter, minimum */
float cal_max ; /*!< calibration parameter, maximum */
int qform_code ; /*!< codes for (x,y,z) space meaning */
int sform_code ; /*!< codes for (x,y,z) space meaning */
int freq_dim ; /*!< indexes (1,2,3, or 0) for MRI */
int phase_dim ; /*!< directions in dim[]/pixdim[] */
int slice_dim ; /*!< directions in dim[]/pixdim[] */
int slice_code ; /*!< code for slice timing pattern */
int slice_start ; /*!< index for start of slices */
int slice_end ; /*!< index for end of slices */
float slice_duration ; /*!< time between individual slices */
/*! quaternion transform parameters
[when writing a dataset, these are used for qform, NOT qto_xyz] */
float quatern_b , quatern_c , quatern_d ,
qoffset_x , qoffset_y , qoffset_z ,
qfac ;
mat44 qto_xyz ; /*!< qform: transform (i,j,k) to (x,y,z) */
mat44 qto_ijk ; /*!< qform: transform (x,y,z) to (i,j,k) */
mat44 sto_xyz ; /*!< sform: transform (i,j,k) to (x,y,z) */
mat44 sto_ijk ; /*!< sform: transform (x,y,z) to (i,j,k) */
float toffset ; /*!< time coordinate offset */
int xyz_units ; /*!< dx,dy,dz units: NIFTI_UNITS_* code */
int time_units ; /*!< dt units: NIFTI_UNITS_* code */
int nifti_type ; /*!< 0==ANALYZE, 1==NIFTI-1 (1 file),
2==NIFTI-1 (2 files),
3==NIFTI-ASCII (1 file) */
int intent_code ; /*!< statistic type (or something) */
float intent_p1 ; /*!< intent parameters */
float intent_p2 ; /*!< intent parameters */
float intent_p3 ; /*!< intent parameters */
char intent_name[16] ; /*!< optional description of intent data */
char descrip[80] ; /*!< optional text to describe dataset */
char aux_file[24] ; /*!< auxiliary filename */
char *fname ; /*!< header filename (.hdr or .nii) */
char *iname ; /*!< image filename (.img or .nii) */
int iname_offset ; /*!< offset into iname where data starts */
int swapsize ; /*!< swap unit in image data (might be 0) */
int byteorder ; /*!< byte order on disk (MSB_ or LSB_FIRST) */
void *data ; /*!< pointer to data: nbyper*nvox bytes */
int num_ext ; /*!< number of extensions in ext_list */
nifti1_extension * ext_list ; /*!< array of extension structs (with data) */
analyze_75_orient_code analyze75_orient; /*!< for old analyze files, orient */
} nifti_image ;
/* struct for return from nifti_image_read_bricks() */
typedef struct {
int nbricks; /* the number of allocated pointers in 'bricks' */
size_t bsize; /* the length of each data block, in bytes */
void ** bricks; /* array of pointers to data blocks */
} nifti_brick_list;
/*****************************************************************************/
/*--------------- Prototypes of functions defined in this file --------------*/
char *nifti_datatype_string ( int dt ) ;
char *nifti_units_string ( int uu ) ;
char *nifti_intent_string ( int ii ) ;
char *nifti_xform_string ( int xx ) ;
char *nifti_slice_string ( int ss ) ;
char *nifti_orientation_string( int ii ) ;
int nifti_is_inttype( int dt ) ;
mat44 nifti_mat44_inverse( mat44 R ) ;
mat33 nifti_mat33_inverse( mat33 R ) ;
mat33 nifti_mat33_polar ( mat33 A ) ;
float nifti_mat33_rownorm( mat33 A ) ;
float nifti_mat33_colnorm( mat33 A ) ;
float nifti_mat33_determ ( mat33 R ) ;
mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ;
void nifti_swap_2bytes ( int n , void *ar ) ;
void nifti_swap_4bytes ( int n , void *ar ) ;
void nifti_swap_8bytes ( int n , void *ar ) ;
void nifti_swap_16bytes( int n , void *ar ) ;
void nifti_swap_Nbytes ( int n , int siz , void *ar ) ;
int nifti_datatype_is_valid (int dtype, int for_nifti);
int nifti_datatype_from_string(const char * name);
char * nifti_datatype_to_string (int dtype);
void swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ;
int nifti_get_filesize( const char *pathname ) ;
/* main read/write routines */
nifti_image *nifti_image_read_bricks(const char *hname , int nbricks,
const int *blist, nifti_brick_list * NBL);
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 );
nifti_image *nifti_image_read ( const char *hname , int read_data ) ;
int nifti_image_load ( nifti_image *nim ) ;
void nifti_image_unload ( nifti_image *nim ) ;
void nifti_image_free ( nifti_image *nim ) ;
int nifti_read_collapsed_image( nifti_image * nim, const int dims [8],
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?