I found the basic MATLAB implementation of a two-dimensional gamma index in Appendix A this thesis .
I copy / paste the following code from the thesis and I made a couple of simplifications for readability. I spoke with the author and confirmed that my version of the code (below) is correct. Recently, I used this code in the analytic part of a study of medical physics, which I will publish soon.
Inputs A1 and A2 are two-dimensional arrays (which in practice are dose maps or fluence maps). We will use A1 as reference data and A2 as data that is being evaluated. If we use the typical acceptance criterion of 2%, 2 mm, then we set the distance to agreement as DTA=2mm , and we set the dose threshold dosed=0.02 , which is 2%.
In this simple implementation, we assume that the array indices are spaced 1 mm apart. If your data does not use 1 mm increments, then change the dosed value dosed (for example, if your A1 and A2 in 0.5 mm increments, use DTA=4 to get a 2 mm criterion).
The output, G , is a 2D array of gamma values.
function G = gamma2d (A1, A2, DTA, dosed) size1=size (A1) ; size2=size (A2) ; dosed = dosed * max(A1 ( : ) ) ; %scale dosed as a percent of the maximum dose G=zeros ( size1 ) ; %this will be the output Ga=zeros ( size1 ) ; if size1 == size2 for i = 1 : size1( 1 ) for j = 1 : size1( 2 ) for k = 1 : size1( 1 ) for l = 1 : size1( 2 ) r2 = ( i - k )^2 + (j - l) ^2 ; %distance (radius) squared d2 = ( A1( i , j ) - A2( k , l ) )^2 ; %difference squared Ga( k , l ) = sqrt(r2 / (DTA^2) + d2/ dosed ^ 2); end end G( i , j )=min(min(Ga)) ; end end else fprintf=('matrices A1 and A2 are do not share the same dimensions! \n') end end
To see the explanation of the gamma index in mathematical notation, I recommend watching this blog post .
source share