So again, when we do transformations of images,

we usually have some sort of interpolation.

So I take your brain, or I'll take an image and I'll warp it around and for

example a binary mask.

So when we put that in a new space it's going to be located with the voxel

sizes and the dimensions in the template space.

What that means is, although the region of interest initially was binary.

We actually take it, warp it and we do some interpolation,

AKA some local averaging.

So we take an area of the brain, let's say we put it here and

what do we want to assign that voxel to?

Well, we take a local average of neighboring voxels to get

that voxel value in the template space.

What that means again is that the ROI in the template space

is no longer binary due to interpolation.

So, I did a histogram of the ROI

after it has been non-linearly warped to the template space.

Again, note that this would have happened with the affine registration,

a rigids registration to the template and so forth.

So actually, any registration where you 're changing the voxel dimensions in

the space generally will have some interpolation.

So you have to, if you want to create a binary ROI,

again, you have to do some thresholding.

So in general, a lot of recommendations for binary mass for rigid or

affine registration, or affine transformations.

They say it's maybe used around a 0.5 cutoff,

but we recommend to investigate the image in the template space.

Or in the transform space with different cut off's to see what gives kind of

reasonable results.

And this is that are easy to do with one image, sometimes it's harder to do it in

the entire pipeline of hundreds or thousands of images.

But, you want to at least do some double checks to make sure that

they overlap to what the area should be.

So again, now that it's not binary, we want to say where is this ROI?

So we can do one of two things and I would say one of the most common things to do,

is to do thresholding like we just discussed.

Or depending on what we're doing to just add up the voxel values.

So in some respects, because we're averaging zero to one's,

this can be thought as a proportion.

Or maybe a probability that this voxel is in ROI is brain tumor, right?

So, for example for the impact to the histogram,

0.8 means that when you did some local averaging.

There was about 80% of the neighbouring voxels [INAUDIBLE], so

you can kind of think of it as a probability.

So sometimes for certain problems,

you way want a threshold, you may want to be able to just do a weighted sum.

Where you don't have to sets threshold agnostic,

it doesn't matter what threshold you use.

So here, what we're doing is creating another data frame and

I'll be using the plyr package, and I'll tell you why in a minute.

We're making another data frame, where we took the [COUGH] index.

Now corresponds to the voxel we take syn_roi greater than zero.

So all the voxels of the ROI in the template space that are greater than zero.

And we subset the labels, the atlas labels and we call that index and

then we took the again just the actual values of the ROI.

And so now you have a data frame with two columns one saying,

what is the value of the voxel of the ROI?

And the template space and then what is the associated label on the atlas?

So now I use ddply from the plyr package to say roi.df.

So the data frame we just created and I want to go through each index.

So every single label of the atlas and

I want to summarize it in saying I want to add up all the the voxels.

All the raw intensities or

I want to add it up where only voxels are greater than 0.5.

And I'm actually not adding up only voxels greater than 0.5,

I'm saying if you're greater than 0.5 you're a one.

You already have ROI and

if you're not greater than 0.5 we're going to set you to zero.

So these represent slightly different things, but

they represent for each individual atlas label.

The number of voxels that were counted, so either a weighted sum or

the number greater than 0.5, okay?

And then, we'll actually merge this with the data frame that has the labels.

For example the cingulate and so forth, from the Look Up Table.

So now we can say of the actual image of the ROI,

where do these things lie, and what percentage overlap do we have?

So again, I'm just doing some simple book keeping and

sorting here to actually sort the data frames.

So if you actually do use this code and actually look at each operation.

All we are doing is some merging, some sorting just so

we can actually get to this last table, which I will show you.

The areas of the brain that are engaged by the tumor or the region of interest.

So for example,

the precentral gyrus on the left hand side is engaged by the tumor.

And so what we actually did is we normalized these columns, so

we took the column and divided by the column sums.

And that now each element in this table represents of

the entire ROI, what percent engages this area.

So for example, 15.6% of the brain tumor is in

the precentral gyrus on the left-hand side.

12.9% is in the precentral white matter on the left-hand side.

And so one of the nice things that we see comparing left to right on each of

the rows, is that they relatively comparable?

So that, even if we use a threshold of 0.5 or you use the weighted sum.

You get generally the same results for

how much of the brain tumor's engaged by a certain region.

So this is really nice, so you can now tell clinicians that this patient.

For example, 9.4% of the brain tumor

was engaged in the superior temporal gyrus and so on and so forth.

And then, you can do more things, as in collapsing left and right labels or

collapsing larger areas, so on and so forth.

But this allows you to get to some clinically meaningful or

translatable answer.