Skip to content
Snippets Groups Projects
Commit 9ced3739 authored by Stephen Smith's avatar Stephen Smith
Browse files

CVS: ----------------------------------------------------------------------

parent 80761757
No related branches found
No related tags found
No related merge requests found
...@@ -154,76 +154,54 @@ namespace MISCMATHS { ...@@ -154,76 +154,54 @@ namespace MISCMATHS {
volinfo.miscinfo = FslInit(); volinfo.miscinfo = FslInit();
FslCloneHeader(volinfo.miscinfo,IP); FslCloneHeader(volinfo.miscinfo,IP);
size_t imagesize=x*y*z*v; size_t imagesize=x*y*z;
FslGetDataType(IP,&type); FslGetDataType(IP,&type);
output.ReSize(v,x*y*z); output.ReSize(v,x*y*z);
switch(type) for(size_t i=1; i<=(size_t)v; i++)
{ {
case DT_SIGNED_SHORT: switch(type)
{ {
short* sbuffer=new short[imagesize]; case DT_SIGNED_SHORT:
FslReadVolumes(IP, sbuffer,v);
size_t volsize = volinfo.x*volinfo.y*volinfo.z;
size_t volstart = 1;
for(size_t i=1; i<=(size_t)v; i++)
{ {
volstart = (i-1)*volsize; short* sbuffer=new short[imagesize];
for(size_t j = 1; j<=(size_t)x*y*z; j++) FslReadVolumes(IP, sbuffer,1);
for(size_t j = 1; j<=imagesize; j++)
{ {
if (doscaling==0) { output(i,j)=sbuffer[volstart+j-1]; } if (doscaling==0) { output(i,j)=sbuffer[j-1]; }
else { output(i,j)=(slope * sbuffer[volstart+j-1]) + intercept;} else { output(i,j)=(slope * sbuffer[j-1]) + intercept;}
} }
delete[] sbuffer;
} }
break;
delete[] sbuffer; case DT_FLOAT:
}
break;
case DT_FLOAT:
{
float* fbuffer=new float[imagesize];
FslReadVolumes(IP,fbuffer,v);
size_t volsize = volinfo.x*volinfo.y*volinfo.z;
size_t volstart = 1;
for(size_t i=1; i<=(size_t)v; i++)
{ {
volstart = (i-1)*volsize; float* fbuffer=new float[imagesize];
for(size_t j = 1; j<=(size_t)x*y*z; j++) FslReadVolumes(IP,fbuffer,1);
for(size_t j = 1; j<=imagesize; j++)
{ {
if (doscaling==0) { output(i,j)=fbuffer[volstart+j-1]; } if (doscaling==0) { output(i,j)=fbuffer[j-1]; }
else { output(i,j)=(slope * fbuffer[volstart+j-1]) + intercept;} else { output(i,j)=(slope * fbuffer[j-1]) + intercept;}
} }
delete[] fbuffer;
} }
delete[] fbuffer; break;
} case DT_UNSIGNED_CHAR:
break;
case DT_UNSIGNED_CHAR:
{
unsigned char* cbuffer=new unsigned char[imagesize];
FslReadVolumes(IP,cbuffer,v);
size_t volsize = volinfo.x*volinfo.y*volinfo.z;
size_t volstart = 1;
for(size_t i=1; i<=(size_t)v; i++)
{ {
volstart = (i-1)*volsize; unsigned char* cbuffer=new unsigned char[imagesize];
for(size_t j = 1; j<=(size_t)x*y*z; j++) FslReadVolumes(IP,cbuffer,1);
for(size_t j = 1; j<=imagesize; j++)
{ {
if (doscaling==0) { output(i,j)=cbuffer[volstart+j-1]; } if (doscaling==0) { output(i,j)=cbuffer[j-1]; }
else { output(i,j)=(slope * cbuffer[volstart+j-1]) + intercept;} else { output(i,j)=(slope * cbuffer[j-1]) + intercept;}
} }
delete[] cbuffer;
} }
delete[] cbuffer; break;
} default:
break; perror("FslRead: DT not supported");
default: }
perror("FslRead: DT not supported");
} }
FslClose(IP); FslClose(IP);
...@@ -252,23 +230,58 @@ namespace MISCMATHS { ...@@ -252,23 +230,58 @@ namespace MISCMATHS {
FslSetIntent(OP, volinfo.intent_code, volinfo.intent_p1, volinfo.intent_p2, FslSetIntent(OP, volinfo.intent_code, volinfo.intent_p1, volinfo.intent_p2,
volinfo.intent_p3); volinfo.intent_p3);
int volStart = 1;
int volSize = getNumSeries(); int volSize = getNumSeries();
int volNum = getNumVolumes(); int volNum = getNumVolumes();
float *qv = new float[volSize*volNum]; FslWriteHeader(OP);
float *qv = new float[volSize];
for(int i = 1; i<= volNum; i++) for(int i = 1; i<= volNum; i++)
{ {
volStart = (i-1)*volSize;
for(int j = 1; j <= volSize; j++) for(int j = 1; j <= volSize; j++)
{ qv[j-1] = (*this)(i,j);
qv[volStart+j-1] = (*this)(i,j); FslWriteVolumes(OP, qv, 1);
}
} }
delete [] qv;
FslClose(OP);
}
void VolumeSeries::writeThresholdedSeriesAsFloat(const VolumeInfo& pvolinfo,const ColumnVector& in,const string& fname)
{
volinfo = pvolinfo;
preThresholdPositions = in;
Time_Tracer ts(string("VolumeSeries::writeThresholdedSeriesAsFloat" + fname).c_str());
FSLIO* OP = FslOpen(fname.c_str(), "wb");
FslCloneHeader(OP,volinfo.miscinfo);
FslSetDim(OP,volinfo.x, volinfo.y, volinfo.z, volinfo.v);
FslSetVoxDim(OP,volinfo.vx, volinfo.vy, volinfo.vz, volinfo.tr);
FslSetDataType(OP, DT_FLOAT);
FslSetIntent(OP, volinfo.intent_code, volinfo.intent_p1, volinfo.intent_p2, volinfo.intent_p3);
int volSize = getUnthresholdNumSeries();
int numThresholdedSeries = getNumSeries();
int volNum = getNumVolumes();
FslWriteHeader(OP); FslWriteHeader(OP);
FslWriteVolumes(OP, qv, volNum);
float *qv = new float[volSize];
for(int i = 1; i<= volNum; i++)
{
for(int j = 1; j <= volSize; j++)
qv[j-1]=0;
for(int j = 1; j <= numThresholdedSeries; j++)
qv[int(preThresholdPositions(j))-1] = (*this)(i,j);
FslWriteVolumes(OP, qv, 1);
}
delete [] qv; delete [] qv;
......
...@@ -98,6 +98,7 @@ namespace MISCMATHS { ...@@ -98,6 +98,7 @@ namespace MISCMATHS {
void read(const string& fname); void read(const string& fname);
void writeAsInt(const string& fname); void writeAsInt(const string& fname);
void writeAsFloat(const string& fname); void writeAsFloat(const string& fname);
void writeThresholdedSeriesAsFloat(const VolumeInfo& pvolinfo,const ColumnVector& in,const string& fname);
void replaceMeans(); void replaceMeans();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment