regarding gamma test of 2D arrays(images)

35 views
Skip to first unread message

Alexander S

unread,
Jul 7, 2020, 8:49:34 AM7/7/20
to PyMedPhys
Dear all,

I am working the MC simulations and Gafchromic films, where my obtained dose maps are usual 2D images.
I would like to know how I could use this package to perform the gamma test on such inputs instead of standard dicoms , and what special conditions are necessary for input images(same x, y pixel count and grey-scale, I guess?)

Thank you very much for your help,

Regards
Aleksandras

Simon Biggs

unread,
Jul 7, 2020, 8:54:35 AM7/7/20
to Alexander S, PyMedPhys
Hi Aleksandras,

Within the docs is an example where two 2D maps are compared:


But it should also be possible to compare a 2D film result to a 3D dose map also. Are you in a position to provide example data, and I can show you how you might go about allowing the gamma to not only search along the film plane in the 3D MC dose grid, but also along the axis perpendicular to the film plane.

Cheers,
Simon

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymedphys+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pymedphys/dc4af9f7-e1ac-4e8b-9101-4fbf3c9f2392o%40googlegroups.com.

Alexander S

unread,
Jul 7, 2020, 9:37:03 AM7/7/20
to PyMedPhys
Thanks. I am quit new with python, however. Could you please help, how I could generate a valid dose map from actual jpeg, for example, instead of artificial one:

So instead of this:

xmin = -28
xmax = 28
ymin = -25
ymax = 25
extent = [xmin-grid/2, xmax+grid/2, ymin-grid/2, ymax+grid/2]
x = np.arange(xmin, xmax + grid, grid)
y = np.arange(ymin, ymax + grid, grid)

coords = (y, x)
xx, yy = np.meshgrid(x, y)
dose_ref = np.exp(-((xx/15)**20 + (yy/15)**20))

plt.figure()
plt.title('Reference dose')
plt.imshow(dose_ref, clim=(0, 1.04), extent=extent)
plt.colorbar()


I can first do this:

image = Image.open('original_dose.jpg')
data = np.array(image)


But I am not sure how to proceed further,

Regards
A.


On Tuesday, 7 July 2020 15:54:35 UTC+3, Simon Biggs wrote:
Hi Aleksandras,

Within the docs is an example where two 2D maps are compared:


But it should also be possible to compare a 2D film result to a 3D dose map also. Are you in a position to provide example data, and I can show you how you might go about allowing the gamma to not only search along the film plane in the 3D MC dose grid, but also along the axis perpendicular to the film plane.

Cheers,
Simon

On Tue, 7 Jul 2020 at 22:49, Alexander S <ragna...@gmail.com> wrote:
Dear all,

I am working the MC simulations and Gafchromic films, where my obtained dose maps are usual 2D images.
I would like to know how I could use this package to perform the gamma test on such inputs instead of standard dicoms , and what special conditions are necessary for input images(same x, y pixel count and grey-scale, I guess?)

Thank you very much for your help,

Regards
Aleksandras

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

Simon Biggs

unread,
Jul 7, 2020, 9:52:01 AM7/7/20
to Alexander S, PyMedPhys
Hi Aleksandras,

Can I recommend taking a look at some of the following film code and their associated papers:


Turning a film scan into a dose map requires more than just code of course, such as appropriate film handling, scan protocols, etc. This is all well documented within the literature though.

Cheers,
Simon

To unsubscribe from this group and stop receiving emails from it, send an email to pymedphys+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pymedphys/aba0cebc-687a-4e03-813c-bf263c7bc547o%40googlegroups.com.

ragna...@gmail.com

unread,
Jul 7, 2020, 11:01:50 AM7/7/20
to m...@simonbiggs.net, PyMedPhys

I am aware about the protocols of the film preparation, however, the coding is my weaker part at the moment.

The code link you provided looks really good, however, as the most of such codes, contains a huge drawback – no proper documentation for entry level users.

The provided documentation are just the links to the theoretical frameworks that code uses. But maybe I miss something?

 

Could you maybe please explain: if I have (n,n) matrix in which the pixel gray values correspond to dose value,  how should I proceed to obtain correct form of input for coords, dose_ref ?

 

A.

ragna...@gmail.com

unread,
Jul 7, 2020, 2:48:29 PM7/7/20
to m...@simonbiggs.net, PyMedPhys

Update:  I found my mistakes and was able to successfully convert the images and use the tool. Thanks!

 

A.

Randle Taylor

unread,
Jul 7, 2020, 4:26:34 PM7/7/20
to ragna...@gmail.com, m...@simonbiggs.net, PyMedPhys
Just wanted to chime in and say in general you do not want to use JPG for scientific images.  JPG images are usually compressed (lossy) and can give misleading results (this is maybe not always true, but better safe than sorry).  Saving your scan to 8 or 16 bit TIFF (lossless) images is a safer bet!

Randy

ragna...@gmail.com

unread,
Jul 7, 2020, 4:54:02 PM7/7/20
to Randle Taylor, m...@simonbiggs.net, PyMedPhys

Indeed, thank you much for your notice.

My previous questions were related just for the testing purposes.

I see that it works really well and as intended.

Rgds

A.

ragna...@gmail.com

unread,
Jul 7, 2020, 5:08:17 PM7/7/20
to Randle Taylor, m...@simonbiggs.net, PyMedPhys

If I may one more time, just to clarify the last thing,

In the example https://docs.pymedphys.com/howto/gamma/effect-of-noise.html,

 

'distance_mm_threshold': 3,

xmin = -28

xmax = 28

ymin = -25

ymax = 25

 

Do I understand correctly that in this particular example the generated image is normalized to 1 mm per pixel ?

For example, if I had 100x100 image with pixel size 0.2 mm, and I would like to apply distance threshold 3 mm, the actual value I should put in should be 'distance_mm_threshold': 15,

 

Thank you very much,

 

Rgds

Alex

 

From: Randle Taylor <randle...@gmail.com>
Sent: Tuesday, July 7, 2020 23:26
To: ragna...@gmail.com

Simon Biggs

unread,
Jul 7, 2020, 6:26:16 PM7/7/20
to Alexander S, Randle Taylor, PyMedPhys
Hi Alex,
 
The code link you provided looks really good, however, as the most of such codes, contains a huge drawback – no proper documentation for entry level users.

There is an interesting dynamic within the open source community. Most often people are sharing items that they made that were of value to them. It is shared in the hope that it will be useful, but also, the item is shared is something that was already made, something that only took a little bit of extra work to share it. As a result the community is often quite efficient, because the items being made and shared are those items that each person was already going to make for themselves, they just posted it up in case someone else might find it helpful.

And here is where you come in. Once you have this question of yours answered, through your toil, and other's guidance, you are in the prime position to meet the very need that you encountered when you entered the community. Once you have an example MC dose grid file, and an example film scan, you could, for example, attach those files to an email on this forum along with a fully working example that acts on those files. It could use Scott's film code, and then it could call PyMedPhys' gamma code. And so the community grows, expands, and improves. Each person still simply submitting that which they found useful. By having more beginners in the community who then share their snippets of working code, there will be more examples that are accessible by beginners. 

By sharing in a forum like this, the answers are then google searchable. Also to make the example more discoverable, once you create a working example, with your permission, I can upload it into the how-to section of the docs (https://docs.pymedphys.com/howto/gamma/index.html), while linking back to this forum post so that users can see the process undergone to make the example.

Do I understand correctly that in this particular example the generated image is normalized to 1 mm per pixel ?

To answer your question from the example at https://docs.pymedphys.com/howto/gamma/effect-of-noise.html, the important feature that defines the distance scale is the "coords" variable:

grid = 0.5

x
= np.arange(xmin, xmax + grid, grid) y = np.arange(ymin, ymax + grid, grid) coords = (y, x)

gamma_no_noise = pymedphys.gamma(
    coords, dose_ref,
    coords, dose_eval,
    **gamma_options)

As you can see, the coord parameter has been defined with a step size of 0.5 mm using the grid variable. I could probably name this better / highlight via a comment that this parameter will correspond to the pixel resolution ie 1 pixel -> 0.5 mm.

Cheers,
Simon



Aleksandras

unread,
Jul 8, 2020, 1:46:06 AM7/8/20
to Simon Biggs, PyMedPhys
Hi Simon,

It would be amazing to reach such a level that my code would be useful to someone else - and I would gladly share it to the community. However, as you see from my questions, I am still at a very trivial level , where I need to google how to convert an image to array in the python  - and therefore a clear example of code usage is essential for me at the moment. Without nicely provided examples I would not be able to use pymedphys. So thanks again not only for creating the code, but also making all the documentation with the examples of how to use it.
My current data are two images from different areas - a film image (with calibration curve, done manually), and the MC simulation image. In the very first step I needed to find a working gamma test algorithm that I would be able to use for 2D - done.  Second, I need to convert pixels to dose according to the calibration curve - not sure at the moment how to do that. I am trying to understand Scott's film code - but I can't find a single example showing how it works. Should I just import calibration.py,  create a class object of the needed calibration, and use def plot_calibration(calibration, filename) ? So my output is a calibration curve?  But how to convert the pixel values to dose values according to it? As far as I understand, I just multiply the pixel value by its corresponding calibration value - but I still need to learn how to implement this in python properly ( it is probably again very trivial ). Then I need to normalize the MC image according to it. Last, I have no idea yet how to align the images so precisely that it would not impact the gamma test.
I will gladly commit my input if anyone finds it useful, and as soon as I have a working example. As for the moment, these images are different, not suitable for gamma test, and without above described modifications it makes no sense to compare them.




Simon Biggs

unread,
Jul 8, 2020, 3:14:19 AM7/8/20
to Aleksandras, PyMedPhys, sb.c...@gmail.com
Hi Alex,

Regarding your question on how to use Scott's library, that might be best directed to Scott himself, I'll cc him into this email via the email address posted on his webpage (http://sbcrowe.net/).

There certainly are quite a few steps involved in what you're discussing. A while ago I wrote some code that allowed one to contour a box inside of the MaxHD phantom (https://gammagurus.com/products/max-hd-end-to-end-srs-phantom) and then extract the dose grid out from that DICOM dose file in the locations of the axis of that box (which corresponded to the film inserts). The dose grid interpolation was done in such a way so that the 2D images produced are in the same coordinates, orientation, and position as the film. This allowed precise correspondence between the film image and the planning system. The prototyping code is within the following notebook:


It never reached production stage, and I know for a fact that the pymedphys imports being used in that notebook no longer exist in those locations, so that code won't work as is. But nevertheless, it provides one idea of how one might solve the alignment problem between a dose grid and a film image.

Cheers,
Simon



Aleksandras

unread,
Jul 8, 2020, 4:15:17 AM7/8/20
to Simon Biggs, PyMedPhys, sb.c...@gmail.com
Thanks for the discussion and links, it really helps.
I sincerely tried to use calibration.py, but it gives me various errors. Even when I managed to plot polynomial fit, it didn't correspond correctly to the stated numbers of degrees...However, I actually need only polynomial fit and its coefficients, so a single function of numpy.polyfit gives me that, and with that I can calculate a proper dose map in a few code lines.It's a first time I am using numpy library, and I didn't know is capabilities, including superb manipulation of matrices in the form of np.array.
So this step also seems to be solved.
So I will start to work with alignment of images. I will look through your work,
Rgds
A.

Simon Biggs

unread,
Jul 8, 2020, 4:39:09 AM7/8/20
to Aleksandras, PyMedPhys, sb.c...@gmail.com
You might also be interested in the weiner filter:

Also, the univariate smoothing spline can be a neater solution than a polynomial fit:
You just have to choose a sensible smoothing value.

Scott Crowe

unread,
Jul 8, 2020, 5:21:49 AM7/8/20
to PyMedPhys
Hey Alex,

I'm glad you've developed a solution - numpy is a wonderful library. For reference, in case anyone else stumbles on this discussion, an example of how the calibration is performed using that code is shared here; utilising data included in the publication "Accuracy and efficiency of published film dosimetry techniques using a flat-bed scanner and EBT3 film". The netOD values are explicitly defined in this example - the intent of the code is that these values would be calculated from images imported by the user. 

Good luck with your registration process.

Scott.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyme...@googlegroups.com.

Aleksandras

unread,
Jul 8, 2020, 5:26:15 AM7/8/20
to Scott Crowe, PyMedPhys
Hi Scott,

Thank you very much for your help. I will certainly try it again now. Sorry that due to my lack of experience I didn't think to look through the folders - I will keep now this in mind in future,

Regards
A.

To unsubscribe from this group and stop receiving emails from it, send an email to pymedphys+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pymedphys/e3eb604d-410f-43a0-a3e8-0c042bdfd91eo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages