19 - Atlases and ROIs: Part 2 of 2
Date Posted:
January 28, 2019
Date Recorded:
May 30, 2018
Speaker(s):
Daniel Glen, NIMH
All Captioned Videos AFNI Training Bootcamp
Description:
Daniel Glen, NIMH
Related documents:
For more information and course materials, please visit the workshop website: http://cbmm.mit.edu.ezproxyberklee.flo.org/afni
We recommend viewing the videos at 1920 x 1080 (Full HD) resolution for the best experience. A lot of code and type is displayed that may be hard to read otherwise.
DANIEL GLEN: Now we're going to look at the draw data set plug-in inside AFNI. And I'm going to start it in the AFNI data six AFNI directory. So in AFNI data six AFNI directory, just type AFNI. And I'm going to switch to [INAUDIBLE] view just to show you some other features. You can do this in the native space, too.
And there's a couple ways to get to the draw data set plug-in. And one is to just right click on any image viewer and select draw ROI plug-in. That's one way. The other way is to go to define data mode and select plug-ins. And there, you have draw data set. So that's the second way. I'll do that.
With the draw data set menu open, you kind of go through this sequentially from the top. It says no data set. Look at these options. So here, we're going to make a copy of a data set. And we're going to use a zeroed out copy. And we're going to show it in the overlay.
And rather than as is, let's save it in byte format. Next. Then I clicked on that. So that showed that clearly. Choose data set for copying. Let's choose our data set. And we'll choose anat plus [INAUDIBLE] as our data set. And what this does is, it makes a blank copy of that data set.
What's a blank copy? That's just a copy that's just zero everywhere. So we're just getting the grid of our data set. And we're going to draw over that same data set. And we're going to draw in the overlay. Could draw on the underlay. But almost no one ever does that. So let's just draw on the overlay.
And we can draw in lots of different ways. And we have to first choose a drawing color. This is the index that we're going to put into our data set. So we're going to pick it-- an intensity that we're going to draw with. And we're going to put a value of 1 here. And we can call it something. So let's say RY1.
You can call it whatever you like. And we're going to choose a drawing color. And here the drawing color is, by default, set to yellow. You could choose other colors, if you like-- depends on what you're looking at and how clear that is. And by default, you can look-- it has the mode is filled curve.
You can choose a variety of other methods. We'll talk about just a couple of these. And you can play around with other ones on your own. So let's go over to any window. And if you click, nothing happens. You just can choose the area that you want to start drawing. And if you use the middle button, you can start to draw with your middle button.
And there, I've drawn something. And if I don't-- so it's a little bit difficult to see. Maybe I'll change my-- I didn't like what I did. So I will undo it down here in the lower left. So select undo. You can also redo. And I'll draw with a different color.
This is just the drawing color. It's just temporary color, just so I can see the pen a little bit better. So I can draw. Now I am doing this very quickly and roughly. If you're drawing a lot of regions, I have some recommendations. So one thing that you may want to do is zoom in more to the area that you're looking at.
Another thing is you may want a stylus for drawing. If you have a touch screen, you can draw with a stylus. This is a handy way to make this a lot faster. An even better touch screen-- there are things like the Wacom Cintiq, which is a nice big large screen that's used by Pixar and Disney for doing their animation. You can draw regions with it, too. And that works great.
And it will cut your time significantly for most people. So a lot of these macaque and marmoset atlases that were drawn [INAUDIBLE] often with AFNI. It's a fairly meticulous process. And you want to save as much time as you can. So we-- so if you're using one of these things like a stylus or the Wacom Cintiq, or you just want to use the left button-- you can select the pen button over here.
And when you select the pen button, the cursor changes to something that looks a little like a pen. And you can draw with a pen using the left button. I prefer this, because I'm more used to dragging with left-- the left mouse button anyway. But you have your choice.
So I've drawn one region. It's-- they are kind of in two separate pieces here. I can go to another region and draw my second ROI. And here, I'll-- and these are drawn one slice at a time. So if I-- so here, let me choose a different drawing method instead of these kind of polygon that I've been drawing with-- this filled curve-- I'm going to draw with a 3D sphere.
So the 3D sphere is something like a 3D paintbrush. I'm drawing in three dimensions with a ball. And this ball has a value of 2 everywhere I click it. So let's see. And there's a 4 millimeter radius. Let's see what that looks like. And I've got pen set, so I can use the left mouse button.
So that's what happens when you use the ball. But you'll see, if I go through the slices, I'm drawing on the coronal slice. You can see, as it goes away, the ball gets smaller. And we can also zoom in and see what that looks like across the other slices. So you can see it's-- we've done something with those balls in a row.
So you have a different kind of effect. And so drawing with 3D spheres is a fast way to cover a lot of distance if-- and so it can be really useful for making a big, rough mask. You can go back and fine tune it by erasing parts of it. So how would you erase an ROI? Does anyone have any idea? Yes.
AUDIENCE: Set it to zero.
DANIEL GLEN: Set it to zero. That's right. So we can start drawing with zero. So if I set this to zero, then I can go back and maybe I want to use a smaller ball. Maybe, let's say, I enter in one. Having a problem clicking that. One. Now I can go back and you see I'm drawing now with the zero and zeroing out my data. So that's one way to erase.
You can also use the points mode. So this will give you one voxel at a time. And erase with that. Pen and pan are not compatible. So if you want a pan, you have to turn off pen. I'm not sure why that is, but that's what we've got. And it's useful to zoom in pan to the area that-- where you want to draw, so it'll be easier to see everything and to work with a large area, too.
If you wanted to only draw every few slices, you can use this linear fill in. If you want to use atlas regions, you can do that here. So you can choose your atlas-- choose one that's in the space of your data set. I'm going to choose one of the Desai atlases here. And there's a long list. For anywhere there's a long list-- almost everywhere there's a long list in AFNI-- you can right click just to the left of it and see the list as a window that you can scroll through.
Let's say-- I'll do that. And then I can load that. I can either overwrite or fill in what hasn't been drawn in before. So here, let's see where that-- I forgot. This has to be done in the color here.
Of course, I don't know exactly where that is. Yeah, there. Well, it's somewhere in there. Have to find the part of the Insula where I put that. There it is. So you can bring in atlas regions into your data set that way. And once you've got your set of regions, an atlas can have hundreds of regions. And this can take many, many months of work.
And as you go, you should save it. And the save as button is down here. So save as. These are-- call it what you like. And then save that. And then you can convert that into an-- into an atlas, also. So that's how you create regions. Any questions about how to use draw data set?
Now, you don't have to create regions with AFNI, also. You can create regions with any other package that creates nifty data sets. Just be careful that when it comes in, it's got the right header information-- the left and right, particularly-- and that everything is in just the right place. The coordinates haven't been shifted over anything. So when you're finished, you just click done.
And you also notice that over here-- let me turn that off there-- as you click, the regions show up labeled in the overlay panel. And here, we're looking at a color scale that's good for looking at regions. It has separate, distinct colors for every region. And you can get to those ROI type of color scales by right clicking on the color bar and selecting choose color scale.
When you save this kind of data set, it's saved with an attribute that says show it with an integral color map-- just integers-- so a color map like this. So here's the-- it's shown ROII32, but we have ones that go up to 256. And there are certainly a lot of other color scales that you can look at.
If you reload-- if you want to do-- continue this on, then you wouldn't zero it out. You could just select the data set and keep the data as is. You wouldn't select that zero. You would have to give it a new name.
You would keep the data as is and then continue on the process everyday, updating it often. You can draw any shape you like, hearts included. The renderer that's built in-- the render plugin that's built into AFNI-- will show the overlay and will show it as you're drawing.
So if you want to see it as you're drawing, you can do that. I'm not sure who did this, but somebody drew some name there. So some issues that you have to think about when you're dealing with ROIs. So we drew on a high resolution data set-- our anatomical data set. But we're mostly going to apply it to our much lower resolution or FMRI data-- typically much lower.
That's-- so instead of one millimeter resolution, we may have two millimeter or three millimeter resolution. And how do we go between those two kinds of resolutions? So here is a diagram-- high res to low res here, when we fill up a low res voxel with a high res voxel, it's pretty clear what to do with that. We just keep the same value.
But what if it's only halfway filled? Or what if it's only a quarter of the way filled? Then what do we do? So we've got some programs for dealing with that. So one program is called 3dfractionize. So here, you give it what you're going to. So we're going to low res from our high resolution ROI that we've drawn very meticulously in draw data set.
And we're going to destroy all the details of it by moving it to a low resolution. And we're going to say keep it. Keep the value there if it's half filled. So it's at 0.5-- clip value of 0.5. Keep the value itself. Don't give us-- the preserve says, don't give us a resampled, interpolated value.
Give us the value itself. So if we've drawn with a value of 4, and it's 0.8 filled, we don't want a value of 3.2. We want a value of 4. That's what that does. And if you've got multiple regions, it will figure out which one is more or less. And you can have a voting, which one wins the campaign in that voxel.
So here's a little diagram. This voxel is 80% filled. That's more than the 0.5 clipping value. We want to keep that. This one's only 30% filled. We want to lose it. This happens often when you're dealing with high resolution structures-- structures that are very fine and maybe they're diagonal. And so their voxels don't quite make it to fill up a voxel.
Maybe they'll only be 30% filled. In that case, you can lose a lot of the shape-- so something like the hippocampus or sub sub regions of the hippocampus. These won't fill voxels necessarily. And so you may want to keep those. And so you can use 3dfractionize to do that.
In general, most people don't really worry about this. And so for a lot of the kind of work we do 3dresample is good enough. This is effectively a 50% cut off. And with ROIs, you would use this resampling mode of nearest neighbor. And so that just looks to see what voxel would show up at the center of that new grid. And is it for that ROI?
And so that's generally what we do with 3dresample. 3dfractionize is much, much slower. And you still have to decide what that cutoff clip value is. So here's an example. We're going from this region that we drew here. And then we resample it down to this resolution here.
And so, 3dresample is often used for this. So you give it the master data set. You give it the name of the output, the prefix. You give it the input, which here is called dash inset, and the resampling mode nearest neighbor. Other things you can do with ROIs-- you can get the average at every time point with 3dmaskave.
So you've drawn this region-- or you've gotten it out of a cluster-- you can say, what is the average at each time point in this data set? So this is the volume registered EPI data set. And redirect all the output to this one d text file is just numbers. So every row is just the mean across the ROI. And this is what it looks like.
The EPI average data set is just this column of numbers-- 1,076 down to 1,084, the last one. And then we can plot it with one deep plot. This is a very commonly used tool in AFNI, using-- to be able to get the averages across the regions. Another thing that sometimes people want is 3dmaskdump. They want to find out all the voxel values in a data set within an ROI.
And so, you can do that with this 3dmaskdump. You provide it the mask, what region to apply it to-- so this is func slim plus a ridge. The second sub brick-- sub brick 2. And so that's the reliable visual tstat. And so this will all show up in one text file-- all the values within that. And people will often ask for this-- maybe to bring it into Matlab or into some other kind of analysis software.
Having said that, we do have an AFNI Matlab toolkit that makes bringing in data sets a little bit easier. You can extract them. You can bring in the whole data set and extract what you want inside Matlab, too. A similar program to 3dmaskave-- it's 3droistats. So 3dmaskave gives us one region-- one mask. But if you use 3droistats, then you can-- it will separately handle each of the ROIs.
So if you have an ROI with a value of one, a value of two, and a value of three, it will give you those-- means across each of those separately. And this is what the output looks like. This is for-- just applied to one single sub brick, but you could also apply it to a whole time series and it would give you three columns for each of the means.
Another way to get ROIs is from clusters. We showed you the clusterize plug-in. I think we'll show it to you a couple more times. That's one way to get-- you can take your activation maps, threshold them, cluster them if you like, and those will be new ROI data sets.
So here's an example. You've seen this. You can get averages across time inside the plug-in. And there's a brand new program. Paul [INAUDIBLE] just wrote this. It's just been released into the AFNI source code. 3dclusterize-- this replaces 3dclust and 3dmerge for clusters. The syntax is easier.
So it's easier to work with. And here's an example of what you would do with it. So with 3dclusterize you could tell it how many voxels have to be in your cluster. Here I'll say 200 voxels. This is just an example. And I want a bi-sided result. I don't want to mix my positive and negatives.
I want positive clusters or negative clusters, but not mixes of positive and negative clusters. And I want those to be between minus two points-- well, outside of-- with a threshold of minus 2.0 and positive 2.0. So the absolute value is going to be more than 2.0. And I'm going to get the threshold from sub brick two, and the data from sub brick one.
So remember, this is my-- in this case, it's back to the func slim data set. This is the tstat for the reliable visual stimulus. And this is the beta coefficient-- the percent signal change for that stimulus. And I want to get that-- the clusters defined by seeing neighbors-- the default.
So nearest neighbor mode with just the voxels that are facing head on. And the input is my func slim data set. And the output is a map of your clusters. Call that my clusters. And this is what it looks like on the output. You get a data set like this, with this map of the clusters. And you get a report.
This is similar to the ones that we've seen for the other kinds of things. We have a list of the clusters. And the center of mass-- we have the extents of each of the clusters-- the minimum, the maximum in three directions. We have the mean through that cluster. We have error.
And we have the peak values. So peak value, and then the location of those peak values. So all that comes out. It's pretty simple and fast to run. 3dmerge does something very similar, but the syntax is a lot harder. One thing to note is that because-- when you use a number of voxel cutoff, you can't just use that arbitrarily across all studies.
There have been studies in the past that say always use some number of voxels-- 27 voxels or three voxels or 81 voxels. That doesn't really make sense. There has to be some kind of volume associated with it. If you have a higher resolution, you need a different number of voxels than a lower resolution. That seems fairly straightforward, but has been missed in the past.
Another way to create our ROIs is just to put some spheres down. So you can put spheres at any location you like. If you know that an activation happened here, here, and here in the past, you can use that as your region of interest. And this is an example of how you would put a sphere into a data set. It's basically 3dundump with the dash srad option.
This tells it to put 7.5 millimeter sphere at that location. We can take it from some localizer study from another data set and put the spheres down here. And so this is what it looks like in AFNI. We can also use whereami. We can use atlas regions. And so, whereami-- if you say whereami dash mask_atlas_engine, and you give it the name of the atlas-- whether you want left or right-- the right side, and the name of the region. And then give it the output name.
And you'll have just that part of the atlas as a separate data set. So here-- this is similar to the other example with 3dclust. This is with the new 3dclusterize. Take the output of the clusterize output, and then tell me where these coordinates are in various atlases. And that does [INAUDIBLE] there. It goes across all the different atlases, and tells you what regions those coordinates are in.
Now, [INAUDIBLE] can also use-- the atlases are available not just with whereami, but in every AFNI command. AFNI data sets can be just the reference to an atlas. So you can say, as here, when it asks for the mask data set, you can give it the name of the atlas and the side and the region.
If you don't care about which side it is, you can just put colon, colon. And that's usually what you do. Most atlases you would just put colon, colon, and the atlas and the region name. And here's an example with 3dcalc. I don't know if we've talked too much about 3dcalc, but if you're an AFNI user, you must learn how to use 3dcalc.
It will be very, very handy for you. So this is an image calculator. And it takes all kinds of-- any data sets as input, and [INAUDIBLE] output. Here is a pretty simple example. Here we're going to give it as input the hippocampus from the macro label atlas. And we're going to apply it to our fstat result.
And here, we give it an expression to evaluate at every voxel. So the expression says, evaluate this a. A is the hippocampus. Is this a not zero? Is it positive, actually? Is it positive? If it's positive, then this step a converts it to a one. And then we multiply it by the b value.
So this is a way to effectively mask the fstat to just the hippocampus. And this 3dcalc takes options from a to z. And there are some things that are useful that are-- we have ijk, xyz, t, l, [INAUDIBLE] maybe, that can be used for other things or they can be used for data sets.
So I just wanted you to be aware that-- of two things here-- that atlases are available everywhere. And there-- and 3dcalc, because this is a super important program. Here's another 3dcalc command. We have the-- we're going to give it as input. The a- data set will be [INAUDIBLE] amygdala. The b data will be the macro label amygdala.
And let's just take one times one of the [INAUDIBLE] demons, and two times the macro label. So if they-- this is a way just to compare it. We're going to create a kind of simple binary format for our atlases. So here, if it exists in the [INAUDIBLE] demon, it gets a value of one. If it also exists in-- well, if it exists in the macro label, we'll add two.
And if it's in both, it'll be 1 plus 2, which is usually 3. So we'll have 3 there. So if they overlap, they'll be shown with a value 3, which is shown in red here. So this also shows us that atlases don't agree with each other. And it shows us how to use 3dcalc and that atlases are available as data set.
Now, someone asked yesterday-- the day before-- I don't remember-- how to go back to the original native space. So-- and that depends. There are a bunch of ways to go back. If you've done-- if it got in-- if it's in a standard space by an affine transformation, all these methods work. And they work pretty similarly.
So you can use 3d Allineate3, 3dWarp, and 3dfractionize. This-- the last one is the slowest. But if you've got multiple ROIs that have to go back into a native space, this has a voting option that can help there. So this is here. I don't expect you to memorize this. I don't have it memorized either. So-- but just as a reference.
If you've gone to a standard space through a non-linear transformation, here's an example how to go back, while here's how you might have gotten there, with a combination of add auto [INAUDIBLE] and auto warp, or just auto warp. You could do it that way. And 3dNwarpApply is what you would use to go backwards. And you give it these parameters.
So here it's going to invert your translation-- you're affine transformation and your nonlinear warp, and put it-- put the data back into the native space. Now remember, if you're working with ROIs, you'll probably want to use a nearest neighbor interpolation, because you don't want fractions of an ROI. You just want the value itself.
But otherwise, you can use other kinds of interpolations, like linear, cubic, or W sync, windowed sync 5, or something like that. Some other ways that can do the similar things-- 3dNwarpApply is probably the most robust for this. This was a controversy several years ago, that there was something-- the problem of circularity and that people were supposedly double dipping.
They were taking their regions and then taking parts of their regions, and saying, look how correlated everything is. And these are really useful results. And that was called what-- voodoo FMRI. Is that what it was called?
AUDIENCE: Voodoo circularity.
DANIEL GLEN: Voodoo circularity.
AUDIENCE: [INAUDIBLE].
DANIEL GLEN: And so, different ways to avoid this. In many cases, this was not really done if you looked very closely at the studies. Every couple of years, there's some major controversy in FMRI. And sometimes it's real, and sometimes it's not. But so you want to avoid double dipping. You want to make sure your statistics are valid.
So one way to do this is use ROIs from independent data sets-- from previous studies, from atlas regions, from set up a locator task, or just split your samples. So you can do it from other subjects. This was done with AFNI. One way to do it with a locator task is shown down here. So you can take the transformations from one data set and apply it to your-- from your locator task to your task data set. And here's the command you might use for that. And that's it.