@chauffeur_afni options

Hi there!

Two questions about chauffeur_afni:

  1. Is there a way to generate .nii.gz images using @chauffeur_afni? I'm generating some transparent brain maps using the highlight-but-don't hide approach (thresholded at p < .001 the code below, sub-threshold voxels show up as translucent voxels - see attached figure and code below) and it'll be nice if I can get the same images in two formats - (1) the usual output of chauffeur_afni (axial/saggital/coronal slices' images) and (2) as an .nii.gz image. With a .nii.gz file, I am hoping to also plot this mao on a brain surface using nilearn's surface plot functions.

  2. Is there a way to add the colorbar limits (max/min values) to the colorbar.png file that gets saved using -pbar_saveim? Also, if I want the extremes of the colorbars to be -x and x, is this the way to define this: -func_range x ?

AFNI version

: 23.0.04

@chauffeur_afni                                                 \
    -ulay               ${ulay}                                 \
    -olay               ${olay}                                 \
    -cbar               Reds_and_Blues_Inv                      \
    -set_subbricks      ${ulay_subbrik} ${olay_subbrik} ${thr_subbrik} \
    -thr_olay_p2stat    0.001                                   \
    -thr_olay_pside     bisided                                 \
    -olay_alpha         Yes                                     \
    -olay_boxed         Yes                                     \
    -opacity            7                                       \
    -prefix             ${outfile}                              \
    -save_ftype         "PNG"                                   \
    -pbar_saveim        ${outdir}/cbar_unc_${dv}.png            \
    -delta_slices       8 10 8                                  \
    -montx              5                                       \
    -monty              4                                       \
    -set_xhairs         OFF                                     \
    -zerocolor          white                                   \
    -label_color        black                                   \
    -label_mode         1                                       \
    -label_size         4

Thanks in advance,

Hi, Rekha-

Starting with #2:

  • there is a text file output when you use -pbar_saveim .., and it contains a record of the colormap range information. If the colorbar is called A.png, then the text file is called A.txt. Within that text file, the fields keys in the first column are called pbar_bot and pbar_top.
  • to set the values of the colormap range, you can use any of the following options:
    along with possibly -pbar_posonly.
  • if you want the range to be from -R to R, then you can use -func_range R, and do not include -pbar_posonly.

Re. #1:
I am a little unsure what this means. The utilized NIFTI information is the ulay, olay and thr volumes. To make the image, these are represented in useful ways (e.g., choosing colorbar and range for mapping overlay numbers to color; choosing threshold values along with tranparency---and great to see that being used!---etc.), but the volumes are not changed. So, the output is really text or images using those chosen values when viewing the data, but not new NIFTI datasets themselves.

But there is a relatively new option to output a driving tcsh script to make AFNI open up the input dsets and visualize them in the way you have specified in the command:

-cmd2script FILE.tcsh

After adding that option, you can run tcsh FILE.tcsh to be able to run the AFNI GUI automatically to visualize your imaged data, but in the active GUI session. Does that provide what you would like here?


1 Like

Hi pt,

Thanks very much, that was quick!

Reg 2, thanks for clarifying these points. I was actually wondering if there was a way to add the pbar_bot and pbar_top onto the .png colorbar file (on that note, is there a way to add any text to the colorbar file?). For context, I am testing about 5 models and comparing results across about 5-10 thresholded beta maps - so it'll be nice if there's a way to insert text programmatically into the images.

Reg 1, apologies for the lack of clarity. Overall, my goal is to save the overlay in these PNG (i.e., showing the supra-threshold voxels and the sub-threshold voxels weighted by their significance/distance from the threshold) as an .nii.gz file, so that this can be used like any other beta map - e.g. to overlay on surface plots (nilearn has options that convert volumetric maps to surface maps), to overlay on anatomical and functional brain atlases etc. Hope this adds some context to it.

Thanks again!

Hi, Rekha-

Re. #2: There isn't a way within AFNI to plop text into the image files generically (just some specific text generation GUI image views, like slice number). I agree that would be useful in many cases, but at present that would have to done in a separate software. (And if you find an convenient/nice one for that, I'd appreciate knowing.)

Re. #1: I see, I understand now. There is an RGB dataset type within NIFTI (and AFNI uses it, for example to make DEC maps for diffusion directionality viewing) but those don't have alpha fading as part of it. AFNI can actually send data to SUMA to project volumetric data onto surfaces---it sends RGB information, and we are planning to have it deal with the alpha channel in the near future, too.

In terms of having other software use the information, it might be possible to view that have nilearn show the data in a similar way. I am not familiar with that tool, but if you can do matplotlib-like things there, you can make an alpha value per voxel according to, perhaps:

def calc_alpha(VAL, THR):
    """VAL is the voxel value, and THR is the threshold magnitude.
Return an alpha value in range [0, 1].
    if abs(VAL) > THR :
        return 1.0
    elif abs(VAL) > 0 :
        return ABS(VAL)/THR
        return 0.0

1 Like

Thank you! Yeah this is exactly the info I needed. Reg. colorbar text - don't have a good solution either besides Illustrator, but will update if I do!


There are some tricks ...
The slice image viewer allows for adding text to the view.

  1. Right-click on grayscale bar on a plane you would like the text like the axial view.
  2. Choose "Label append string" like " Test Model 1" (I put a leading space there).
  3. Right-click on grayscale bar and choose "Label" to be on at a position like "LowerMid". If you like, you can change the size of the font with the Size button.
  4. Choose Disp menu in lower left of slice viewer and turn off "Save One".
  5. Right-click on "Sav1.jpg", save the dataset as png format and select "Set"
  6. Turn off crosshairs with the upper left menu of the afni GUI.
  7. Save the slice images into the current directory by clicking on the Sav1.png button. A set of images is saved; this can just be underlay or both the combination of underlay and overlay datasets. These are saved at the resolution of the underlay dataset.
  8. In the terminal, form a new dataset with the png image files.
3dcopy anat_final.FT.NL+tlrc. testanat_LAI 
3drefit -orient LAI testanat_LAI+tlrc
to3d -geomparent testanat_LAI+tlrc. -prefix model1_with_textLAI model1_with_text.0*.png
3drefit -view tlrc model1_with_textLAI+tlrc.HEAD
@Align_Centers -base anat_final.FT.NL+tlrc -grid -no_cp -dset model1_with_textLAI+tlrc.

The new dataset is in RGB format which should display properly in afni, but not in the suma GUI, and most processing doesn't work with RGB format. Convert that to an integer format with :

3dcalc -a model1_with_textLAI+tlrc. -expr a -prefix model1_with_textLAI_short -datum short

The 16-bit integer volume can be rendered in 3D with

suma -vol model1_with_textLAI+tlrc.

I think this could all be scripted and drive afni to make this easier. You will have to be careful about dataset orientation with these kinds of interactions.

The text annotation of images can also be done with other software packages for general 2D images like ImageMagick: