Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mrilib.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #ifndef _MCW_MRILIB_HEADER_
00008 #define _MCW_MRILIB_HEADER_
00009 
00010 #define MRILIB_7D
00011 
00012 #define COXEMAIL "rwcox@nih.gov"        /* or /dev/null, if you prefer */
00013 
00014 extern char MRILIB_orients[] ;          /* 12 Mar 2001 */
00015 extern float MRILIB_zoff ;              /* global variables from mri_read.c */
00016 extern float MRILIB_tr ;                /* 03 Dec 2001 */
00017 extern float MRILIB_xoff ;              /* 07 Dec 2001 */
00018 extern float MRILIB_yoff ;
00019 
00020 extern int use_MRILIB_zoff ;            /* 20 Dec 2001 */
00021 extern int use_MRILIB_xoff ;
00022 extern int use_MRILIB_yoff ;
00023 
00024 extern int   use_MRILIB_xcos ;         /* 22 Jul 2002 */
00025 extern int   use_MRILIB_ycos ;
00026 extern int   use_MRILIB_zcos ;
00027 extern float MRILIB_xcos[3] ;
00028 extern float MRILIB_ycos[3] ;
00029 extern float MRILIB_zcos[3] ;
00030 
00031 extern int   use_MRILIB_slicespacing ;  /* 10 Jan 2004 */
00032 extern float MRILIB_slicespacing ;
00033 
00034 /*! Clear the MRILIB globals (which are designed to transmit info from image files to to3d.c). */
00035 
00036 #define CLEAR_MRILIB_globals                              \
00037  do{ MRILIB_orients[0]='\0';                              \
00038      MRILIB_zoff=MRILIB_xoff=MRILIB_yoff=MRILIB_tr=0.0;   \
00039      use_MRILIB_xoff=use_MRILIB_yoff=use_MRILIB_zoff=0;   \
00040      use_MRILIB_xcos=use_MRILIB_ycos=use_MRILIB_zcos=0;   \
00041      use_MRILIB_slicespacing=0;                           \
00042  } while(0)
00043 
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <math.h>
00047 
00048 #include "mcw_malloc.h"  /* 06 Mar 1999 addition */
00049 #include "debugtrace.h"  /* 26 Jan 2001 addition */
00050 #include "Amalloc.h"     /* 09 Dec 2003 addition */
00051 
00052 #ifndef PI
00053 #  define PI 3.14159265358979323846
00054 #endif
00055 
00056 #ifndef WAY_BIG
00057 /*! A big number (anything over this is infinity). */
00058 #  define WAY_BIG 1.e+10
00059 #endif
00060 
00061 #ifndef FLDIF
00062 /*! Are 2 floats significantly different? */
00063 #  define FLDIF(x,y) ( fabs(x-y) > 1.e-4 * (fabs(x)+fabs(y)) )
00064 #endif
00065 
00066 
00067 #ifndef MAX
00068 #  define MAX(a,b) (((a)<(b)) ? (b) : (a))
00069 #endif
00070 
00071 #ifndef MIN
00072 #  define MIN(a,b) (((a)>(b)) ? (b) : (a))
00073 #endif
00074 
00075 #undef DONT_USE_MEMCPY
00076 
00077 /**** define types ****/
00078 
00079 /*! The MRI_byte data type. */
00080 
00081 #ifndef TYPEDEF_byte
00082 #define TYPEDEF_byte
00083 typedef unsigned char byte ;
00084 #endif
00085 
00086 /*! RGBA data type; not used anywhere (yet). */
00087 
00088 #ifndef TYPEDEF_rgba
00089 #define TYPEDEF_rgba
00090 typedef struct { byte r,g,b,a ; } rgba ;  /* 24 Aug 2001 */
00091 #endif
00092 
00093 #define LOAD_rgba(s,rr,gg,bb,aa)   ((s).r=(rr),(s).g=(gg),(s).b=(bb),(s).a=(bb))
00094 #define UNLOAD_rgba(s,rr,gg,bb,aa) ((rr)=(s).r,(gg)=(s).g,(bb)=(s).b,(aa)=(s).a)
00095 
00096 /*! Scale a byte [0..255] to a float in [0..1). */
00097 
00098 #define BYTE_TO_ZONE(b) (0.00392157*(b))
00099 
00100 /*! Scale a float in [0..1] to a byte in [0..255]. */
00101 
00102 #define ZONE_TO_BYTE(z) ((byte)(255.49*(z)))
00103 
00104 /*! Integer flags for different image types.  Sometimes called the "datum". */
00105 
00106 typedef enum MRI_TYPE {
00107          MRI_byte , MRI_short  , MRI_int  ,
00108         MRI_float , MRI_double , MRI_complex , MRI_rgb , MRI_rgba } MRI_TYPE ;
00109 
00110 #define MRI_KIND MRI_TYPE ;   /* to alleviate stupidity */
00111 #define MRI_type MRI_TYPE ;
00112 #define MRI_kind MRI_TYPE ;
00113 
00114 #define MRI_rgbyte MRI_rgb
00115 
00116 /*! The last MRI_TYPE yet defined. */
00117 
00118 #define LAST_MRI_TYPE 7
00119 
00120 /*! String names for MRI_TYPE. */
00121 
00122 static char * MRI_TYPE_name[8] =
00123   { "byte", "short", "int", "float", "double", "complex", "rgb", "RGBA" } ;
00124 
00125 #define MRI_type_name MRI_TYPE_name  /* because I forget */
00126 
00127 #define MRI_TYPE_NAME(iimm) MRI_TYPE_name[(iimm)->kind]  /* 26 Apr 2005 */
00128 
00129 /*! Max value of a byte. */
00130 
00131 #define MRI_maxbyte         255
00132 
00133 /*! Max value of a short. */
00134 
00135 #define MRI_maxshort      32767
00136 
00137 /*! Max value of an int. */
00138 
00139 #define MRI_maxint   2147483647
00140 
00141 /*! Max values for various types, if they have them. */
00142 
00143 static float MRI_TYPE_maxval[7] =
00144   { 255.0 , 32767.0 , 2147483647.0 , 0.0,0.0,0.0 , 255.0 } ;
00145 
00146 /*! Force a float into a short. */
00147 
00148 #define SHORTIZE(xx) (  ((xx) < -32767.0) ? (short)-32767                    \
00149                       : ((xx) >  32767.0) ? (short) 32767 : (short)rint(xx) )
00150 
00151 /*! Force a float into a byte. */
00152 
00153 #define BYTEIZE(xx)  (  ((xx) <   0.0) ? (byte)0                     \
00154                       : ((xx) > 255.0) ? (byte)255 : (byte)rint(xx) )
00155 
00156 /*! Determine if a MRI_TYPE is an integer type. */
00157 
00158 #define MRI_IS_INT_TYPE(typ) ((typ) < 3)
00159 
00160 /*! I suppose that the next C makes this pleonastic. */
00161 
00162 #ifdef _SUNPERF_COMPLEX
00163 # define TYPEDEF_complex
00164 #endif
00165 
00166 #ifndef TYPEDEF_complex
00167 #define TYPEDEF_complex
00168 typedef struct complex { float r , i ; } complex ;
00169 #endif
00170 
00171 /*-------*/
00172 
00173 /*! Triple to hold RGB bytes. */
00174 
00175 #ifndef TYPEDEF_rgbyte
00176 #define TYPEDEF_rgbyte
00177 typedef struct rgbyte { byte r,g,b ; } rgbyte ;  /* 15 Feb 1999 */
00178 
00179 #undef  RGBZEQ
00180 #undef  RGBZAS
00181 #define RGBZEQ(q) ( (q).r==0 && (q).g==0 && (q).b==0 )  /* is == (0,0,0)? */
00182 #define RGBZAS(q) ( (q).r = (q).g = (q).b = 0 )         /* set = (0,0,0). */
00183 #endif
00184 
00185 static rgbyte tEMp_rgbyte_aAa ;
00186 
00187 /*! Convert one RBG triple (rgbyte) to a single int. */
00188 
00189 #define RGBYTE_TO_INT(rgb) ( (rgb).r << 16 | (rgb).g << 8 | (rgb).b )
00190 
00191 /*! Convert one int to a RGB triple (rgbyte). */
00192 
00193 #define INT_TO_RGB(q) ( tEMp_rgbyte_aAa.r = ((q) >> 16) & 0xff , \
00194                         tEMp_rgbyte_aAa.g = ((q) >>  8) & 0xff , \
00195                         tEMp_rgbyte_aAa.b = (q)         & 0xff , tEMp_rgbyte_aAa )
00196 /*-------*/
00197 
00198 /*! A union type to hold all possible MRI_IMAGE types.
00199     This was created before I really understood how to use void *. */
00200 
00201 typedef union MRI_DATA {
00202          byte     *byte_data ;
00203          short    *short_data ;
00204          int      *int_data ;
00205          float    *float_data ;
00206          double   *double_data ;
00207          complex  *complex_data ;
00208          byte     *rgb_data ;      /* Apr 1996: not well supported yet */
00209          rgba     *rgba_data ;     /* Mar 2002 */
00210 } MRI_DATA ;
00211 
00212 /** Mar 1996: Extended to images up to 7D;
00213               Not all routines work with images > 2D --
00214               check top of file for "7D SAFE" comments **/
00215 
00216 #undef USE_MRI_LABELS
00217 #ifdef USE_MRI_LABELS
00218 #  define MRI_LABEL_SIZE 4
00219 #endif
00220 
00221 #define USE_MRI_DELAY   /* 01 Jan 1997 */
00222 #ifdef USE_MRI_DELAY
00223 #  define INPUT_DELAY  1
00224 #  define BSWAP_DELAY  2
00225 #endif
00226 
00227 /*! Stores one image (1D to 7D).
00228     Why 7D, you ask?  Well, I originally only had 2D images here.
00229     When extending AFNI from 3D to 3D+time and buckets, I thought
00230     that I might use 4D images (x,y,z,t) as the basic element.
00231     Instead, I decided to use an array of 3D images (in a THD_datablock),
00232     but by then I'd extended this typedef to allow (x,y,z,t,u,v,w) dimensioned
00233     arrays.  I don't think anyplace ever uses more than 3D images, though.
00234 */
00235 
00236 typedef struct MRI_IMAGE {
00237           int nx ;            /*!< 1st dimension of image */
00238           int ny ;            /*!< 2nd dimension of image (1 for 1D image) */
00239           int nz  ;           /*!< 3rd dimension of image (1 for 2D image) */
00240           int nt ;            /*!< 4th dimension of image (1 for 3D image) */
00241           int nu ;            /*!< 5th dimension of image (1 for 4D image) */
00242           int nv ;            /*!< 6th dimension of image (1 for 5D image) */
00243           int nw  ;           /*!< 7th dimension of image (1 for 6D image) */
00244           int nxy ;           /*!< nx*ny */
00245           int nxyz ;          /*!< nx*ny*nz */
00246           int nxyzt  ;        /*!< nx*ny*nz*nt */
00247           int nvox   ;        /*!< number of voxels total */
00248           int pixel_size ;    /*!< bytes per pixel */
00249 
00250           MRI_TYPE kind ;     /*!< one of the MRI_TYPE codes above */
00251           MRI_DATA im ;       /*!< pointer to actual pixel data */
00252           char *name ;        /*!< string attached; may be NULL; might be filename */
00253 
00254           float dx ;          /*!< physical pixel size, if != 0 */
00255           float dy ;          /*!< physical pixel size, if != 0 */
00256           float dz ;          /*!< physical pixel size, if != 0 */
00257           float dt ;          /*!< physical pixel size, if != 0 */
00258           float du ;          /*!< physical pixel size, if != 0 */
00259           float dv ;          /*!< physical pixel size, if != 0 */
00260           float dw ;          /*!< physical pixel size, if != 0 */
00261           float xo ;          /*!< spatial origin of axis */
00262           float yo ;          /*!< spatial origin of axis */
00263           float zo ;          /*!< spatial origin of axis */
00264           float to ;          /*!< spatial origin of axis */
00265           float uo ;          /*!< spatial origin of axis */
00266           float vo ;          /*!< spatial origin of axis */
00267           float wo ;          /*!< spatial origin of axis */
00268 
00269 #ifdef USE_MRI_LABELS
00270          char xlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00271               ylab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00272               zlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00273               tlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00274               ulab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00275               vlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00276               wlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00277 #endif
00278 
00279 #ifdef USE_MRI_DELAY
00280          char *fname ;   /*!< to read actual image data after delay */
00281          int foffset ;   /*!< offset into fname of image data */
00282          int fondisk ;   /*!< flag to indicate if is on disk (?) */
00283 #endif
00284 
00285          int was_swapped ; /* 07 Mar 2002 */
00286 } MRI_IMAGE ;
00287 
00288 #ifdef USE_MRI_LABELS
00289 /*! Copy auxiliary data from one MRI_IMAGE to another. */
00290 #  define MRI_COPY_AUX(nn,oo)                                           \
00291     ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \
00292       (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \
00293       (nn)->dw = (oo)->dw ,                                             \
00294       (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \
00295       (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \
00296       (nn)->wo = (oo)->wo ,                                             \
00297       strcpy((nn)->xlab,(oo)->xlab) , strcpy((nn)->ylab,(oo)->ylab) ,   \
00298       strcpy((nn)->zlab,(oo)->zlab) , strcpy((nn)->tlab,(oo)->tlab) ,   \
00299       strcpy((nn)->ulab,(oo)->ulab) , strcpy((nn)->vlab,(oo)->vlab) ,   \
00300       strcpy((nn)->wlab,(oo)->wlab) ,                                   \
00301       mri_add_name( (oo)->name , (nn) ) )
00302 #else
00303 #  define MRI_COPY_AUX(nn,oo)                                           \
00304     ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \
00305       (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \
00306       (nn)->dw = (oo)->dw ,                                             \
00307       (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \
00308       (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \
00309       (nn)->wo = (oo)->wo ,                                             \
00310       mri_add_name( (oo)->name , (nn) ) )
00311 #endif
00312 
00313 /*! Check if MRI_IMAGE is 1D (ny=1) */
00314 #define MRI_IS_1D(iq)  ((iq)->ny == 1)
00315 
00316 /*! Check if MRI_IMAGE is 2D (nz=1) */
00317 #define MRI_IS_2D(iq)  ((iq)->ny > 1 && (iq)->nz == 1)
00318 
00319 /*! Check if MRI_IMAGE is 3D (nt=1) */
00320 #define MRI_IS_3D(iq)  ((iq)->nz > 1 && (iq)->nt == 1)
00321 
00322 /*! Check if MRI_IMAGE is 4D (nu=1) */
00323 #define MRI_IS_4D(iq)  ((iq)->nt > 1 && (iq)->nu == 1)
00324 
00325 /*! Return dimensionality of MRI_IMAGE */
00326 #define MRI_DIMENSIONALITY(iq)                     \
00327  ( ((iq)->ny == 1) ? 1 : ((iq)->nz == 1) ? 2 :     \
00328    ((iq)->nt == 1) ? 3 : ((iq)->nu == 1) ? 4 :     \
00329    ((iq)->nv == 1) ? 5 : ((iq)->nw == 1) ? 6 : 7 )
00330 
00331 #define MRI_BYTE_PTR(iq)    ((iq)->im.byte_data)
00332 #define MRI_SHORT_PTR(iq)   ((iq)->im.short_data)
00333 #define MRI_INT_PTR(iq)     ((iq)->im.int_data)
00334 #define MRI_FLOAT_PTR(iq)   ((iq)->im.float_data)
00335 #define MRI_DOUBLE_PTR(iq)  ((iq)->im.double_data)
00336 #define MRI_COMPLEX_PTR(iq) ((iq)->im.complex_data)
00337 #define MRI_RGB_PTR(iq)     ((iq)->im.rgb_data)
00338 #define MRI_RGBA_PTR(iq)    ((iq)->im.rgba_data)
00339 
00340 #define MRI_BYTE_2D(iq,ix,jy)    MRI_BYTE_PTR(iq)[(ix)+(jy)*(iq)->nx]
00341 #define MRI_SHORT_2D(iq,ix,jy)   MRI_SHORT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00342 #define MRI_INT_2D(iq,ix,jy)     MRI_INT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00343 #define MRI_FLOAT_2D(iq,ix,jy)   MRI_FLOAT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00344 #define MRI_DOUBLE_2D(iq,ix,jy)  MRI_DOUBLE_PTR(iq)[(ix)+(jy)*(iq)->nx]
00345 #define MRI_COMPLEX_2D(iq,ix,jy) MRI_COMPLEX_PTR(iq)[(ix)+(jy)*(iq)->nx]
00346 
00347 #define FLOAT_TO_BYTE(fff) \
00348   ( ((fff)<=0.0) ? (0) : ((fff)>=255.5) ? (255) : (byte)((fff)+0.49) )
00349 
00350 #define SHORT_TO_BYTE(fff) \
00351   ( ((fff)<=0) ? (0) : ((fff)>=255) ? (255) : (byte)(fff) )
00352 
00353 #define FLOAT_TO_SHORT(fff) ((short)(fff))
00354 
00355 /*********** Type: array of MRI_IMAGE pointers ***********/
00356 
00357 /*! Array of MRI_IMAGE pointers. */
00358 
00359 typedef struct MRI_IMARR {
00360       int num ;              /*!< Number of actual MRI_IMAGE here */
00361       int nall ;             /*!< Size of imarr array currently allocated */
00362       MRI_IMAGE ** imarr ;   /*!< Array of MRI_IMAGE pointers */
00363 } MRI_IMARR ;
00364 
00365 /*! Get the nn-th image from the image array "name". */
00366 
00367 #define IMAGE_IN_IMARR(name,nn) ((name)->imarr[(nn)])
00368 #define IMARR_SUBIMAGE          IMAGE_IN_IMARR
00369 #define IMARR_SUBIM             IMAGE_IN_IMARR
00370 
00371 /*! Get the number of images in the image array "name". */
00372 
00373 #define IMARR_COUNT(name)       ((name)->num)
00374 
00375 #define IMARR_LASTIM(name)      ((name)->imarr[(name)->num-1])
00376 #define IMARR_FIRSTIM(name)     ((name)->imarr[0])
00377 
00378 #define INC_IMARR 32
00379 
00380 /*! Initialize an MRI_IMARR struct. */
00381 
00382 #define INIT_IMARR(name)                                                           \
00383    do{ int iq ; (name) = (MRI_IMARR *) malloc(sizeof(MRI_IMARR)) ;                 \
00384        (name)->num = 0 ; (name)->nall = INC_IMARR ;                                \
00385        (name)->imarr = (MRI_IMAGE **)malloc(sizeof(MRI_IMAGE *)*INC_IMARR) ;       \
00386        for( iq=(name)->num ; iq < (name)->nall ; iq++ ) (name)->imarr[iq] = NULL ; \
00387        break ; } while(0)
00388 
00389 /*! Add one MRI_IMAGE to the MRI_IMARR struct. */
00390 
00391 #define ADDTO_IMARR(name,imm)                                                           \
00392    do{ int nn , iq ;                                                                    \
00393        if( (name)->num == (name)->nall ){                                               \
00394           nn = (name)->nall = 1.1*(name)->nall + INC_IMARR ;                            \
00395           (name)->imarr = (MRI_IMAGE **)realloc( (name)->imarr,sizeof(MRI_IMAGE *)*nn );              \
00396           for( iq=(name)->num ; iq < (name)->nall ; iq++ ) (name)->imarr[iq] = NULL ; } \
00397        nn = (name)->num ; ((name)->num)++ ;                                             \
00398        (name)->imarr[nn] = (imm) ; break ; } while(0)
00399 
00400 /*! Free the MRI_IMARR struct (but not the images within). */
00401 
00402 #define FREE_IMARR(name)                                                        \
00403    do{ if( (name) != NULL ){                                                    \
00404           free((name)->imarr); free((name)); (name) = NULL; } break; } while(0)
00405 
00406 /*! Free the MRI_IMARR struct, including the images within. */
00407 
00408 #define DESTROY_IMARR(name)                                                     \
00409    do{ int nn ;                                                                 \
00410        if( (name) != NULL ){                                                    \
00411           for( nn=0 ; nn < (name)->num ; nn++ ) mri_free((name)->imarr[nn]) ;   \
00412           free((name)->imarr); free((name)); (name) = NULL; } break; } while(0)
00413 
00414 /*! Free all images at-and-after [qq] in the MRI_IMARR struct. */
00415 
00416 #define TRUNCATE_IMARR(name,qq)                                                 \
00417    do{ int nn ;                                                                 \
00418        if( (name) != NULL && qq < (name)->num ){                                \
00419           for( nn=qq ; nn < (name)->num ; nn++ ) mri_free((name)->imarr[nn]);   \
00420           (name)->num = qq ;                                                    \
00421        } } while(0)
00422 
00423 /******* macros for complex arithmetic, using comma operator *******/
00424 
00425 static float   MRI_fla ;                      /* float temporaries   */
00426 static complex MRI_cxa , MRI_cxb , MRI_cxc ;  /* complex temporaries */
00427 
00428 /*! Return a complex from two floats. */
00429 
00430 #define CMPLX(x,y) ( MRI_cxa.r = (x) , MRI_cxa.i = (y) , MRI_cxa )
00431 
00432 /*! Return complex u+v */
00433 
00434 #define CADD(u,v) ( MRI_cxa.r = u.r + v.r , \
00435                     MRI_cxa.i = u.i + v.r , MRI_cxa )
00436 
00437 /*! complex u += v */
00438 
00439 #define CADDTO(u,v) ( u.r += v.r , u.i += v.i )
00440 
00441 /*! Return complex u-v */
00442 #define CSUB(u,v) ( MRI_cxa.r = u.r - v.r , \
00443                     MRI_cxa.i = u.i - v.i , MRI_cxa )
00444 
00445 /*! complex u -= v */
00446 
00447 #define CSUBFROM(u,v) ( u.r -= v.r , u.i -= v.i )
00448 
00449 /*! Return complex u*v */
00450 
00451 #define CMULT(u,v) ( MRI_cxb.r = u.r * v.r - u.i * v.i , \
00452                      MRI_cxb.i = u.r * v.i + u.i * v.r , MRI_cxb )
00453 
00454 /*! complex u *= v */
00455 
00456 #define CMULTBY(u,v) ( MRI_fla = u.r * v.r - u.i * v.i , \
00457                        u.i     = u.r * v.i + u.i * v.r , u.r = MRI_fla )
00458 
00459 /*! Return complex u * conjg(v) */
00460 
00461 #define CJMULT(u,v) ( MRI_cxb.r = u.r * v.r + u.i * v.i , \
00462                       MRI_cxb.i = u.i * v.r - u.r * v.i , MRI_cxb )
00463 
00464 /*! complex u *= conjg(v) */
00465 
00466 #define CJMULTBY(u,v) ( MRI_fla = u.r * v.r + u.i * v.i , \
00467                         u.i     = u.i * v.r - u.r * v.i , u.r = MRI_fla )
00468 
00469 /*! complex w += u*v */
00470 
00471 #define CMADD(u,v,w) ( w.r += u.r * v.r - u.i * v.i , \
00472                        w.i += u.r * v.i + u.i * v.r    )
00473 
00474 /*! Return complex exp(I*t) */
00475 
00476 #define CEXPIT(t)   ( MRI_cxc.r = cos(t) , MRI_cxc.i = sin(t) , MRI_cxc )
00477 
00478 /**** macros ****/
00479 
00480 static int MRI_mm ;
00481 
00482 /*! Median of 3. */
00483 
00484 #define MEDIAN(a,b,c) ( MRI_mm = 4*((a)<(b)) + 2*((a)<(c)) + ((b)<(c)) , \
00485                         (MRI_mm==3||MRI_mm==4) ? (a) :                   \
00486                         (MRI_mm==7||MRI_mm==0) ? (b) : (c) )
00487 
00488 /*! Order-statistic filter of 3. */
00489 
00490 #define OSFSUM(p,q,r) (0.70*(p)+0.15*((q)+(r)))
00491 
00492 /*! Order-statistic filter of 3. */
00493 
00494 #define OSFILT(a,b,c) ( MRI_mm = 4*((a)<(b)) + 2*((a)<(c)) + ((b)<(c)) , \
00495                         (MRI_mm==3||MRI_mm==4) ? OSFSUM(a,b,c) :         \
00496                         (MRI_mm==7||MRI_mm==0) ? OSFSUM(b,a,c) : OSFSUM(c,a,b) )
00497 
00498 #ifndef TRUE
00499 #   define TRUE  (1)
00500 #endif
00501 
00502 #ifndef FALSE
00503 #   define FALSE (0)
00504 #endif
00505 
00506 #define MRI_BILINEAR  (1)   /* for the warping function */
00507 #define MRI_LINEAR    (1)
00508 #define MRI_BICUBIC   (2)
00509 #define MRI_CUBIC     (2)
00510 #define MRI_FOURIER   (3)
00511 #define MRI_NN        (0)
00512 #define MRI_QUINTIC   (4)   /* Nov 1998 */
00513 #define MRI_HEPTIC    (5)
00514 #define MRI_TSSHIFT   (6)   /* Dec 1999 */
00515 
00516 #define MRI_FOURIER_NOPAD (66)  /* 13 May 2003 */
00517 
00518 #define SQR(x)   ((x)*(x))
00519 #define CSQR(z)  (SQR(z.r)+SQR(z.i))
00520 #define CABS(z)  sqrt(CSQR(z))
00521 #define CARG(z)  ( ((z).r!=0.0 || (z).i!=0.0) ? atan2((z).i,(z).r) : 0.0 )
00522 
00523 /*! complex z /= abs(z) */
00524 
00525 #define CUNITIZE(z) ( MRI_fla=CABS(z) , z.r=z.r/MRI_fla , z.i=z.i/MRI_fla )
00526 
00527 #ifdef MRI_DEBUG
00528 #  define WHOAMI fprintf(stderr,"in file: %s at line %d\n",__FILE__,__LINE__);
00529 #else
00530 #  define WHOAMI
00531 #endif
00532 
00533 #ifdef MRI_DEBUG
00534 #  define IMHEADER(f) \
00535           fprintf(stderr,"%s: nx=%d ny=%d kind=%d\n",#f,f->nx,f->ny,f->kind);
00536 #else
00537 #  define IMHEADER(f)
00538 #endif
00539 
00540 #define MRI_FATAL_ERROR \
00541         {fprintf(stderr,"in file: %s at line %d\n",__FILE__,__LINE__);EXIT(1);}
00542 
00543 /**** prototypes ****/
00544 
00545 #ifdef USE_MRI_DELAY
00546   extern void        mri_input_delay( MRI_IMAGE * ) ;
00547   extern void        mri_purge_delay( MRI_IMAGE * ) ;
00548   extern void        mri_add_fname_delay( char * , MRI_IMAGE * ) ;
00549   extern MRI_IMARR * mri_read_file_delay( char * ) ;
00550   extern MRI_IMARR * mri_read_3D_delay( char * ) ;
00551 #endif
00552 
00553 extern int mri_equal( MRI_IMAGE *, MRI_IMAGE * ) ; /* 30 Jun 2003 */
00554 
00555 extern MRI_IMARR * mri_read_analyze75( char * ) ;  /* 05 Feb 2001 */
00556 extern MRI_IMARR * mri_read_siemens( char * ) ;    /* 12 Mar 2001 */
00557 extern MRI_IMARR * mri_read3D_analyze75( char * ); /* 26 Aug 2002 */
00558 
00559 extern MRI_IMAGE * mri_read_stuff( char * ) ;      /* 22 Nov 2002 */
00560 extern void        mri_inflate_pbm( MRI_IMAGE * ); /* 02 Jan 2002 */
00561 
00562 extern void mri_add_name( char * , MRI_IMAGE * ) ;
00563 
00564 extern MRI_IMAGE ** mri_stat_seq( MRI_IMAGE * ) ;
00565 
00566 extern MRI_IMAGE * mri_edit_image( float pthr, float power, MRI_IMAGE * im ) ;
00567 
00568 extern MRI_IMARR * mri_read_mpeg( char * ) ;    /* 03 Dec 2003 */
00569 extern int         mri_isgray( MRI_IMAGE * ) ;
00570 extern int         mri_imcount_mpeg( char * ) ;
00571 
00572 extern void cfft( int , int , float * , float * ) ;
00573 extern void cfft2d( int , int , int , float * , float * ) ;
00574 extern void csfft_cox( int,int , complex * ) ;
00575 extern void csfft_many( int,int,int , complex * ) ;
00576 extern int  csfft_nextup(int) ;
00577 extern int csfft_nextup_one35(int) ;
00578 extern int csfft_nextup_even(int) ;
00579 extern void csfft_scale_inverse(int) ;
00580 extern void csfft_use_fftw( int ) ;     /* 20 Oct 2000 */
00581 
00582 extern void mri_fftshift( MRI_IMAGE *, float,float,float, int ) ; /* 13 May 2003 */
00583 
00584 extern void *mri_data_pointer( MRI_IMAGE * ) ;
00585 extern void mri_free( MRI_IMAGE * ) ;
00586 extern void mri_fix_data_pointer( void * , MRI_IMAGE * ) ;
00587 
00588 extern char * mri_dicom_header( char * ) ;  /* 15 Jul 2002 */
00589 extern void   mri_dicom_pxlarr( off_t *, unsigned int * ) ;
00590 extern void   mri_dicom_noname( int ) ;
00591 extern void   mri_dicom_nohex ( int ) ;
00592 extern void   mri_dicom_setvm ( int ) ;     /* 28 Oct 2002 */
00593 extern void   mri_dicom_seterr( int ) ;     /* 05 Nov 2002 */
00594 
00595 extern MRI_IMARR * mri_read_dicom( char * )  ;
00596 extern int         mri_imcount_dicom( char * ) ;
00597 extern char *      mri_dicom_sexinfo( void ) ;   /* 23 Dec 2002 */
00598 extern int mri_possibly_dicom( char * ) ;        /* 07 May 2003 */
00599 
00600 
00601 /*! Set the data pointer in an MRI_IMAGE to NULL. */
00602 
00603 #define mri_clear_data_pointer(iq) mri_fix_data_pointer(NULL,(iq))
00604 
00605 /*! Set all pixels in MRI_IMAGE to zero. */
00606 
00607 #define mri_zero_image(iq) \
00608    memset(mri_data_pointer(iq),0,(iq)->nvox*(iq)->pixel_size)
00609 
00610 extern MRI_IMAGE * mri_zeropad_3D( int,int,int,int,int,int , MRI_IMAGE * ) ;
00611 extern MRI_IMAGE * mri_zeropad_2D( int,int,int,int, MRI_IMAGE * ) ;
00612 
00613 extern double mri_max( MRI_IMAGE * ) ;
00614 extern double mri_min( MRI_IMAGE * ) ;
00615 extern double mri_maxabs( MRI_IMAGE * ) ;
00616 
00617 extern MRI_IMAGE * mri_cut_2D( MRI_IMAGE * , int,int,int,int ) ;
00618 extern MRI_IMAGE * mri_cut_3D( MRI_IMAGE * , int,int,int,int,int,int ) ;
00619 
00620 /** 15 Apr 1999 **/
00621 
00622 extern void upsample_7( int , int , float * , float * ) ;
00623 extern void upsample_1( int , int , float * , float * ) ; /* 12 Mar 2002 */
00624 extern MRI_IMAGE * mri_dup2D( int , MRI_IMAGE * ) ;
00625 extern void        mri_dup2D_mode( int ) ;                /* 12 Mar 2002 */
00626 
00627 extern void mri_move_guts( MRI_IMAGE *, MRI_IMAGE * ) ;  /* 28 Mar 2002 */
00628 extern MRI_IMAGE * mri_copy( MRI_IMAGE * ) ;             /* 17 Apr 2000 */
00629 extern MRI_IMAGE * mri_expand_2D( int , MRI_IMAGE * ) ;  /* 22 Feb 2004 */
00630 extern MRI_IMAGE *mri_new( int , int , MRI_TYPE ) ;
00631 extern MRI_IMAGE *mri_read( char * ) ;
00632 extern MRI_IMAGE *mri_read_ge4( char * ) ;               /* 03 Jun 2003 */
00633 extern int mri_write( char * , MRI_IMAGE * ) ;
00634 extern int mri_write_pnm( char * , MRI_IMAGE * ) ;
00635 extern int mri_write_jpg( char * , MRI_IMAGE * ) ;       /* 15 Apr 2005 */
00636 extern int mri_write_7D( char * , MRI_IMAGE * ) ;
00637 extern int mri_datum_size( MRI_TYPE typ ) ;
00638 extern MRI_IMAGE *mri_read_ascii( char * ) ;
00639 extern MRI_IMAGE *mri_read_ascii_ragged(char *, float) ; /* 28 Jul 2004 */
00640 extern int mri_write_ascii( char * , MRI_IMAGE * ) ;
00641 extern int mri_write_raw( char * , MRI_IMAGE * ) ;       /* 05 Jan 2000 */
00642 extern void mri_write_analyze( char * , MRI_IMAGE * ) ;  /* 29 Nov 2001 */
00643 
00644 extern MRI_IMAGE * mri_read_1D( char * ) ;               /* 16 Nov 1999 */
00645 extern int mri_write_1D( char * , MRI_IMAGE * ) ;        /* 16 Nov 1999 */
00646 
00647 extern MRI_IMAGE * mri_1D_fromstring( char * ) ;         /* 28 Apr 2003 */
00648 
00649 extern int setup_mri_write_angif( void ) ;               /* 28 Jun 2001 */
00650 extern int mri_write_angif( char *, MRI_IMARR * ) ;
00651 extern MRI_IMAGE * mri_colorsetup( int,int,int,int ) ;   /* 05 Oct 2004 */
00652 
00653 extern MRI_IMAGE *mri_new_vol      ( int,int,int , MRI_TYPE ) ;
00654 extern MRI_IMAGE *mri_new_vol_empty( int,int,int , MRI_TYPE ) ;
00655 
00656 MRI_IMAGE *mri_new_7D_generic( int nx, int ny, int nz, int nt,
00657                                int nu, int nv, int nw,
00658                                MRI_TYPE kind , int make_space ) ;
00659 
00660 /*! Create new MRI_IMAGE of type kk, with same dimensions as iq. */
00661 
00662 #define mri_new_conforming(iq,kk)                                   \
00663    mri_new_7D_generic( (iq)->nx, (iq)->ny, (iq)->nz , (iq)->nt ,    \
00664                        (iq)->nu, (iq)->nv, (iq)->nw , (kk) , TRUE )
00665 
00666 /*! Create new MRI_IMAGE of type kk, with same dimensions as iq,
00667     and with no data space allocated. */
00668 
00669 #define mri_empty_conforming(iq,kk)                                 \
00670    mri_new_7D_generic( (iq)->nx, (iq)->ny, (iq)->nz , (iq)->nt ,    \
00671                        (iq)->nu, (iq)->nv, (iq)->nw , (kk) , FALSE )
00672 
00673 extern MRI_IMARR * mri_read_3D( char * ) ;
00674 extern MRI_IMARR * mri_read_3A( char * ) ;
00675 extern MRI_IMARR * mri_read_file( char * ) ;
00676 extern int mri_imcount( char * ) ;
00677 extern MRI_IMARR * mri_read_many_files( int nf , char * fn[] ) ;
00678 
00679 /** returns array of byte images: red, green, blue **/
00680 
00681 extern MRI_IMARR * mri_read_ppm3( char * fname ) ;
00682 extern MRI_IMAGE * mri_read_ppm( char * fname ) ;
00683 
00684 extern void mri_read_ppm_header( char *, int *, int *) ; /* 17 Sep 2001 */
00685 
00686 MRI_IMAGE *mri_read_just_one( char * fname ) ;
00687 MRI_IMAGE *mri_read_nsize( char * fname ) ;
00688 MRI_IMARR *mri_read_many_nsize( int nf , char * fn[] ) ;
00689 
00690 void init_MCW_sizes(void) ;
00691 char * imsized_fname( char * fname ) ;
00692 long mri_filesize( char * pathname ) ;
00693 char * my_strdup( char * str ) ;
00694 
00695 extern void mri_overlay_2D( MRI_IMAGE *, MRI_IMAGE *, int,int ) ;
00696 
00697 extern void mri_swapbytes( MRI_IMAGE * ) ;
00698 
00699 extern void swap_twobytes  ( int n , void * ar ) ;  /* 14 Sep 1998 */
00700 extern void swap_fourbytes ( int n , void * ar ) ;
00701 extern void swap_eightbytes( int n , void * ar ) ;  /* 06 Feb 2003 */
00702 
00703 extern MRI_IMAGE *mri_to_float( MRI_IMAGE * ) ;
00704 extern MRI_IMAGE *mri_to_short( double , MRI_IMAGE * ) ;
00705 extern MRI_IMAGE *mri_to_short_scl( double,double , MRI_IMAGE * ) ;
00706 extern MRI_IMAGE *mri_to_short_sclip( double,double , int,int , MRI_IMAGE * ) ;
00707 extern MRI_IMAGE *mri_to_complex( MRI_IMAGE * ) ;
00708 extern MRI_IMAGE *mri_to_byte( MRI_IMAGE * ) ;
00709 extern MRI_IMAGE *mri_to_byte_scl( double , double , MRI_IMAGE * ) ;
00710 
00711 extern MRI_IMAGE * mri_to_rgb( MRI_IMAGE * ) ;
00712 extern MRI_IMAGE * mri_3to_rgb( MRI_IMAGE * , MRI_IMAGE * , MRI_IMAGE * ) ;
00713 extern MRI_IMARR * mri_rgb_to_3float( MRI_IMAGE * ) ;
00714 extern MRI_IMARR * mri_rgb_to_3byte( MRI_IMAGE * ) ;
00715 extern MRI_IMAGE * mri_sharpen_rgb( float , MRI_IMAGE * ) ;
00716 extern MRI_IMAGE * mri_flatten_rgb( MRI_IMAGE * ) ;
00717 extern void mri_invert_inplace( MRI_IMAGE *) ;   /* 07 Apr 2003 */
00718 
00719 extern MRI_IMAGE * mri_to_rgba( MRI_IMAGE * ) ;  /* 20 Mar 2002 */
00720 
00721 extern MRI_IMAGE *mri_pair_to_complex( MRI_IMAGE * , MRI_IMAGE * ) ;
00722 extern MRI_IMARR *mri_complex_to_pair( MRI_IMAGE * ) ;
00723 
00724 extern MRI_IMAGE *mri_to_complex_ext( MRI_IMAGE * , int , int , int ) ;
00725 
00726 extern MRI_IMAGE *mri_scale_to_float( float , MRI_IMAGE * ) ;
00727 extern void mri_threshold( double , double , MRI_IMAGE * , MRI_IMAGE * ) ;
00728 extern MRI_IMAGE * mri_mult_to_float( float * , MRI_IMAGE * ) ;
00729 
00730 extern MRI_IMAGE * mri_scalize( MRI_IMAGE *, int, float * ) ; /* 20 Oct 2003 */
00731 
00732 extern MRI_IMAGE *mri_multiply_complex( int , MRI_IMAGE * , MRI_IMAGE * ) ;
00733 extern MRI_IMAGE *mri_complex_phase( MRI_IMAGE * ) ;
00734 
00735 extern MRI_IMAGE *mri_to_mri( int , MRI_IMAGE * ) ;
00736 extern MRI_IMAGE *mri_to_mri_scl( int , double , MRI_IMAGE * ) ;
00737 extern MRI_IMAGE *mri_complex_abs( MRI_IMAGE * ) ;
00738 
00739 extern void mri_fft_complex( int , float , MRI_IMAGE * ) ;
00740 extern float *mri_setup_taper( int , float ) ;
00741 
00742 extern MRI_IMAGE *mri_warp( MRI_IMAGE * , int , int , int ,
00743                             void func(float,float,float *,float *) ) ;
00744 
00745 extern MRI_IMAGE *mri_warp_bicubic( MRI_IMAGE * , int , int ,
00746                                     void func(float,float,float *,float *) ) ;
00747 
00748 extern MRI_IMAGE *mri_warp_bilinear( MRI_IMAGE * , int , int ,
00749                                      void func(float,float,float *,float *) ) ;
00750 
00751 #undef WARP_POINT_ROUTINES
00752 #ifdef WARP_POINT_ROUTINES
00753 extern float mri_warp_bicubic_point( MRI_IMAGE * , int , int ,
00754                                      void func( float,float,float *,float *) ) ;
00755 
00756 extern float mri_rotate_point( MRI_IMAGE *im, float,float,float,float, int,int ) ;
00757 #endif /* WARP_POINT_ROUTINES */
00758 
00759 extern MRI_IMAGE *mri_resize( MRI_IMAGE * , int , int ) ;
00760 
00761 extern MRI_IMAGE *mri_resize_NN( MRI_IMAGE *, int , int ) ;  /* 08 Jun 2004 */
00762 extern MRI_IMAGE *mri_squareaspect( MRI_IMAGE * ) ;
00763 
00764 extern MRI_IMAGE *mri_rotate         ( MRI_IMAGE * , float,float,float,float ) ;
00765 extern MRI_IMAGE *mri_rotate_bilinear( MRI_IMAGE * , float,float,float,float ) ;
00766 
00767 extern MRI_IMAGE *mri_rota         ( MRI_IMAGE * , float,float,float ) ;
00768 extern MRI_IMAGE *mri_rota_bilinear( MRI_IMAGE * , float,float,float ) ;
00769 extern MRI_IMAGE *mri_rota_shear   ( MRI_IMAGE * , float,float,float ) ;
00770 extern MRI_IMAGE *mri_rota_variable( int, MRI_IMAGE * , float,float,float ) ;
00771 
00772 extern MRI_IMAGE *mri_aff2d_byte( MRI_IMAGE *,int,float,float,float,float) ;
00773 extern MRI_IMAGE *mri_aff2d_rgb ( MRI_IMAGE *,int,float,float,float,float) ;
00774 
00775 /** 27 Nov 2001: mri_scale.c **/
00776 
00777 extern void mri_scale_inplace( float , MRI_IMAGE * ) ;
00778 
00779 extern void ft_shift2( int, int, float, float *, float, float * ) ;
00780 
00781 extern MRI_IMAGE *mri_float_func( int,int,
00782                                   float , float , float , float ,
00783                                   float (*func)(float,float) ) ;
00784 
00785 extern void mri_histogram( MRI_IMAGE * , float,float ,
00786                                          int,int, int h[] ) ;
00787 
00788 extern void mri_histobyte        ( MRI_IMAGE * , int * ) ;
00789 extern void mri_histoshort_all   ( MRI_IMAGE * , int * ) ;  /* 25 Jul 2001 */
00790 extern void mri_histoshort_nonneg( MRI_IMAGE * , int * ) ;
00791 
00792 extern void mri_percents( MRI_IMAGE * , int nper , float per[] ) ;
00793 extern MRI_IMAGE * mri_flatten( MRI_IMAGE * ) ;
00794 extern float mri_quantile( MRI_IMAGE * im , float alpha ) ;
00795 
00796 extern void qsort_short( int , short * ) ;
00797 extern void qsort_float( int , float * ) ;
00798 extern void qsort_pair( int , float * , int * ) ;
00799 extern void qsort_int( int , int * ) ;
00800 
00801 extern void isort_short( int , short * ) ;
00802 extern void isort_float( int , float * ) ;
00803 extern void isort_pair ( int , float * , int * ) ;
00804 
00805 extern MRI_IMAGE * mri_nsize( MRI_IMAGE * ) ;
00806 
00807 extern float * mri_lsqfit( MRI_IMAGE * fitim , MRI_IMARR * refim , MRI_IMAGE * ) ;
00808 extern double * mri_startup_lsqfit( MRI_IMARR * , MRI_IMAGE * ) ;
00809 extern float * mri_delayed_lsqfit( MRI_IMAGE * , MRI_IMARR * , double * ) ;
00810 extern float * lsqfit( int , float * , float * , int , float *ref[] ) ;
00811 extern double * startup_lsqfit( int , float * , int , float *ref[] ) ;
00812 extern float * delayed_lsqfit( int , float * , int , float *ref[] , double * ) ;
00813 
00814 extern MRI_IMAGE * mri_sobel( int , int , MRI_IMAGE * ) ;
00815 extern MRI_IMAGE * mri_sharpen( float , int , MRI_IMAGE * ) ;
00816 extern MRI_IMAGE * mri_transpose( MRI_IMAGE * ) ;
00817 
00818 #define FILT_FFT_WRAPAROUND  1
00819 
00820 extern MRI_IMAGE * mri_filt_fft( MRI_IMAGE * im , float,int,int,int ) ;
00821 
00822 extern MRI_IMAGE *mri_medianfilter( MRI_IMAGE *, float, byte *, int ) ;  /* 22 Feb 2005 */
00823 
00824 extern MRI_IMAGE * mri_cat2D( int,int,int,void *,MRI_IMARR *) ;
00825 extern MRI_IMARR * mri_uncat2D( int , int , MRI_IMAGE * im ) ; /* 09 May 2000 */
00826 
00827 extern MRI_IMAGE * mri_shift_1D( MRI_IMAGE * im , float shift ) ;
00828 
00829 /*** image alignment procedures and constants ***/
00830 
00831 #define ALIGN_DFSPACE_TYPE    1
00832 #define ALIGN_DFTIME_TYPE     2
00833 
00834 #define ALIGN_VERBOSE_CODE    1   /* verbose output during routine */
00835 #define ALIGN_NOITER_CODE     2   /* don't iterate alignment algorithm */
00836 #define ALIGN_REGISTER_CODE   4   /* return MRI_IMARR * of registered images */
00837 #define ALIGN_DETREND_CODE    8   /* remove trend from registered images (DFTIME only) */
00838 #define ALIGN_DOBOTH_CODE    16   /* do dfspace before dftime (DFTIME only) */
00839 #define ALIGN_DEBUG_CODE     32   /* print out debugging info */
00840 #define ALIGN_FREEUP_CODE    64   /* free input images when no longer needed */
00841 #define ALIGN_BILINEAR_CODE 128   /* use bilinear interpolation in mri_align */
00842 #define ALIGN_FOURIER_CODE  256   /* use Fourier interpolation in mri_align */
00843 
00844 extern MRI_IMARR * mri_align_dfspace( MRI_IMAGE *, MRI_IMAGE * , MRI_IMARR *,
00845                                       int, float *, float *, float * ) ;
00846 
00847 extern MRI_IMARR * mri_align_dftime( MRI_IMAGE *, MRI_IMAGE * , MRI_IMARR *,
00848                                      int, float *, float *, float * ) ;
00849 
00850 extern void mri_align_params( int,float,float,float,float,float,float ) ;
00851 extern void mri_align_method( int,int,int ) ;  /* 01 Oct 1998 */
00852 
00853 extern void mri_get_cmass_2D( MRI_IMAGE *, float *, float * ); /* 12 Nov 2001 */
00854 extern void mri_get_cmass_3D( MRI_IMAGE *, float *, float * , float *);
00855 
00856 /*---------------------------------------------------------------------*/
00857 /* 07 April 1998: routines for one-at-a-time alignment (mri_2dalign.c) */
00858 
00859 /*! Struct used in 2D image registration. */
00860 
00861 typedef struct {
00862    MRI_IMARR * fitim , * fine_fitim ;
00863    double * chol_fitim , * chol_fine_fitim ;
00864 } MRI_2dalign_basis ;
00865 
00866 extern void mri_2dalign_params( int,float,float,float,float,float,float ) ;
00867 extern void mri_2dalign_method( int,int,int ) ;
00868 extern MRI_2dalign_basis * mri_2dalign_setup( MRI_IMAGE * , MRI_IMAGE * ) ;
00869 extern MRI_IMAGE * mri_2dalign_one( MRI_2dalign_basis * , MRI_IMAGE * ,
00870                                     float * , float * , float * ) ;
00871 extern MRI_IMARR * mri_2dalign_many( MRI_IMAGE *, MRI_IMAGE * , MRI_IMARR *,
00872                                      float * , float * , float * ) ;
00873 extern void mri_2dalign_cleanup( MRI_2dalign_basis * ) ;
00874 /*---------------------------------------------------------------------*/
00875 
00876 /*** routine to flip 2D images around ***/
00877 
00878 #define MRI_ROT_0   1  /* codes for various rotations */
00879 #define MRI_ROT_90  2  /* [do not change these unless */
00880 #define MRI_ROT_180 4  /*  imseq.h is changed also!]  */
00881 #define MRI_ROT_270 8
00882 #define MRI_FLMADD  128
00883 
00884 extern MRI_IMAGE * mri_flippo( int rot , int mirror , MRI_IMAGE * im ) ;
00885 
00886 extern MRI_IMAGE * mri_flip3D( int,int,int , MRI_IMAGE *inim ) ; /* 19 Mar 2003 */
00887 
00888 /*---------------------------------------------------------------------*/
00889 /*--------- 22 April 1998: byte order routines (mri_order.c) ----------*/
00890 
00891 #define LSB_FIRST      1
00892 #define MSB_FIRST      2
00893 #define NATIVE_ORDER  -1
00894 
00895 #define REVERSE_ORDER(bord) (3-(bord))  /* 21 Jun 2002 */
00896 
00897 #define ORDER_LEN        9
00898 #define LSB_FIRST_STRING "LSB_FIRST"
00899 #define MSB_FIRST_STRING "MSB_FIRST"
00900 #define NATIVE_STRING    "NATIVE_ORDER"
00901 
00902 #define BYTE_ORDER_STRING(qq) (  ((qq)==LSB_FIRST) ? LSB_FIRST_STRING \
00903                                : ((qq)==MSB_FIRST) ? MSB_FIRST_STRING \
00904                                                    : "Illegal Value" )
00905 extern int mri_short_order(void) ;
00906 extern int mri_int_order(void) ;
00907 extern void mri_swap2( int , short * ) ;
00908 extern void mri_swap4( int , int * ) ;
00909 
00910 /*---------------------------------------------------------------------*/
00911 /*------------------ 18 Sep 2001: drawing stuff -----------------------*/
00912 
00913 extern void mri_drawline( MRI_IMAGE *im, int x0,int y0, int x1,int y1,
00914                           byte r,byte g,byte b );
00915 
00916 extern void mri_drawfilledrectangle( MRI_IMAGE *im ,
00917                                      int x, int y, int width, int height ,
00918                                      byte r,byte g,byte b );
00919 
00920 extern void mri_drawemptyrectangle( MRI_IMAGE *im ,
00921                                     int x, int y, int width, int height ,
00922                                     byte r,byte g,byte b );
00923 
00924 extern void mri_drawtext( MRI_IMAGE *im ,
00925                           int x, int y, int height, int angle, char *s,
00926                           byte r,byte g,byte b );
00927 
00928 extern void mri_draw_opacity( float ) ;
00929 
00930 /**********************************************************************/
00931 
00932 #include "coxplot.h"
00933 #undef min
00934 #undef max
00935 
00936 extern void set_memplot_RGB_box( int xbot, int ybot, int xtop, int ytop ) ;
00937 
00938 extern void memplot_to_RGB_sef( MRI_IMAGE *im , MEM_plotdata * mp ,
00939                                 int start , int end , int freee    ) ;
00940 
00941 /************************ Statistics routines *************************/
00942 
00943 /**
00944   if the math library doesn't have the log(gamma(x))
00945   function (as on Linux, for example)
00946 **/
00947 
00948 #ifdef NO_GAMMA
00949 extern double gamma_12    ( double ) ;
00950 extern double gamma       ( double ) ;
00951 extern double gamma_asympt( double ) ;
00952 #endif
00953 
00954 extern double lnbeta         ( double , double ) ;
00955 extern double incbeta        ( double , double , double , double ) ;
00956 extern double incbeta_inverse( double , double , double , double ) ;
00957 extern double qginv          ( double ) ;
00958 extern double qg             ( double ) ;     /* 21 Mar 2001 */
00959 extern double log10qg        ( double ) ;
00960 #define QG(x) (0.5*erfc(x/1.414213562373095))
00961 
00962 #define erfcinv(y) (0.70710678*qginv(0.5*y))  /* 07 Oct 1999 */
00963 
00964 extern double student_t2p( double , double ) ;
00965 extern double student_p2t( double , double ) ;
00966 extern double student_t2z( double , double ) ;
00967 
00968 extern double correl_t2p ( double , double , double , double ) ;
00969 extern double correl_t2z ( double , double , double , double ) ;
00970 extern double correl_p2t ( double , double , double , double ) ;
00971 
00972 extern double studave_t2p( double , double , double ) ;  /* not implemented */
00973 extern double studave_t2z( double , double , double ) ;  /* not implemented */
00974 extern double studave_p2t( double , double , double ) ;
00975 
00976 extern double fstat_p2t( double , double , double ) ;
00977 extern double fstat_t2p( double , double , double ) ;
00978 extern double fstat_t2z( double , double , double ) ;
00979 
00980 extern double normal_t2p  ( double zz ) ;
00981 extern double normal_p2t  ( double qq ) ;
00982 #define       normal_t2z(x) (x)                     /* no function needed here! */
00983 
00984 extern double chisq_t2p   ( double xx , double dof ) ;
00985 extern double chisq_t2z   ( double xx , double dof ) ;
00986 extern double chisq_p2t   ( double qq , double dof ) ;
00987 
00988 extern double beta_t2p    ( double xx , double aa , double bb ) ;
00989 extern double beta_t2z    ( double xx , double aa , double bb ) ;
00990 extern double beta_p2t    ( double qq , double aa , double bb ) ;
00991 
00992 extern double binomial_t2p( double ss , double ntrial , double ptrial ) ;
00993 extern double binomial_t2z( double ss , double ntrial , double ptrial ) ;
00994 extern double binomial_p2t( double qq , double ntrial , double ptrial ) ;
00995 
00996 extern double gamma_t2p   ( double xx , double sh , double sc ) ;
00997 extern double gamma_t2z   ( double xx , double sh , double sc ) ;
00998 extern double gamma_p2t   ( double qq , double sh , double sc ) ;
00999 
01000 extern double poisson_t2p ( double xx , double lambda ) ;
01001 extern double poisson_t2z ( double xx , double lambda ) ;
01002 extern double poisson_p2t ( double qq , double lambda ) ;
01003 
01004 /*----------------- Misc other types -------------------------------------*/
01005 
01006 typedef struct { int i,j;   } int_pair ;    /* 12 Aug 2002 */
01007 typedef struct { int i,j,k; } int_triple ;
01008 
01009 typedef struct { int nar ; float *ar ; } floatvec ;
01010 #define KILL_floatvec(fv)                      \
01011   do{ if( (fv)->ar != NULL ) free((fv)->ar);   \
01012       free(fv);                                \
01013   } while(0)
01014 
01015 typedef struct { int nvec ; floatvec *fvar ; } floatvecvec ;
01016 
01017 typedef struct { int nar ; int *ar ; } intvec ;
01018 #define KILL_intvec(fv)                        \
01019   do{ if( (fv)->ar != NULL ) free((fv)->ar);   \
01020       free(fv);                                \
01021   } while(0)
01022 
01023 typedef struct {
01024   int nbot, ntop , gbot ;
01025   char name[64] ;
01026 } SYM_irange ;
01027 
01028 floatvecvec * SYM_expand_ranges( int nlast, int nrang, SYM_irange *rang, char *str );
01029 
01030 /*-----------------  30 Oct 1996: incorporation of cdflib ----------------*/
01031 #include "cdflib.h"
01032 /*------------------------------------------------------------------------*/
01033 
01034 /*-----------------  01 Feb 1998: incoroporation of mcw_glob -------------*/
01035 #include "mcw_glob.h"
01036 /*------------------------------------------------------------------------*/
01037 
01038 /*-----------------  06 Dec 2004: incorporation of list_struct  ----------*/
01039 #include "list_struct.h"
01040 
01041 /*-----------------  02 Feb 1998:
01042                      incoroporation of 3ddata, 3dmaker, iochan -----------*/
01043 
01044 #include "thd_iochan.h"
01045 #include "3ddata.h"
01046 #include "thd_maker.h"
01047 #include "editvol.h"
01048 
01049 #include "cs.h"            /* 17 Aug 1998 addition */
01050 
01051 #include "multivector.h"   /* 18 May 1999 addition */
01052 
01053 #include "afni_environ.h"  /* 07 Jun 1999 addition */
01054 /*------------------------------------------------------------------------*/
01055 
01056 extern MRI_IMAGE * THD_average_timeseries( MCW_cluster_array *, THD_3dim_dataset *) ;
01057 extern MRI_IMAGE * THD_average_one_timeseries( MCW_cluster *, THD_3dim_dataset *) ;
01058 
01059 /** mri_warp3D.c functions: 14 Apr 2003 */
01060 
01061 extern MRI_IMAGE *mri_warp3D_cubic ( MRI_IMAGE *, int,int,int ,
01062                                      void func( float,float,float,
01063                                                 float *,float *,float *) ) ;
01064 extern MRI_IMAGE *mri_warp3D_linear( MRI_IMAGE *, int,int,int ,
01065                                      void func( float,float,float,
01066                                                 float *,float *,float *) ) ;
01067 extern MRI_IMAGE *mri_warp3D_NN    ( MRI_IMAGE *, int,int,int ,
01068                                      void func( float,float,float,
01069                                                 float *,float *,float *) ) ;
01070 extern MRI_IMAGE *mri_warp3D       ( MRI_IMAGE *, int,int,int ,
01071                                      void func( float,float,float,
01072                                                 float *,float *,float *) ) ;
01073 extern void mri_warp3D_method( int ) ;
01074 extern void mri_warp3D_zerout( int ) ;
01075 
01076 extern void mri_warp3D_set_womask( MRI_IMAGE * ) ;  /* 19 Nov 2004 */
01077 
01078 extern MRI_IMAGE *mri_warp3D_quintic( MRI_IMAGE *, int,int,int , /* 06 Aug 2003 */
01079                                       void func( float,float,float,
01080                                                  float *,float *,float *) ) ;
01081 
01082 extern MRI_IMAGE * mri_warp3D_affine( MRI_IMAGE * , THD_vecmat ) ;
01083 extern MRI_IMAGE * mri_warp3D_resize( MRI_IMAGE *, int,int,int ) ;
01084 
01085 extern double mri_entropy16( MRI_IMAGE * ) ;  /* 09 Jan 2004 */
01086 extern double mri_entropy8 ( MRI_IMAGE * ) ;  /* 09 Jan 2004 */
01087 
01088 /*------------------------------------------------------------------*/
01089 
01090 #undef INLINE
01091 #ifdef __GNUC__
01092 # define INLINE __inline__
01093 #else
01094 # define INLINE /*nada*/
01095 #endif
01096 
01097 #undef RESTRICT
01098 #ifdef __GNUC__
01099 # define RESTRICT __restrict__
01100 #else
01101 # define RESTRICT /*nada*/
01102 #endif
01103 
01104 /*------------------------------------------------------------------*/
01105 
01106 #include "AFNI_label.h"
01107 #undef  PRINT_VERSION
01108 #define PRINT_VERSION(pp) \
01109   INFO_message("Program %s: AFNI version=%s",(pp),AFNI_VERSION_LABEL)
01110 
01111 #undef  WROTE_DSET_MSG
01112 #define WROTE_DSET_MSG(dd,ss) \
01113   INFO_message("Output dataset %s {%s}",DSET_BRIKNAME(dd),(ss))
01114 
01115 #undef  WROTE_DSET
01116 #define WROTE_DSET(dd) \
01117   INFO_message("Output dataset %s",DSET_BRIKNAME(dd))
01118 
01119 /*------------------------------------------------------------------*/
01120 
01121 #endif /* _MCW_MRILIB_HEADER_ */
 

Powered by Plone

This site conforms to the following standards: