Color transparency customization in viewer

Hi All,

Hoping for some aesthetic assistance with a brain image. I am trying to create an image with a semi-transparent background for part of the overlay image and non-transparent for the rest of the overlay. Is there a way to do this with the AFNI viewer? (I know you can control the transparency of the overlay as a whole, but I just want to do part of it). I am attaching an example image, where I would like the grey color to be semi-transparent.

Thanks for any advice.


Hi, Becky-

There isn’t a way to do this, as far as I know (e.g., like a voxelwise alpha value for the overlay).

Can I ask what you are trying to show differentially with this overlay? Perhaps there’s another way to represent what you want.


Hi, Thanks for getting back to me so quickly. I have a network mask (in grey) and the colored areas show voxels that are significant for a contrast within the network. We want to show which areas of the brain are included in the network referenced against the results of the statistical test. My colleague tells me there may be a way to do this in photoshop so I might migrate the images over there if it doesn’t work out to do them directly in AFNI.

Actually, we do have something that might suit what you want…

Have you tried the “alpha” and “boxed” features in the GUI? This refers to the ‘A’ and ‘B’ button at the top of the GUI near the “Thr” button. It’s described a bit in this youtube video (give it a minute or two of preamble from this time point… sorry, seemed to make more sense that way…):

You can set the threshold value so that above it, results are opaque and boxed, and those outside of it are increasingly translucent. It is also described here:
… with the drivable form of the AFNI GUI to make images.

We use this a lot to present statistical results. This seems exactly what you want, and the purpose it is there for.


Ah, yes! That is exactly what I want. I’ve been using AFNI for years and never noticed those A/B boxes before :slight_smile: Thanks so much!

I think you want two things really -

  1. Show a localization cluster in gray and transparent
  2. Show a statistic in color, differently transparent

The AFNI GUI is mostly limited to a single overlay dataset, but here are some workarounds.

  1. Below threshold reduced opacity. At the top of the overlay bar, you can choose to show sub-threshold data with reduced opacity relative to the threshold and above data. That will allow showing the localization cluster as more transparent if you make a dataset that is a hybrid of your datasets.

set beta = func_slim+orig’[1]’
set tstat = func_slim+orig’[2]’
set localclust = quickmask+orig
set tstat_thr = 3.5
set newlocal_val = 0.5

3dcalc -a “$beta” -b “$tstat” -c “$localclust”
-expr “a*step(b-${tstat_thr}) +
-prefix beta_n_clust.nii.gz -overwrite

In the AFNI GUI set the threshold just above the newlocal_val used above, and click on the button labeled ‘A’ above the Overlay color bar. You can also click ‘B’ for the box edges. You can experiment with the different color scales too by right-clicking on the color bar and selecting a new color scale. Also explore the paned color bars by clicking on the double asterisks below the color bar and try 20 color panes. Set the pane that corresponds to the values around 0.5 here to set a different color. This combination method is limited in that beta values at or below newlocal_val can’t be shown. To get around that, you could add or multiply all the values to make the supra-threshold voxels higher, so a beta of 3 might show up as 4 just by adding 1.

  1. Make the cluster an atlas. One of the few exceptions to not allowing for multiple overlays is that an atlas can be shown as another layer. You just have to convert your cluster ROI to an atlas and set an environment variable to tell AFNI to use that atlas. The datasets need to be marked as all being in a standard space too.

make a simple label table to use for the atlas (here for two regions named act and deact where act=1, deact=2)

cat act_deact.txt
1 act
2 deact

turn the mask dataset into an atlas

@Atlasize -dset act_deact+tlrc. -atlas_name act_deact -atlas_description “activation or deactivation”
-atlas_type S -space MNI -lab_file act_deact.txt 1 0

the act_deact dataset is a new “Session atlas”

whereami -show_atlases

++ act_deact TT_N27 act_deact+tlrc. activation or deactivation

start afni GUI to show new Atlas colors

afni -DAFNI_ATLAS_COLORS=act_deact

In the AFNI GUI, right-click on any image viewer and select “Atlas colors”. The region will

  1. Simulate opacity in anatomical underlay (grayscale usually)
    set anat = anat+orig
    set graylev = 3dBrickStat -percentile 75 75 0 -non-zero $anat
    set opacity = 0.4444
    3dresample -prefix lc_anat.nii.gz -master “$anat” -input $localclust -overwrite
    3dcalc -a “$anat” -b lc_anat.nii.gz -expr “a*(1-$opacity)+step(b)$opacity${graylev[2]}”
    -prefix lc_anat.gray.nii.gz -overwrite

Now just make the anatomical-cluster hybrid dataset the underlay. The cluster mask will show up as a “translucent” region, and the overlay controls are the usual.

Great, glad that is useful!

I will put a plug in here for signing up to the AFNI Digest, to hear about updates (we batch them, and the rate of emailing is typically far below one per week; more about one per month):,154890,154890


Thank you for the detailed instructions!