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

Fixed problems with initial masking - bugs now gone from -P and -k and -l and -u

parent 328830e5
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@ using namespace NEWIMAGE;
using namespace MISCMATHS;
bool masks_used=false;
bool lthr_used=false;
bool uthr_used=false;
void print_usage(const string& progname) {
cout << "Usage: avwstats++ <input> [options]" << endl << endl;
......@@ -124,10 +126,8 @@ template <class T>
int generate_masks(volume4D<T> &mask, volume4D<T> &masknz, const volume4D<T> &vin,
T& lthr, T& uthr)
{
if ((lthr==42) && (uthr==8)) { // my case of "uninitialised"
lthr=vin.min()-1;
uthr=vin.max()+1;
}
if (!lthr_used) { lthr=vin.min()-1; }
if (!uthr_used) { uthr=vin.max()+1; }
mask = binarise(vin,lthr,uthr,exclusive);
masknz = mask * ((T) 1 - binarise(vin,(T) 0.0, (T) 0.0));
return 0;
......@@ -153,11 +153,9 @@ int fmrib_main(int argc, char* argv[])
volume4D<T> vin, vol, mask, masknz;
read_volume4D(vol,argv[1]);
T lthr=42, uthr=8; // special "uninitialised" codes
T lthr=0, uthr=0; // these initial values are not used
if (masks_used) {
vin = vol;
lthr=vin.min()-1;
uthr=vin.max()+1;
generate_masks(mask,masknz,vin,lthr,uthr);
vol = vin * mask;
}
......@@ -197,6 +195,7 @@ int fmrib_main(int argc, char* argv[])
} else if (sarg=="-w") {
if (!masks_used) {
if (vin.nvoxels()<1) { vin = vol; }
masks_used=true;
generate_masks(mask,masknz,vin,lthr,uthr);
vol = vin * mask;
}
......@@ -225,6 +224,7 @@ int fmrib_main(int argc, char* argv[])
} else if (sarg=="-e") {
if (!masks_used) {
if (vin.nvoxels()<1) { vin = vol; }
masks_used=true;
generate_masks(mask,masknz,vin,lthr,uthr);
vol = vin * mask;
}
......@@ -260,10 +260,20 @@ int fmrib_main(int argc, char* argv[])
exit(2);
}
read_volume4D(mask,argv[narg]);
if (!samesize(mask,vol)) {
if (!samesize(mask[0],vol[0])) {
cerr << "Mask and image must be the same size" << endl;
exit(3);
}
if ( mask.tsize() > vol.tsize() ) {
cerr << "Mask and image must be the same size" << endl;
exit(3);
}
if ( mask.tsize() != vol.tsize() ) {
// copy the last max volume until the correct size is reached
while (mask.tsize() < vol.tsize() ) {
mask.addvolume(mask[mask.maxt()]);
}
}
if (!masks_used) {
masks_used=true;
vin = vol;
......@@ -284,6 +294,7 @@ int fmrib_main(int argc, char* argv[])
cerr << "Must specify an argument to -l" << endl;
exit(2);
}
lthr_used=true;
if (!masks_used) {
masks_used=true;
vin = vol;
......@@ -298,6 +309,7 @@ int fmrib_main(int argc, char* argv[])
cerr << "Must specify an argument to -u" << endl;
exit(2);
}
uthr_used=true;
if (!masks_used) {
masks_used=true;
vin = vol;
......@@ -389,6 +401,12 @@ int fmrib_main(int argc, char* argv[])
cerr << "Percentile must be between 0 and 100" << endl;
exit(1);
}
if (!masks_used) {
if (vin.nvoxels()<1) { vin = vol; }
masks_used=true;
generate_masks(mask,masknz,vin,lthr,uthr);
vol = vin * mask;
}
cout << vol.percentile((float) n/100.0,masknz) << " ";
} else {
cerr << "Unrecognised option: " << sarg << endl;
......
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