Skip to content
Snippets Groups Projects
Commit 220bc12d authored by Mark Jenkinson's avatar Mark Jenkinson
Browse files

Fully working version, with all bells and whistles.

Some testing has been done, but more will be done with FEAT4 soon.
parent efd8d68b
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,19 @@ Option<string> outmax(string("--omax"), string(""), ...@@ -78,6 +78,19 @@ Option<string> outmax(string("--omax"), string(""),
Option<string> outmean(string("--omean"), string(""), Option<string> outmean(string("--omean"), string(""),
string("filename for output of mean image"), string("filename for output of mean image"),
false, requires_argument); false, requires_argument);
Option<string> transformname(string("-x,--xfm"), string(""),
string("filename for transform of input->talairach volume"),
false, requires_argument);
Option<string> talvolname(string("--talvol"), string(""),
string("filename for talairach volume"),
false, requires_argument);
template <class T>
void print_dims(const volume<T>& vol)
{
cout << "dims=(" << vol.xdim()*vol.xsign() << ","
<< vol.ydim()*vol.ysign() << "," << vol.zdim()*vol.zsign() << ")";
}
template <class T> template <class T>
...@@ -139,6 +152,23 @@ void addoriginoffset(vector<triple<T> >& coords, const volume<S>& vol) ...@@ -139,6 +152,23 @@ void addoriginoffset(vector<triple<T> >& coords, const volume<S>& vol)
} }
template <class T, class S>
void applyvoxelxfm(vector<triple<T> >& coords, const Matrix& mat,
const volume<S>& source, const volume<S>& dest)
{
Matrix voxmat;
voxmat = dest.sampling_mat().i() * mat * source.sampling_mat();
ColumnVector vec(4);
for (unsigned int n=0; n<coords.size(); n++) {
vec << coords[n].x << coords[n].y << coords[n].z << 1.0;
vec = voxmat * vec; // apply voxel xfm
coords[n].x = vec(1);
coords[n].y = vec(2);
coords[n].z = vec(3);
}
}
template <class T> template <class T>
void get_stats(const volume<int>& labelim, const volume<T>& origim, void get_stats(const volume<int>& labelim, const volume<T>& origim,
vector<int>& size, vector<int>& size,
...@@ -258,18 +288,38 @@ void print_results(const vector<int>& idx, ...@@ -258,18 +288,38 @@ void print_results(const vector<int>& idx,
copyconvert(maxpos,fmaxpos); copyconvert(maxpos,fmaxpos);
copyconvert(cog,fcog); copyconvert(cog,fcog);
copyconvert(copemaxpos,fcopemaxpos); copyconvert(copemaxpos,fcopemaxpos);
if (medxcoords.value()) { volume<T> talvol;
if ( !transformname.unset() && !talvolname.unset() ) {
read_volume(talvol,talvolname.value());
Matrix trans;
read_matrix(trans,transformname.value(),zvol);
if (verbose.value()) {
cout << "Transformation Matrix filename = "<<transformname.value()<<endl;
cout << trans.Nrows() << " " << trans.Ncols() << endl;
cout << "Transformation Matrix = " << endl;
cout << trans << endl;
}
applyvoxelxfm(fmaxpos,trans,zvol,talvol);
applyvoxelxfm(fcog,trans,zvol,talvol);
if (!copename.unset()) applyvoxelxfm(fcopemaxpos,trans,zvol,talvol);
}
if ( medxcoords.value() && (!mm.value()) ) {
vox2medxcoord(fmaxpos,zvol); vox2medxcoord(fmaxpos,zvol);
vox2medxcoord(fcog,zvol); vox2medxcoord(fcog,zvol);
if (!copename.unset()) vox2medxcoord(fcopemaxpos,cope); if (!copename.unset()) vox2medxcoord(fcopemaxpos,cope);
} }
if (mm.value()) { if (mm.value()) {
addoriginoffset(fmaxpos,zvol); const volume<T> *refvol = &zvol;
addoriginoffset(fcog,zvol); if ( !transformname.unset() && !talvolname.unset() ) refvol = &talvol;
if (!copename.unset()) addoriginoffset(fcopemaxpos,zvol); if (verbose.value()) {
vox2mmcoord(fmaxpos,zvol); cout << "Using origin : " << (refvol->getorigin()).t() << endl;
vox2mmcoord(fcog,zvol); }
if (!copename.unset()) vox2mmcoord(fcopemaxpos,cope); addoriginoffset(fmaxpos,*refvol);
addoriginoffset(fcog,*refvol);
if (!copename.unset()) addoriginoffset(fcopemaxpos,*refvol);
vox2mmcoord(fmaxpos,*refvol);
vox2mmcoord(fcog,*refvol);
if (!copename.unset()) vox2mmcoord(fcopemaxpos,*refvol); // used cope before
} }
string units=" (vox)"; string units=" (vox)";
...@@ -326,6 +376,7 @@ int fmrib_main(int argc, char *argv[]) ...@@ -326,6 +376,7 @@ int fmrib_main(int argc, char *argv[])
// read in the volume // read in the volume
volume<T> zvol, mask, cope; volume<T> zvol, mask, cope;
read_volume(zvol,inputname.value()); read_volume(zvol,inputname.value());
if (verbose.value()) {cout<<"Zvol: "; print_dims(zvol); cout<<endl;}
if ( fractional.value() ) { if ( fractional.value() ) {
float frac = th; float frac = th;
...@@ -334,9 +385,11 @@ int fmrib_main(int argc, char *argv[]) ...@@ -334,9 +385,11 @@ int fmrib_main(int argc, char *argv[])
mask = zvol; mask = zvol;
mask.threshold((T) th); mask.threshold((T) th);
if (minv.value()) { mask = ((T) 1) - mask; } if (minv.value()) { mask = ((T) 1) - mask; }
if (verbose.value()) {cout<<"Mask: "; print_dims(mask); cout<<endl;}
// Find the connected components // Find the connected components
labelim = connected_components(mask,numconnected.value()); labelim = connected_components(mask,numconnected.value());
if (verbose.value()) {cout<<"Labelim: "; print_dims(labelim); cout<<endl;}
// process according to the output format // process according to the output format
get_stats(labelim,zvol,size,maxvals,meanvals,maxpos,cog,minv.value()); get_stats(labelim,zvol,size,maxvals,meanvals,maxpos,cog,minv.value());
...@@ -431,43 +484,64 @@ int main(int argc,char *argv[]) ...@@ -431,43 +484,64 @@ int main(int argc,char *argv[])
OptionParser options(title, examples); OptionParser options(title, examples);
options.add(inputname); try {
options.add(thresh); options.add(inputname);
options.add(outindex); options.add(thresh);
options.add(outthresh); options.add(outindex);
options.add(outsize); options.add(outthresh);
options.add(outmax); options.add(outsize);
options.add(outmean); options.add(outmax);
options.add(pthresh); options.add(outmean);
options.add(copename); options.add(pthresh);
options.add(voxvol); options.add(copename);
options.add(dLh); options.add(voxvol);
options.add(fractional); options.add(dLh);
options.add(numconnected); options.add(fractional);
options.add(medxcoords); options.add(numconnected);
options.add(mm); options.add(medxcoords);
options.add(minv); options.add(mm);
options.add(no_table); options.add(minv);
options.add(verbose); options.add(no_table);
options.add(help); options.add(transformname);
options.add(talvolname);
options.parse_command_line(argc, argv); options.add(verbose);
options.add(help);
if ( (help.value()) || (!options.check_compulsory_arguments(true)) )
{ options.parse_command_line(argc, argv);
options.usage();
exit(EXIT_FAILURE);
}
if ( (!pthresh.unset()) && (dLh.unset() || voxvol.unset()) ) if ( (help.value()) || (!options.check_compulsory_arguments(true)) )
{ {
options.usage(); options.usage();
cerr << endl exit(EXIT_FAILURE);
<< "Both --dlh and --volume MUST be set if --pthresh is used!" }
<< endl;
exit(EXIT_FAILURE); if ( (!pthresh.unset()) && (dLh.unset() || voxvol.unset()) )
} {
options.usage();
cerr << endl
<< "Both --dlh and --volume MUST be set if --pthresh is used."
<< endl;
exit(EXIT_FAILURE);
}
if ( ( !transformname.unset() && talvolname.unset() ) ||
( transformname.unset() && (!talvolname.unset()) ) )
{
options.usage();
cerr << endl
<< "Both --xfm and --talvol MUST be set together."
<< endl;
exit(EXIT_FAILURE);
}
} catch(X_OptionError& e) {
options.usage();
cerr << endl << e.what() << endl;
exit(EXIT_FAILURE);
} catch(std::exception &e) {
cerr << e.what() << endl;
}
return call_fmrib_main(dtype(inputname.value()),argc,argv); return call_fmrib_main(dtype(inputname.value()),argc,argv);
} }
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