Hello Chris,
If you use C++, then the newimage library is _much_ more user-friendly for dealing with image files ( almost all FSL software uses this library ). For an fslio/niftiio only example - the following code outlines one way to read and write image data.
Kind Regards
Matthew
FSLIO* in;
FSLIO* out;
short x,y,z,v,dt;
void *buffer;
int bufsize;
in = FslOpen(filename,"rb");
FslGetDim(fslio,&x,&y,&z,&v);
bufsize = x * y * z * v * (FslGetDataType(in,&dt) / 8);
buffer = (void *) calloc(bufsize,1);
FslReadVolumes(in,buffer,v);
FslClose(in);
/* Write code to modify data here*/
out = FslOpen(filename2,"wb")
FslCloneHeader(out,in)
FslWriteHeader(out);
FslWriteVolumes(out,buffer,out->niftiptr->dim[4]);
FslClose(out);
> Dear FSL team,
>
> Firstly, thanks for your work, it's really helpful for studies.
>
> I use some functions like fslmaths merge etc ... and I have to make some statistics in results of these functions.
> But to do that I need to create new nifti images and if possible write and change values in nifti files.
> So, I tried to use fsl (fslio.c) and niftiio source files to code a module in C to access and modify nifti files but I cannot write data in nifti files ( I tried FslWriteAllVolumes but it doesn't write any data) and when I open a nifti file with the write option, it destroy my input nifti file.
>
> Maybe I misunderstood how to use fslio.c. I try to write only in C because I'm more comfortable with, but if I have to code in C++ I can. I saw in .cc files, you don't use fslio.c functions but directly nifti1_io.c functions, should I do like this to write in images ?
>
> In fact, I try to recode some functions of the R module "oro.nifti" because it consume several times the space of an input nifti image in memory and with large nifti it's not possible to use it so I try to use you I/O functions to optimize this, because fsl can compute on really large nifti so I think it's a good example to follow.
>
> Thanks in advance, and thanks for your work,
>
> Chris
|