pylinac icon indicating copy to clipboard operation
pylinac copied to clipboard

About gamma analysis

Open LuisOlivaresJ opened this issue 1 year ago • 1 comments

Describe the bug On core.image.BaseImage.gamma() method,

If the parameter normalize is set to False, an update on doseTA must be performed with respect to the maximum dose:

doseTa = doseTa * np.max(ref_img)

Otherwise lines 935-937 work with incorrect physical dimensions, i.e. doseTA as a percentage (0 -100) and grad_img as absolute dose values (Gray) https://github.com/jrkerns/pylinac/blob/22185452c0cd6c11eb57238bfea34736ed933cd6/pylinac/core/image.py#L935-L937

From the article "A revision of the γ -evaluation concept for the comparison of dose distributions" by Annemarie Bakai, et.al. Image

I would be happy to create a pull request to include it if you want.

LuisOlivaresJ avatar Apr 15 '25 23:04 LuisOlivaresJ

Hello,

The gradient calculation currently uses the Sobel filter (line 929), https://github.com/jrkerns/pylinac/blob/22185452c0cd6c11eb57238bfea34736ed933cd6/pylinac/core/image.py#L929-L930 which involves a convolution operation with a 3x3 kernel. Because of this, the gradient in one direction includes some contribution from the other direction. I'm not sure if this is the intended behavior for gamma analysis. I suggest using np.gradient(img) instead of Sobel.

For example, if we have an array with a uniform increase of one to the right and a uniform increase of ten to the bottom, should the output be a uniform array of one (for axis=1) and ten (for axis=0) as obtained with np.gradient()?

#Create an uniform increase array and show it
import plotly.express as px

uniform_increase_array = np.arange(0, 100).reshape(10, 10)
px.imshow(uniform_increase_array)

Image

# Calculate with sobel to the right
from scipy.ndimage import sobel

sobel_x = sobel(uniform_increase_array, axis=1)
px.imshow(sobel_x)

Image

# Calculate with np.gradient to the right
import numpy as np

gradient_x = np.gradient(uniform_increase_array, axis=1)
px.imshow(gradient_x)

Image

A similar result is obtained for axis=0, Sobel outputs a gradient of 80, and np.gradient an output of 10.

Thank you, Luis

LuisOlivaresJ avatar Apr 23 '25 18:04 LuisOlivaresJ