[MINC-users] Reading MINC Files in SPM
Deepa H. Shroff
minc-users@bic.mni.mcgill.ca
Mon Mar 1 19:31:35 2004
Hello:
I am using MINC API in my C code to generate a 3D image file.
The data is of type 'double' and size of image data is 64*64*16.
When i try to read the .mnc file in SPM it gives me an error.
I dont know whether SPM cant read MINC files or there is something
wrong with the way i have generated the MINC files.
I am attaching my code with this email. Any feedback will be very
helpful.
Thanks a lot.
Deepa
=============================
C Code to generate MINC file.
-----------------------------------------
/* create minc file */
sprintf(buffer, "./files/f_t%d.mnc",i);
int fileid;
fileid = nccreate(buffer, NC_CLOBBER);
/* create image dimensions */
int image_dims = 3; // X, Y, Z
int XSIZE = valResolution; //64
int YSIZE = valResolution; //64
int ZSIZE = valSlices; //16
/* create dimension variable */
int dim[MAX_VAR_DIMS];
dim[2] = ncdimdef(fileid, MIxspace, XSIZE);
dim[1] = ncdimdef(fileid, MIyspace, YSIZE);
dim[0] = ncdimdef(fileid, MIzspace, ZSIZE);
/* define image varibale */
int imgid;
imgid = ncvardef(fileid, MIimage, NC_DOUBLE,
image_dims, dim);
/* define max and min for image */
int maxid;
int minid;
maxid = ncvardef(fileid, MIimagemax, NC_DOUBLE, 0, NULL);
minid = ncvardef(fileid, MIimagemin, NC_DOUBLE, 0,
NULL);
/* end definition mode */
ncendef(fileid);
/* writing image max and min */
ncvarput1(fileid, maxid, NULL, &max);
ncvarput1(fileid, minid, NULL, &min);
long count[MAX_VAR_DIMS];
long start[MAX_VAR_DIMS];
/* last dimension varies fastest. in our data set, X
changes fastest, followed by Y and then Z */
count[2] = XSIZE;
count[1] = YSIZE;
count[0] = ZSIZE;
start[2] = 0;
start[1] = 0;
start[0] = 0;
// vetcor funtionalSlicesArr has image data
vector<double> temp(length);
int bn = i * length;
int en = bn + length;
temp.insert(temp.begin(),functionalSlicesArr.begin()+bn,
functionalSlicesArr.begin() + en);
double imageArr[length];
for(int i=0; i < length; i++)
imageArr[i] = temp[i];
ncvarput(fileid, imgid, start, count, imageArr);
ncclose(fileid);
============================