Skip to content

Commit

Permalink
Merge pull request #2273 from MRtrix3/fixelconnectivity
Browse files Browse the repository at this point in the history
fixelconnectivity: Enhancements
  • Loading branch information
Lestropie authored Jul 19, 2023
2 parents 5a3a8bf + cdc1c3b commit 86eb1ea
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 158 deletions.
59 changes: 50 additions & 9 deletions cmd/fixelconnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#include "command.h"
#include "fixel/fixel.h"
#include "fixel/helpers.h"
#include "fixel/index_remapper.h"

#include "dwi/tractography/weights.h"
#include "fixel/matrix.h"



#define DEFAULT_ANGLE_THRESHOLD 45.0
#define DEFAULT_CONNECTIVITY_THRESHOLD 0.01

Expand Down Expand Up @@ -60,7 +62,17 @@ void usage ()
+ Argument ("value").type_float (0.0, 90.0)

+ Option ("mask", "provide a fixel data file containing a mask of those fixels to be computed; fixels outside the mask will be empty in the output matrix")
+ Argument ("file").type_image_in();
+ Argument ("file").type_image_in()

+ DWI::Tractography::TrackWeightsInOption

+ OptionGroup ("Options for additional outputs to be generated")

+ Option ("count", "export a fixel data file encoding the number of connections for each fixel")
+ Argument ("path").type_image_out()

+ Option ("extent", "export a fixel data file encoding the extent of connectivity (sum of weights) for each fixel")
+ Argument ("path").type_image_out();

}

Expand All @@ -69,6 +81,20 @@ using value_type = float;
using Fixel::index_type;



template <class WriterType>
void set_optional_outputs (WriterType& writer)
{
auto opt = get_options ("count");
if (opt.size())
writer.set_count_path (opt[0][0]);
opt = get_options ("extent");
if (opt.size())
writer.set_extent_path (opt[0][0]);
}



void run()
{
const value_type connectivity_threshold = get_option_value ("connectivity", value_type(DEFAULT_CONNECTIVITY_THRESHOLD));
Expand Down Expand Up @@ -96,14 +122,29 @@ void run()
fixel_mask.value() = true;
}

auto connectivity_matrix = Fixel::Matrix::generate (argument[1],
index_image,
fixel_mask,
angular_threshold);
if (get_options ("tck_weights_in").size()) {

auto connectivity_matrix = Fixel::Matrix::generate_weighted (argument[1],
index_image,
fixel_mask,
angular_threshold);

Fixel::Matrix::normalise_and_write (connectivity_matrix,
connectivity_threshold,
argument[2]);
Fixel::Matrix::Writer<Fixel::Matrix::InitMatrixWeighted> writer (connectivity_matrix, connectivity_threshold);
set_optional_outputs (writer);
writer.save (argument[2]);

} else {

auto connectivity_matrix = Fixel::Matrix::generate_unweighted (argument[1],
index_image,
fixel_mask,
angular_threshold);

Fixel::Matrix::Writer<Fixel::Matrix::InitMatrixUnweighted> writer (connectivity_matrix, connectivity_threshold);
set_optional_outputs (writer);
writer.save (argument[2]);

}

}

2 changes: 1 addition & 1 deletion core/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace MR
if (check_overwrite_files_func)
check_overwrite_files_func (name);
else
throw Exception ("output file \"" + name + "\" already exists (use -force option to force overwrite)");
throw Exception ("output path \"" + name + "\" already exists (use -force option to force overwrite)");
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/fixel/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace MR
{
class InvalidFixelDirectoryException : public Exception
{
{
public:
InvalidFixelDirectoryException (const std::string& msg) : Exception(msg) {}
InvalidFixelDirectoryException (const Exception& previous_exception, const std::string& msg)
Expand Down Expand Up @@ -306,6 +306,7 @@ namespace MR
header.size(0) = nfixels;
header.size(1) = 1;
header.size(2) = 1;
header.spacing(0) = header.spacing(1) = header.spacing(2) = 1.0;
header.stride(0) = 1;
header.stride(1) = 2;
header.stride(2) = 3;
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/commands/fixelconnectivity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ Options that influence generation of the connectivity matrix / matrices

- **-mask file** provide a fixel data file containing a mask of those fixels to be computed; fixels outside the mask will be empty in the output matrix

- **-tck_weights_in path** specify a text scalar file containing the streamline weights

Options for additional outputs to be generated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- **-count path** export a fixel data file encoding the number of connections for each fixel

- **-extent path** export a fixel data file encoding the extent of connectivity (sum of weights) for each fixel

Standard options
^^^^^^^^^^^^^^^^

Expand Down
1 change: 0 additions & 1 deletion src/dwi/tractography/weights.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace MR
{
namespace DWI
{

namespace Tractography
{

Expand Down
3 changes: 2 additions & 1 deletion src/fixel/filter/smooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef __fixel_filter_smooth_h__
#define __fixel_filter_smooth_h__

#include "fixel/fixel.h"
#include "fixel/matrix.h"
#include "fixel/filter/base.h"

Expand Down Expand Up @@ -51,7 +52,7 @@ namespace MR
*/

class Smooth : public Base
{
{

public:
Smooth (Image<index_type> index_image,
Expand Down
Loading

0 comments on commit 86eb1ea

Please sign in to comment.