DICOM example

DICOM example#

If the dose distribution is generated with a treatment planning system (TPS), export only a dose plane, with a reference point (usually the isocenter on the center of the dose plane image).

In this guide we are going to use the file ‘RD_20x20cm2_256x256pix.dcm’. It is inside the folder /Dosepy/docs/Jupyter. The DICOM file was created with Eclipse (version 15.1), exporting a region of interest of 20 cm x 20 cm, centered on the isocenter and with 256 x 256 pixels.

Let’s import Dosepy and numpy

from Dosepy.image import load
import numpy as np

To read a DICOM file, we call the load() function:

dicom_path = "/home/luis/Documentos/RD_20x20cm2_256x256pix.dcm"

D_tps = load(dicom_path)

#---------------------------------------------
#   Code to plot the dose distribution
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 1, figsize=(8, 4))
axes.imshow(D_tps.array, cmap='viridis', vmin=0, vmax = 1.15 * np.percentile(D_tps.array, 98))
plt.show()
#---------------------------------------------
_images/bd6190c92b1895b93f49952e3ff4f2b196ad9e0011f3082b3d902934d78f8054.png

Open the film dose distribution

film_array = np.genfromtxt('/home/luis/Documentos/D_20x20_film_300dpi.csv', delimiter=",", comments="#")
D_film = load(film_array, dpi=300)

print(f"D_tps shape: {D_tps.shape}")
print(f"D_film shape: {D_film.shape}")
D_tps shape: (256, 256)
D_film shape: (2362, 2362)

D_tps and D_film have different spatial resolution (dpi). In order to compute gamma, we need to equate the images.

D_film.reduce_resolution_as(D_tps)

print(f"D_tps shape: {D_tps.shape}")
print(f"D_film shape: {D_film.shape}")
D_tps shape: (256, 256)
D_film shape: (256, 256)
#---------------------------------------------
#   Plot

import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()
ax[0].imshow(D_film.array, cmap='viridis', vmin=0, vmax = 1.15 * np.percentile(D_tps.array, 98))
ax[0].set_title('Film')
ax[1].imshow(D_tps.array, cmap='viridis', vmin=0, vmax = 1.15 * np.percentile(D_tps.array, 98))
ax[1].set_title('TPS')
fig.tight_layout()
plt.show()
#---------------------------------------------
_images/b3f14e6f91bde1ac28bf139582bb0bdd66f2ad7418f28369690d53bd64e2e9de.png

Make a ROI selection

D_tps = load(D_tps.array[90:165, 75:175], dpi=D_tps.dpi)
D_film = load(D_film.array[90:165, 75:175], dpi=D_film.dpi)
#---------------------------------------------
#   Plot

import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()
ax[0].imshow(D_film.array, cmap='viridis', vmin=0, vmax = 1.15 * np.percentile(D_tps.array, 98))
ax[0].set_title('Film')
ax[1].imshow(D_tps.array, cmap='viridis', vmin=0, vmax = 1.15 * np.percentile(D_tps.array, 98))
ax[1].set_title('TPS')
fig.tight_layout()
plt.show()
#---------------------------------------------
_images/7c9b9b4f6dbafe6028d0e2eaa0369d7afd3814fff81f5c41068e2e991fb03f04.png

Compute gamma

g, pass_rate = D_tps.gamma2D(D_film, 3, 2, dose_threshold = 10, mask_radius = 10)

print(f'Pass rate: {pass_rate:.1f} %')
Pass rate: 98.4 %
fig, axe = plt.subplots()
g_im = axe.imshow(g, vmax=1.5)
fig.colorbar(g_im, ax=axe, label='Gamma')
<matplotlib.colorbar.Colorbar at 0x779b00695c90>
_images/0711fd090ae9ade6a40218461d3387e7f20dcbedcb84f689e0c6a9f53a156d3f.png