# Adding command line option to mrview to set tractography colors

**URL:** <https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453>\
**Category:** Development\
**Tags:** mrview, tractography\
**Created:** [April 17, 2019, 12:22pm UTC](https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453 "2019-04-17T12:22:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blezek](https://community.mrtrix.org/user_avatar/community.mrtrix.org/blezek/32/453_2.png) [@blezek](https://community.mrtrix.org/u/blezek)\
**Post date:** [April 17, 2019, 12:22pm UTC](https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453/1 "2019-04-17T12:22:06Z")

</div>

For some of the work we are doing, different streamlines are generated that run quite close to each other. I’d like to be able to show streamlines overlaid on b0 (and or a registered anatomic image). In the GUI, it’s easy to randomize the colors of each `.tck` file by selecting them all and choosing ‘Random’ from the color combo box.

However, it would be great to be able to generate screenshots programmatically with colors set from the command line. Something like:

```auto
mrview b0.nii.gz -tractography.load tract.tck -tractography.color 1,0,0 -capture.prefix ...

```

First off: is this possible? Secondly, any pointers on how to add this feature?

Thanks,  
-dan

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [April 21, 2019, 3:00am UTC](https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453/2 "2019-04-21T03:00:44Z")

</div>

Hi Daniel,

This is [one](https://github.com/MRtrix3/mrtrix3/issues/1132#issuecomment-385306426) of many items that have been identified within `mrview` as being accessible from the GUI but not the command-line. In part we haven’t put the effort into covering off those functionalities not yet accessible from the command-line because we’d rather implement a [more general solution](https://github.com/MRtrix3/mrtrix3/issues/1438) that would reduce both the management and proclivity for errors in such. This would however most logically be implemented alongside a [rather large `mrview` code overhaul](https://github.com/MRtrix3/mrtrix3/issues/1437), which is no trivial task.

If you’re interested in just implementing one specific functionality in order to serve a specific purpose, it’s only a matter of identifying how similar functionalities are currently implemented, and then modifying a duplicate of such for your requirement. In your case, the relevant functions are:  
[`GUI::MRView::Tool::Tractography::add_commandline_options()`](https://github.com/MRtrix3/mrtrix3/blob/3.0_RC3/src/gui/mrview/tool/tractography/tractography.cpp#L825-L857)  
[`GUI::MRView::Tool::Tractography::process_commandline_option()`](https://github.com/MRtrix3/mrtrix3/blob/3.0_RC3/src/gui/mrview/tool/tractography/tractography.cpp#L876-L1001)

Cheers  
Rob

---

<div class="post-metadata">

**Author:** ![valery](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@valery](https://community.mrtrix.org/u/valery)\
**Post date:** [February 25, 2021, 5:39pm UTC](https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453/4 "2021-02-25T17:39:28Z")

</div>

Hi

Following instructions from another post, I tried to implement a solution using the following changes in src/gui/mrview/tool/tractography/tractogram.cpp :

```auto
  + Option ("tractography.colour", "Specify a manual colour for the tractogram, as three comma-separated values").allow_multiple()
            + Argument ("R,G,B").type_sequence_float()           

```

and

```auto
if (opt.opt->is ("tractography.colour")) {
            try {
            
              auto values = parse_floats (opt[0]);
              if (values.size() != 3)
                throw Exception ("must provide exactly three comma-separated values to the -overlay.colour option");
              const float max_value = std::max ({ values[0], values[1], values[2] });
              if (std::min ({ values[0], values[1], values[2] }) < 0.0 || max_value > 255)
                throw Exception ("values provided to -tractogram.colour must be either between 0.0 and 1.0, or between 0 and 255");
              const float multiplier = max_value <= 1.0 ? 255.0 : 1.0;
              QColor colour (int(values[0] * multiplier), int(values[1]*multiplier), int(values[2]*multiplier));               
                           
              QModelIndexList indices = tractogram_list_view->selectionModel()->selectedIndexes(); 
              
              if (indices.size() != 1)
                  throw Exception ("-tractography.colour option requires one tractogram to be selected");
              // get pointer to tractogram:
              Tractogram* tractogram = tractogram_list_model->get_tractogram (indices[0]);
                
              //input need to be a float *  
              float colour_input[3];
                
               colour_input[0]=values[0]/255;
               colour_input[1]=values[1]/255;
               colour_input[2]=values[2]/255;
                
               // set the color
               tractogram->set_color_type (TrackColourType::Manual);
               tractogram->set_colour(colour_input);
                
               // update_color_type_gui
               colour_combobox->setCurrentIndex (3);                
               colour_button->setEnabled (true);
               colour_button->setColor (QColor (colour_input[0]*255.0f, colour_input[1]*255.0f, colour_input[2]*255.0f));
              
            
            }
            catch (Exception& e) { e.display(); }
            return true;
          }

```

Unfortunately , if I cannot specified different colors if I’m loading more than one tractogram.

For some reasons:

```auto
QModelIndexList indices = tractogram_list_view->selectionModel()->selectedIndexes(); 

```

is always set to 1

Do you know what should be changed ?

Thansk in advance  
Best,  
Valéry

---

<div class="post-metadata">

**Author:** ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)\
**Post date:** [February 25, 2021, 5:46pm UTC](https://community.mrtrix.org/t/adding-command-line-option-to-mrview-to-set-tractography-colors/2453/5 "2021-02-25T17:46:14Z")

</div>

Hi Valéry,

I recommend you set up a [fork of MRtrix](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo), push your code to your fork, and then either [create a pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) or give us access to your fork so we can try it out. It would make it much easier for us to identify what the issue is if we can actually inspect it and try it out on our own systems… Would that be possible?

If you create a pull request, we can also carry on the discussion on GitHub, which is probably a better place to discuss coding-related issues.

All the best,  
Donald.
