Skip to content
Snippets Groups Projects
Commit a25f2e8e authored by Matthew Webster's avatar Matthew Webster
Browse files

index mask mode for SS add to NewNew

parent cf32e692
No related branches found
No related tags found
No related merge requests found
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
using namespace NEWIMAGE; using namespace NEWIMAGE;
void print_usage(const string& progname) { int print_usage(const string& progname) {
cout << "Usage: fslstats [-t] <input> [options]" << endl << endl; cout << "Usage: fslstats [preoptions] <input> [options]" << endl << endl;
cout << "-t will give a separate output line for each 3D volume of a 4D timeseries" << endl; cout << "preoption -t will give a separate output line for each 3D volume of a 4D timeseries" << endl;
cout << "preoption -K < indexMask > will generate seperate n submasks from indexMask, for indexvalues 1..n where n is the maximum index value in indexMask, and generate statistics for each submask" << endl;
cout << "Note - options are applied in order, e.g. -M -l 10 -M will report the non-zero mean, apply a threshold and then report the new nonzero mean" << endl << endl; cout << "Note - options are applied in order, e.g. -M -l 10 -M will report the non-zero mean, apply a threshold and then report the new nonzero mean" << endl << endl;
cout << "-l <lthresh> : set lower threshold" << endl; cout << "-l <lthresh> : set lower threshold" << endl;
cout << "-u <uthresh> : set upper threshold" << endl; cout << "-u <uthresh> : set upper threshold" << endl;
...@@ -44,6 +45,7 @@ void print_usage(const string& progname) { ...@@ -44,6 +45,7 @@ void print_usage(const string& progname) {
cout << "-h <nbins> : output a histogram (for the thresholded/masked voxels only) with nbins" << endl; cout << "-h <nbins> : output a histogram (for the thresholded/masked voxels only) with nbins" << endl;
cout << "-H <nbins> <min> <max> : output a histogram (for the thresholded/masked voxels only) with nbins and histogram limits of min and max" << endl << endl; cout << "-H <nbins> <min> <max> : output a histogram (for the thresholded/masked voxels only) with nbins and histogram limits of min and max" << endl << endl;
cout << "Note - thresholds are not inclusive ie lthresh<allowed<uthresh" << endl; cout << "Note - thresholds are not inclusive ie lthresh<allowed<uthresh" << endl;
return 1;
} }
// Some specialised nonzero functions just for speedup // Some specialised nonzero functions just for speedup
...@@ -103,28 +105,39 @@ int generate_masks(volume4D<float>& mask, volume4D<float>& masknz, const volume4 ...@@ -103,28 +105,39 @@ int generate_masks(volume4D<float>& mask, volume4D<float>& masknz, const volume4
return generateNonZeroMask(mask,masknz,input); return generateNonZeroMask(mask,masknz,input);
} }
int fmrib_main_float(int argc, char* argv[],const bool timeseriesMode) int fmrib_main_float(int argc, char* argv[],const bool timeseriesMode, const string& indexMaskName)
{ {
cout.setf(ios::dec); cout.setf(ios::dec);
cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::left, ios::adjustfield); cout.setf(ios::left, ios::adjustfield);
cout.precision(6); cout.precision(6);
volume<float> vol, inputMaster;
int nTimepoints(1); volume<int> indexMask;
volume4D<float> vol, inputMaster; if ( timeseriesMode || indexMaskName != "" )
if ( timeseriesMode) { read_volume(inputMaster,argv[1]);
read_volume4D(inputMaster,argv[1]); else
nTimepoints=inputMaster.tsize(); read_volume(vol,argv[1]);
} else volume<float> & indexMaster = (timeseriesMode ) ? vol : inputMaster;
read_volume4D(vol,argv[1]); if ( indexMaskName != "" )
read_volume(indexMask,indexMaskName);
for ( int timepoint=0; timepoint < nTimepoints ; timepoint++ ) int nTimepoints((timeseriesMode) ? inputMaster.tsize() : 1), nIndices((indexMaskName != "") ? indexMask.max() : 1);
{ for ( int timepoint=0; timepoint < nTimepoints ; timepoint++ ) {
for ( int index=1; index <= nIndices; index++ ) {
if ( timeseriesMode ) if ( timeseriesMode )
vol=inputMaster[timepoint]; vol=inputMaster[timepoint];
volume4D<float> mask, masknz; volume<float> mask, masknz;
float lthr(numeric_limits<float>::min()); float lthr(numeric_limits<float>::min());
float uthr(numeric_limits<float>::max()); float uthr(numeric_limits<float>::max());
if ( indexMask.nvoxels() ) {
if ( indexMask.dimensionality() > 3 ) {
cerr << "Index mask must be 3D" << endl;
return 3;
}
copyconvert(indexMask,mask);
mask.binarise(index-1,index+1,exclusive);
vol=indexMaster*mask;
generateNonZeroMask(mask,masknz,vol);
}
int narg(2); int narg(2);
while (narg<argc) { while (narg<argc) {
...@@ -452,7 +465,9 @@ int fmrib_main_float(int argc, char* argv[],const bool timeseriesMode) ...@@ -452,7 +465,9 @@ int fmrib_main_float(int argc, char* argv[],const bool timeseriesMode)
narg++; narg++;
} }
cout << endl; }
cout << endl;
} }
return 0; return 0;
} }
...@@ -464,28 +479,30 @@ int main(int argc,char *argv[]) ...@@ -464,28 +479,30 @@ int main(int argc,char *argv[])
Tracer tr("main"); Tracer tr("main");
string progname(argv[0]); string progname(argv[0]);
int retval(-1);
bool timeseriesMode(false); bool timeseriesMode(false);
if ( argc > 2 && string(argv[1])=="-t" ) { string indexMask("");
while ( argc > 2 && ( string(argv[1])=="-t" || string(argv[1]) =="-K" ) ) {
if ( string(argv[1])=="-t" )
timeseriesMode=true;
if ( string(argv[1])=="-K" ) {
indexMask=string(argv[2]);
argv++;
argc--;
}
argv++; argv++;
argc--; argc--;
timeseriesMode=true;
} }
if (argc < 3 )
return print_usage(progname);
try { try {
if (argc < 3 ) { return fmrib_main_float(argc,argv,timeseriesMode,indexMask);
print_usage(progname);
return 1;
}
retval = fmrib_main_float(argc,argv,timeseriesMode);
} catch(std::exception &e) { } catch(std::exception &e) {
cerr << e.what() << endl; cerr << e.what() << endl;
} catch (...) { } catch (...) {
// do nothing - just exit without garbage message // do nothing - just exit without garbage message
} }
return retval; return -1;
} }
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