Skip to Content
MRIcroGL

Scripting

Introduction

New users can run MRIcroGL scripts to explore the software’s features. Advanced users can create their own scripts to avoid tedious manual adjustments. To run or create scripts, simply choose “Scripting” from the “View” menu. A new windows called “Scripting” opens, and you can use the “File” menu to open existing scripts. The currently loaded script is shown in the text editor, and you can choose “Run” from the “Script” menu to execute the script. The manual includes a full reference of the commands available for scripting.

Example script

This script will generate the image with the light source moving to adjust the reflections.

CONST
	ksteps = 220;
	kAziSpeed= 1;
	kElevSpeed= 1;
	kTime = 1;
VAR
	i, az, el: integer;
BEGIN
	RESETDEFAULTS;
	BACKCOLOR(255, 255, 255);
	LOADIMAGE('ch256');
	COLORNAME('surface');
	SHADERADJUST('specular',0.9);
	FOR i := 1 TO ksteps DO BEGIN
		az := (i* kAzispeed) mod 360;
		el :=(i* kElevSpeed) -60;
		SHADERLIGHTAZIMUTHELEVATION(az,el);
		WAIT(ktime);
	END;
END.

Glass brain script

This script demonstrates the ‘overlay_glass’ shader released in 2014 that allows you to independently control the transparency of the background and overlay images. For a tutorial on using this see the demonstration YouTube video

BEGIN	
         LOADIMAGE('mni152_2009bet');
	OVERLAYLOADSMOOTH(true);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, 2.5, 2.5);
	BACKCOLOR(255, 255,255);
	SHADERNAME('overlay_glass');
	SHADERADJUST('edgeThresh', 0.6);
SHADERADJUST('edgeBoundMix', 0.72); END.

Clipping script

This script demonstrates the ‘overlay’ shader released in 2014 that allows you to independently control the transparency of the background and overlay images. This shader allows you to decide whether the clipping is only applied to the background (as shown) or to both the background and overlay images. You can also watch the overlay shader demonstration video on YouTube for hints on how to use this shader.

BEGIN
	RESETDEFAULTS;
	LOADIMAGE('mni152_2009bet');
	BACKCOLOR(128, 169, 255);
	OVERLAYLOADSMOOTH(true);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, -4, -4);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(2, 4, 4);
	CUTOUT(0.0, 0.45, 0.5, 0.75, 1.0, 1.0);
	SHADERNAME('overlay');
END.

Cutout script

This script demonstrates the ability to generate cutouts. Note that I load the statistical map ‘motor’ twice – once to show the regions more active when the left versus right hand was active and once to show the regions that were more active for movements of the right versus left hand (this was a [1 -1] t-test).


BEGIN
	RESETDEFAULTS;
	LOADIMAGE('mni152_2009bet');
	BACKCOLOR(128, 169, 255);
	OVERLAYLOADSMOOTH(true);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, -4, -4);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(2, 4, 4);
	CUTOUT(0.0, 0.45, 0.5, 0.75, 1.0, 1.0);
	SHADERNAME('overlay');
END.

Shell script

This script emphasizes the tissue surfaces (regions with strong gradient magnitude where bright voxels are near darker voxels). This hides regions where the image brightness is not changing, resulting in the cortex and ventricles appearing as thin shells with a hollow interior.

BEGIN
	RESETDEFAULTS;
	LOADIMAGE('mni152_2009bet');
	OVERLAYLOADSMOOTH(true);
	OVERLAYLOAD('motor');
	BACKCOLOR(255, 255, 255);
	OVERLAYMINMAX(1, 2, 2);
	SHADERNAME('overlay_shell');
	SHADERADJUST('colorTemp', 0.0);
	CLIPAZIMUTHELEVATION(0.35, 0, 140);
END. 

3D Mosaic

This is a way to create a 3D mosaic with any shader. I prefer the ‘exploded brain’ method as it is simpler to use interactively and you are not restricted to orthogonal slices. See the exploded brain script for common notes. You can show either the left or right hemisphere by setting AZIMUTHELEVATION(130, 15) or AZIMUTHELEVATION(230, 15).

CONST 
	kSegments = 5;
VAR
	i: integer;
	start, thick: single;
BEGIN
	thick := 1/kSegments;
	RESETDEFAULTS;
	COLORBARVISIBLE(false);
	BACKCOLOR(255, 255, 255);
	LOADIMAGE('mni152_2009bet');
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, -2, -2);
	AZIMUTHELEVATION(130, 15);
	FOR i := 1 TO kSegments DO BEGIN
		start := (i-1)*thick;
		CLIPAZIMUTHELEVATION(start, 0, 180);
		CUTOUT(0.0, 0.0, 0.0, 1.0, 1.0-start-thick, 1.0);
		SAVEBMP('sector'+inttostr(i));
	END;
END.

Exploded Brain

The script generates a series of bitmaps that you can weld together to create a nice image. Unlike the ‘3D Mosaic’, this requires the ‘Overlay’ shader which has a slider named ‘clipThick’ that allows us to adjust the thickness of the clip plane slab. You can also press the ‘overClip’ check-box to select whether the overlay sticks out of the slice (or for a script use ‘SHADERADJUST(‘overClip’, 1)’ and ‘SHADERADJUST(‘overClip’, 0)’). The critical value is ‘kSegments’ – here I generate 12 slabs, you can adjust this for thinner or thicker slices. This script will generate a series of bitmaps that you stack together using your favorite image editor (Photoshop, Acorn, Pixelmator, etc). The trick is to feather the edges between each image (these programs usually include a ‘magic wand’ that allows you to make regions transparent).

CONST 
	kSegments = 12;
VAR
	i: integer;
	start, thick: single;
BEGIN
	thick := 1/kSegments;
	RESETDEFAULTS;
	COLORBARVISIBLE(false);
	BACKCOLOR(255, 255, 255);
	LOADIMAGE('mni152_2009bet');
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, -4, -4);
	SHADERNAME('overlay');
	SHADERADJUST('specular', 0.3);
	SHADERADJUST('overAlpha', 0.6);
	SHADERADJUST('clipThick', thick * 0.75);
	AZIMUTHELEVATION(255, 25);
	FOR i := 1 TO kSegments DO BEGIN
		CLIPAZIMUTHELEVATION(0.001+((i-1)*thick), 0, 180);
		SAVEBMP('sector'+inttostr(i));
	END;
END.

Cluster Thresholds

The statistical maps generated by tools like SPM and FSL can either be unthresholded (green top left image) or thresholded (green bottom left). Since we typically reslice these low resolution images to map onto higher resolution images it is generally a good idea to use the unthresholded image: the thresholded image is artificially surrounded by bogus values so we can not interpolate the boundaries easily. The Overlays/Option/SmoothWhenLoading menu allows you to choose your interpolation method. If this option is unchecked, nearest neighbor interpolation is used and you image will appear jagged (left glass brain) – this is most appropriate if your data was previously thresholded. However, MRIcroGL has commands to remove these small clusters (right image). If the SmoothWhenLoading item is checked, the image will be smoothed with a trilinear filter – this looks very nice (middle glass brain) and is typically appropriate if your raw data was not previously thresholded. However, closer inspection of these reveals that a few tiny clusters appear. If your original analysis used a cluster threshold, you will want to use the overlay windows’ File/AddOverlay(RemoveSmallClusters) option. This will remove any clusters smaller than the specified size. You can also achieve this by calling the ‘overlayloadcluster’ function from a script. You will supply the overlay name, the brightness threshold, and the minimum cluster size (in mm^3), and select whether you also want this thresholded overlay saved to disk (true or false). Note that the cluster size is specified in volume not voxels: if you estimated a random field theory familywise error corrected threshold for clusters of at least 32 voxels with data that was 3mm isotropic (3x3x3 = 27mm^3 per voxel) then you would specify 864mm^3. In the example below we preserve voxels that exceed a brightness of 2.0, are part of clusters of at least 1cc (1000mm^3) and choose not to save the resliced image to disk.

BEGIN
	RESETDEFAULTS;
	LOADIMAGE('mni152_2009bet');
	OVERLAYLOADCLUSTER('motor', 2, 1000, false);
	SHADERNAME('overlay_glass');
END.

Ambient Occlusion

Due to ambient occlusion scattered light (ambient illumination) has less effect on surfaces hidden inside crevices than exterior surfaces. Therefore, making sulci appear a bit darker than gyri tends to make the image look more realistic. MRIcroGL’s “occlusion” shader provides a slider that allows you to adjust the amount of ambient occlusion. The two images below show the effect of amping up the ambient occlusion effect.

BEGIN
	RESETDEFAULTS;
	LOADIMAGE('mni152_2009bet');
	OVERLAYLOADSMOOTH(true);
	OVERLAYLOAD('motor');
	OVERLAYMINMAX(1, 2.6, 2.6);
	BACKCOLOR(255, 255,255);
	SHADERNAME('occlusion');
	AZIMUTHELEVATION(300, 20);
END.
 
 
© 2012 University of South Carolina Board of TrusteesPrivacy Policy