# A Tutorial Introduction to the MNI-ray\_trace Software

**URL:** <https://forum.bic.mni.mcgill.ca/t/a-tutorial-introduction-to-the-mni-ray-trace-software/1070>\
**Category:** BIC-wiki\
**Created:** [March 15, 2018, 6:37pm UTC](https://forum.bic.mni.mcgill.ca/t/a-tutorial-introduction-to-the-mni-ray-trace-software/1070 "2018-03-15T18:37:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.bic.mni.mcgill.ca/user_avatar/forum.bic.mni.mcgill.ca/system/32/277_2.png) [@system](https://forum.bic.mni.mcgill.ca/u/system)\
**Post date:** [March 15, 2018, 6:37pm UTC](https://forum.bic.mni.mcgill.ca/t/a-tutorial-introduction-to-the-mni-ray-trace-software/1070/1 "2018-03-15T18:37:08Z")

</div>

# A Tutorial Introduction to the MNI-ray\_trace Software

David MacDonald (david@bic.mni.mcgill.ca)

- [Introduction](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Introduction)
- [How to Run MNI-ray\_trace](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Running)
- [Data for this Tutorial](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Data)
- [Example 1: Making a Slice Image](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex1)
- [Example 2: Setting the Image Size](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex2)
- [Example 3: Setting the Background](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex3)
- [Example 4: Setting the Over/Under](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex4)
- [Example 5: Cropping the Image](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex5)
- [Example 6: Displaying Tags on a Slice](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex6)
- [Example 7: Using Lighting](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex7)
- [Example 8: Superimposing PET on MRI](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex8)
- [Example 9: Superimposing PET on MRI with Transparency](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex9)
- [Example 10: Displaying Surfaces](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex10)
- [Example 11: Choosing View Orientation](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex11)
- [Example 12: Colouring Surfaces with Volumes](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex12)
- [Example 13: Defining Lights](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex13)
- [Example 14: Cross sections of Surfaces Superimposed on a Slice](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex14)
- [Example 15: Supersampling](http://www.bic.mni.mcgill.ca/~david/Ray_trace/ray_trace_tutorial.html#Ex15)

## Introduction

The MNI-ray\_trace is a set of software used to render high-quality images for publication and animation, and represents an alternative to using MNI-Display and MNI-register to create neuroanatomical images. The reasons to use MNI-ray\_trace over the other two programs include:

- Reproducibility : using script files allows images to be easily regenerated or modified, and
- Image Quality : the use of partial transparency, super-sampling, and other features create better images.

What follows is a tutorial consisting of examples, starting with the simpler cases and progressing to more complicated examples.

## How to Run MNI-ray\_trace

All the executables listed in this tutorial reside in the directory ~david/public\_bin. The list of programs used include:

- ~david/public\_bin/ray\_trace : the ray trace program
- ~david/public\_bin/make\_slice : creates a slice object

## Data for this Tutorial

The following data are used for the examples in this tutorial.

- a T1-weighted Minc volume : /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc
- a cortical surface : /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz
- a set of tags : tags.tag which contains the following:
  - MNI Tag Point File  
Volumes = 1;

Points =  
-30 -52 64 “Marker”  
-30 15 58 “Marker”  
-30 -14 28 “Marker”;

## Example 1: Making a Slice Image

First a rectangle is created using the make\_slice program, then the ray tracer is invoked with the rectangle following the Minc file colour coding arguments on the command line. Note that the -nolight argument must precede the slice.obj argument in order to have the desired effect of not using lighting equations to render the colours of the slice. Instead of **-hot** , one can use **-gray** , **-spectral** , **-red** , **-green** , **-blue** , **-colour** , or **-usercc**.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex1.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj

## Example 2: Setting the Image Size

Use the **-size x\_size y\_size** option.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex2.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200

## Example 3: Setting the Background Colour

Use the **-bg colour** option.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex3.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white

## Example 4: Setting the Over/Under Colours

Use the **-over colour\_name** and **-under colour\_name** option. These two argument only affect subsequent colour coding arguments on the command line, in this case, the -hot … arguments.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex4.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -under blue -over green -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white

## Example 5: Cropping the Image

Since the default view provides a border around the object, the **-crop** option is one way to remove the wasted space, by reducing the width of background to 1 pixel. Another way is to explicitly define the view yourself, described later in the tutorial.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex5.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -under blue -over green -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white -crop

## Example 6: Displaying Tags on a Slice

A tag file contains points in 3 dimensional space and usually has the suffix .tag. The ray\_tracer displays them as spheres. Be careful to put the tag filename on the command line _before_ the -hot option, in order for the tags not to be colour coded by the volume. The colour and size of the tags (if the size is not in the .tag file) are specified by the -marker\_size size and -marker\_colour colour arguments.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex6.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -marker\_size 2 -marker\_colour green tags.tag -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white -crop

## Example 7: Using Lighting

The -light and -nolight turn on and off lighting effects for subsequent objects on the command line. In this example, the tag points have been made larger, and use lighting, but the slice does not use lighting effects.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex7.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex1.rgb -nolight -marker\_size 2 -marker\_colour green tags.tag -hot 80000 500000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white -crop

## Example 8: Superimposing PET on MRI

This example shows all regions of PET activation above a certain value on top of an MR image. This is accomplished by putting the -gray MR colour coding on the command line, followed by -under transparent, and finally the -spectral colouring of the PET volume.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex8.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex8.rgb -nolight -gray 80000 450000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 -under transparent -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 1 slice.obj -size 200 200 -bg white -crop

## Example 9: Superimposing PET on MRI with Transparency

The last argument of the colouring coding argument indicates the opacity of the volume colours. By changing the argument: -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 1 to -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 .4 , the PET image shows a little of the underlying MR image. ![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex9.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/ray\_trace -output ex8.rgb -nolight -gray 80000 450000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 -under transparent -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 .4 slice.obj -size 200 200 -bg white -crop

## Example 10: Displaying Surfaces

Surfaces are collections of triangles constituting a 3D surface, usually in a file with a suffix of .obj. They are rendered simply by placing the filename on the command line. The default view is a 3/4 view from the posterior top left ![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex10.gif)

david/public\_bin/ray\_trace -output ex11.rgb /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz -size 200 200 -crop

## Example 11: Choosing View Orientation

Besides specifying a view orientation numerically (described later), there are 6 canonical views which may be chosen: **-top** , **-bottom** , **-left** , **-right** , **-back** , and **-front**.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex11.gif)

david/public\_bin/ray\_trace -output ex11.rgb /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz -size 200 200 -crop -left

## Example 12: Colouring Surfaces with Volumes

Pet activations and other volume information may be coloured onto a surface in the same way as coloured slices were created in earlier examples.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex12.gif)

~david/public\_bin/ray\_trace -output ex12.rgb -under white -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 1 /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz -size 200 200 -crop -left

## Example 13: Defining Lights

Lights may be defined by the use of **-directional x y z r g b** where x y z defines the direction the light is shining, and r g b define the three colour components of the light, with maximum values of 1. The usual is 1 1 1, which corresponds to white light.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex13.gif)

~david/public\_bin/ray\_trace -output ex12.rgb -under white -spectral 40 60 /avgbrain/brain/images/mni\_demo\_cbf\_normal\_pet\_tal.mnc.gz 0 1 /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz -size 200 200 -crop -left -directional 1 -1 -1 1 1 1 -directional -1 -1 -1 1 1 1

## Example 14: Cross Sections of Surfaces Superimposed on a Slice

Cross sections of surfaces are created by the **plane\_polygon\_intersection** program to create lines, the **set\_object\_colour** program to set the colour, which are then rendered on top of slices.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex14.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/plane\_polygon\_intersect /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz lines.obj x -30

~david/public\_bin/set\_object\_colour lines.obj lines.obj green

~david/public\_bin/ray\_trace -output ex14.rgb -nolight -line\_width 2 lines.obj -hot 80000 450000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white -crop -right

## Example 15: Supersampling

Supersampling is a method of computing the colour several times per pixel and assigning the average value. Essentially it smooths the jagged edges that often appear in images. An argument of **-sup 3** requires 9 times the computation time as the default (which is -sup 1), but the results can sometimes be subtly more pleasing.

![](http://www.bic.mni.mcgill.ca/~david/Ray_trace/Images/ex15.gif)

~david/public\_bin/make\_slice /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc slice.obj x w -30 2 2

~david/public\_bin/plane\_polygon\_intersect /data/icbm/mri1/new\_icbm/subjects/00100/surfaces/mni\_icbm\_00100\_t1\_cortex.obj.gz lines.obj x -30

~david/public\_bin/set\_object\_colour lines.obj lines.obj green

~david/public\_bin/ray\_trace -output ex14.rgb -nolight -line\_width 2 lines.obj -hot 80000 450000 /data/icbm/mri1/new\_icbm/subjects/00100/final/mni\_icbm\_00100\_t1\_final.mnc 0 1 slice.obj -size 200 200 -bg white -crop -right -sup 3
