I am a radiological technologist and a medical physicist. I will leave a memorandum of the process of learning programming in the article. I hope it will be helpful to someone in the future.
What do you want to do with Python in the medical setting? Python is widely used in medical image processing, and there are many themes such as automatic recognition of lesions from images in the field of machine learning. Images used in the medical field are data in the format of DICOM. It can be said that knowledge of DICOM is indispensable for programming in the medical field, mainly image processing. And the first barrier I want to try for the time being is ** "Display images in Python" **.
First, let's organize DICOM (for myself).
DICOM is an abbreviation that connects the acronyms ** "Digital Imaging and Communications in Medicine" **. It is a standard used for communicating medical image information, etc., and is used worldwide. In the data to be communicated, not only the image data that is generally imaged, but also many items such as patient name, patient ID, examination date, device name, and imaging conditions are defined as incidental information.
There are various manufacturers of machines and communication equipment used for inspection, but data is smoother by using common rules that do not depend on manufacturers such as DICOM, instead of handling data with original rules. You can manage it.
In the past (still in some facilities), film X-rays were used for diagnosis, but the shift from analog to digital medical images has made it easier to manage vast amounts of medical data. The existence of DICOM also helps with that.
As an aside, the radiation therapy field has some special DICOM data that is not found in the diagnostic field. This is not necessary knowledge in the process of displaying images, but I am engaged in the radiotherapy department myself, so I will touch on a little. DICOM data (DICOM RT) for radiotherapy includes image-based data like DICOM of other image modality, and non-image-based data such as coordinate information and device setting information. RT dose represents dose information, RT Structure represents contool information, and RT Plan represents device operation information, each of which is linked as information for treatment.
[Reference] DICOM reverse lookup BOOK (You can view the seminar slides → DICOM study session materials)
In addition to this, there is a lot of useful information about DICOM in Japan Imaging Medical System Industry Association [JIRA]: The World of DICOM. It is posted, so please refer to it.
There was a time when I was studying C # for a while, I couldn't even display one slice of the CT image. So it's a pretty high hurdle for me to even display an image ... I thought it wasn't something I could do for the time being.
However!! It was easy with Python! I was surprised. Is it so easy? Thanks to the rich library, you can display it with just knowing the simple code. Thanks to those who made the library.
This time I will use DICOM images that can be used for free, so It doesn't matter if you don't have a DICOM image at hand. I am once again indebted to DICOM World. I'm just grateful.
python 3.7.4 matplotlib 3.1.1 pydicom 1.2.2 Terminal (I don't use Jupyter Notebook) Atom (any text editor is acceptable)
show_dicom.py
from matplotlib import pyplot as plt
import pydicom
cr = pydicom.read_file("CR_LEE_IR6a.dcm")
plt.imshow(cr.pixel_array, cmap = "gray")
plt.show()
** * Save the DICOM data (.dcm) to be used in the same directory as the code (.py). ** **
that's all. Isn't it super easy? I was able to display the image in just 5 lines. You can do this with simple code by leveraging the great existing modules such as matplotlib and pydicom.
I will omit the Python grammar. Please try it.
Finally, I would like to introduce a very useful site. ** Euromedic Medical Physics Room ** Medical Physics Room Blog It contains detailed information that will be very helpful when using Python in the field of radiation therapy. There is no doubt that it will be useful, so if you are interested, check it out!
Recommended Posts