Gamma Compare

60 views
Skip to first unread message

Stephen Amadon

unread,
Jul 1, 2024, 5:51:31 PM7/1/24
to Pylinac
Good evening,

Trying to compare 2 images (chair patterns).  Getting error message about max.  See below.  Am I missing an input into the command?

Thanks,

Steve

ref = image.load(r"C:\Users\Caitlin\PF\Image\Ref_6x_Chair.dcm")
eval = image.load(r"C:\Users\Caitlin\PF\Image\6x_Chair.dcm")

gamma = image.gamma_2d(reference=ref,evaluation=eval, dose_to_agreement=2, distance_to_agreement=3,global_dose=True)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Caitlin\AppData\Roaming\Python\Python311\site-packages\pylinac\core\image.py", line 1997, in gamma_2d
    threshold = reference.max() / 100 * dose_threshold
                ^^^^^^^^^^^^^
AttributeError: 'DicomImage' object has no attribute 'max'. Did you mean: 'cax'?


James Kerns

unread,
Jul 1, 2024, 6:08:48 PM7/1/24
to Pylinac
Documentation on gamma is limited right now but we'll be adding and expanding it within the next 2 releases. 

To use gamma for an existing image you should use the gamma method. The `gamma_2d` function that you're calling is meant for arrays. 

So, `ref.gamma(comparison_image=eval, ...)` works or `image.gamma_2d(reference=ref.array, evaluation=eval.array, ...)` are both alternatives.

Stephen Amadon

unread,
Jul 2, 2024, 3:01:16 PM7/2/24
to Pylinac
I ran this below and no errors.  What is the best way to print the results?  I tried a couple different commands and did not get a result.  Would like to print the gammamap and a pass rate.

Thanks,

Steve

import matplotlib.pyplot as plt
from pylinac import image

# place images in folder (C:\Users\Caitlin\PF\Image\)  before next command


ref = image.load(r"C:\Users\Caitlin\PF\Image\Ref_6x_Chair.dcm")
eval = image.load(r"C:\Users\Caitlin\PF\Image\6x_Chair.dcm")

gamma = ref.gamma(comparison_image=eval)

Safir

unread,
Jul 3, 2024, 5:44:29 AM7/3/24
to Pylinac
Hi,

I think you need to add plt.imshow(gamma) to plot the image and plt.show() to show it. Your code would then look like that:


import matplotlib.pyplot as plt
from pylinac import image

# place images in folder (C:\Users\Caitlin\PF\Image\)  before next command


ref = image.load(r"C:\Users\Caitlin\PF\Image\Ref_6x_Chair.dcm")
eval = image.load(r"C:\Users\Caitlin\PF\Image\6x_Chair.dcm")

gamma = ref.gamma(comparison_image=eval)
plt.imshow(gamma)
plt.show()


Regards,
Safir

Stephen Amadon

unread,
Jul 3, 2024, 4:30:37 PM7/3/24
to Pylinac
Thanks,

I had this previously tried this: plt.imshow(gamma)
The result did not make sense to me:
<matplotlib.image.Axes Image object at 0x000002848A4F0210>

The plt.show() did give a nice picture of the chair pattern, but not really sure it gives useful information.

Thanks for your help.

Steve
Reply all
Reply to author
Forward
0 new messages