forked from MRtrix3/mrtrix3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MRtrix3#1507 from MRtrix3/streamline_length_precise
Precise quantification of streamlines lengths
- Loading branch information
Showing
25 changed files
with
410 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ void usage () | |
|
||
AUTHOR = "Robert E. Smith ([email protected])"; | ||
|
||
SYNOPSIS = "Calculate statistics on streamlines length"; | ||
SYNOPSIS = "Calculate statistics on streamlines lengths"; | ||
|
||
ARGUMENTS | ||
+ Argument ("tracks_in", "the input track file").type_tracks_in(); | ||
|
@@ -66,9 +66,6 @@ void usage () | |
+ Option ("dump", "dump the streamlines lengths to a text file") | ||
+ Argument ("path").type_file_out() | ||
|
||
+ Option ("explicit", "explicitly calculate the length of each streamline, " | ||
"ignoring any step size information present in the header") | ||
|
||
+ Option ("ignorezero", "do not generate a warning if the track file contains streamlines with zero length") | ||
|
||
+ Tractography::TrackWeightsInOption; | ||
|
@@ -111,8 +108,9 @@ void run () | |
size_t count = 0, header_count = 0; | ||
float min_length = std::numeric_limits<float>::infinity(); | ||
float max_length = -std::numeric_limits<float>::infinity(); | ||
double sum_lengths = 0.0, sum_weights = 0.0; | ||
vector<double> histogram; | ||
size_t empty_streamlines = 0, zero_length_streamlines = 0; | ||
default_type sum_lengths = 0.0, sum_weights = 0.0; | ||
vector<default_type> histogram; | ||
vector<LW> all_lengths; | ||
all_lengths.reserve (header_count); | ||
|
||
|
@@ -123,14 +121,9 @@ void run () | |
if (properties.find ("count") != properties.end()) | ||
header_count = to<size_t> (properties["count"]); | ||
|
||
if (!get_options ("explicit").size()) { | ||
step_size = get_step_size (properties); | ||
if (!std::isfinite (step_size) || !step_size) { | ||
INFO ("Streamline step size undefined in header; lengths will be calculated manually"); | ||
if (get_options ("histogram").size()) { | ||
WARN ("Do not have streamline step size with which to construct histogram; histogram will be generated using 1mm bin widths"); | ||
} | ||
} | ||
step_size = get_step_size (properties); | ||
if ((!std::isfinite (step_size) || !step_size) && get_options ("histogram").size()) { | ||
WARN ("Do not have streamline step size with which to bin histogram; histogram will be generated using 1mm bin widths"); | ||
} | ||
|
||
std::unique_ptr<File::OFStream> dump; | ||
|
@@ -142,7 +135,7 @@ void run () | |
Streamline<> tck; | ||
while (reader (tck)) { | ||
++count; | ||
const float length = std::isfinite (step_size) ? tck.calc_length (step_size) : tck.calc_length(); | ||
const float length = Tractography::length (tck); | ||
if (std::isfinite (length)) { | ||
min_length = std::min (min_length, length); | ||
max_length = std::max (max_length, length); | ||
|
@@ -153,15 +146,28 @@ void run () | |
while (histogram.size() <= index) | ||
histogram.push_back (0.0); | ||
histogram[index] += tck.weight; | ||
if (!length) | ||
++zero_length_streamlines; | ||
} else { | ||
++empty_streamlines; | ||
} | ||
if (dump) | ||
(*dump) << length << "\n"; | ||
++progress; | ||
} | ||
} | ||
|
||
if (histogram.size() && histogram.front() && !get_options ("ignorezero").size()) | ||
WARN ("read " + str(histogram.front()) + " zero-length tracks"); | ||
if (!get_options ("ignorezero").size() && (empty_streamlines || zero_length_streamlines)) { | ||
std::string s ("read"); | ||
if (empty_streamlines) { | ||
s += " " + str(empty_streamlines) + " empty streamlines"; | ||
if (zero_length_streamlines) | ||
s += " and"; | ||
} | ||
if (zero_length_streamlines) | ||
s += " " + str(zero_length_streamlines) + " streamlines with zero length (one vertex only)"; | ||
WARN (s); | ||
} | ||
if (count != header_count) | ||
WARN ("expected " + str(header_count) + " tracks according to header; read " + str(count)); | ||
if (!std::isfinite (min_length)) | ||
|
@@ -177,7 +183,7 @@ void run () | |
// Perform a weighted median calculation | ||
std::sort (all_lengths.begin(), all_lengths.end()); | ||
size_t median_index = 0; | ||
double sum = sum_weights - all_lengths[0].get_weight(); | ||
default_type sum = sum_weights - all_lengths[0].get_weight(); | ||
while (sum > 0.5 * sum_weights) { sum -= all_lengths[++median_index].get_weight(); } | ||
median_length = all_lengths[median_index].get_length(); | ||
} else { | ||
|
@@ -187,10 +193,10 @@ void run () | |
median_length = NaN; | ||
} | ||
|
||
double stdev = 0.0; | ||
default_type ssd = 0.0; | ||
for (vector<LW>::const_iterator i = all_lengths.begin(); i != all_lengths.end(); ++i) | ||
stdev += i->get_weight() * Math::pow2 (i->get_length() - mean_length); | ||
stdev = sum_weights ? (std::sqrt (stdev / (((count - 1) / float(count)) * sum_weights))) : NaN; | ||
ssd += i->get_weight() * Math::pow2 (i->get_length() - mean_length); | ||
const float stdev = sum_weights ? (std::sqrt (ssd / (((count - 1) / default_type(count)) * sum_weights))) : NaN; | ||
|
||
vector<std::string> fields; | ||
auto opt = get_options ("output"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.