/******************************************************************************* Trivial extension of pyramidtools.h in spline pyramids package at http://bigwww.epfl.ch/algorithms.html to 3D reduce and expand Coded by Se Young Chun, May 25, 2007, The Univ. of Michigan *******************************************************************************/ #include #include #include #include #include #include /* available at http://bigwww.epfl.ch/sage/pyramids/ */ #include "pyramids/configs.h" #include "pyramids/messagedisplay.h" #include "pyramids/pyramidtools.h" #include "pyramids/pyramidfilters.h" #include "pyramidtools3D.h" static void GetColumn3D ( float *Image, long x, long z, double Line[], long Width, long Height ); static void GetRow3D ( float *Image, long y, long z, double Line[], long Width, long Height ); static void GetSlice3D ( float *Image, long x, long y, double Line[], long Width, long Height, long Slice ); static void PutColumn3D ( float *Image, long x, long z, double Line[], long Width, long Height ); static void PutRow3D ( float *Image, long y, long z, double Line[], long Width, long Height ); static void PutSlice3D ( float *Image, long x, long y, double Line[], long Width, long Height, long Slice ); extern int Reduce_3D ( float *In, long NxIn, long NyIn, long NzIn, float *Out, double g[], long ng, short IsCentered ) { float *Tmp, *Tmp2; double *InBuffer; double *OutBuffer; long kx, ky, kz; long NxOut; long NyOut; long NzOut; /* --- Define dimension of the output --- */ NxOut = NxIn/2L; if (NxOut < 1L) NxOut = 1L; NyOut = NyIn/2L; if (NyOut < 1L) NyOut = 1L; NzOut = NzIn/2L; if (NzOut < 1L) NzOut = 1L; /* --- Allocate a temporary image --- */ Tmp = (float *)malloc((size_t)(NxOut*NyIn*NzIn*(long)sizeof(float))); if (Tmp == (float *)NULL) { MessageDisplay("Unable to allocate memory"); return(ERROR); } Tmp2 = (float *)malloc((size_t)(NxOut*NyOut*NzIn*(long)sizeof(float))); if (Tmp2 == (float *)NULL) { free(Tmp); MessageDisplay("Unable to allocate memory"); return(ERROR); } /* --- X processing --- */ if (NxIn > 1L) { InBuffer=(double*)malloc((size_t)(NxIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NxOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(Tmp); free(Tmp2); free(InBuffer); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (kz=0L; kz 1L) { InBuffer=(double*)malloc((size_t)(NyIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { MessageDisplay("Unable to allocate memory"); free(Tmp); free(Tmp2); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NyOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(InBuffer); free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (kz=0L; kz 1L) { InBuffer=(double*)malloc((size_t)(NzIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { MessageDisplay("Unable to allocate memory"); free(Tmp); free(Tmp2); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NzOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(InBuffer); free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (ky=0L; ky 1L) { InBuffer=(double*)malloc((size_t)(NxIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { MessageDisplay("Unable to allocate memory"); free(Tmp); free(Tmp2); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NxOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(InBuffer); free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (kz=0L; kz 1L) { InBuffer=(double*)malloc((size_t)(NyIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { MessageDisplay("Unable to allocate memory"); free(Tmp); free(Tmp2); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NyOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(InBuffer); free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (kz=0L; kz 1L) { InBuffer=(double*)malloc((size_t)(NzIn*(long)sizeof(double))); if (InBuffer == (double *)NULL) { MessageDisplay("Unable to allocate memory"); free(Tmp); free(Tmp2); return(ERROR); } OutBuffer=(double*)malloc((size_t)(NzOut*(long)sizeof(double))); if (OutBuffer == (double *)NULL) { free(InBuffer); free(Tmp); free(Tmp2); MessageDisplay("Unable to allocate memory"); return(ERROR); } for (ky=0L; ky