Python in Medical Imaging and Radiology

Author
Admin
Last updated
Aug 25, 2026

Python is widely used in medical imaging research, image processing, quantitative analysis, and artificial intelligence. Its combination of readable syntax and a large scientific-computing ecosystem makes it particularly useful for developing reproducible workflows and research tools.

In medical imaging, Python can be used to work with DICOM data, visualize images, perform quantitative analysis, process 2D and 3D images, develop radiomics workflows, and build machine-learning and deep-learning models.


Reading DICOM Images

DICOM is the standard used to store and exchange medical imaging information and associated metadata. Python provides several tools for working with DICOM files, including the widely used pydicom library.

For example:

import pydicom

dataset = pydicom.dcmread("CT001.dcm")

print(dataset.PatientName)

The dcmread() function reads and parses a DICOM dataset and returns a dataset object whose attributes can be accessed using DICOM keywords.

This allows a Python program to access information such as:

  • Patient and study information
  • Modality
  • Image dimensions
  • Pixel spacing
  • Slice thickness
  • Acquisition parameters
  • Pixel data

Important: Patient-identifying information should be handled carefully. Real clinical DICOM data should not be uploaded to public repositories such as GitHub unless it has been appropriately de-identified and its use is permitted.


Python can also be used to visualize medical images.

Displaying Medical Images

The Matplotlib library provides the imshow() function for displaying two-dimensional image data. For grayscale medical images, the gray colormap is commonly used.

For example:

import matplotlib.pyplot as plt

plt.imshow(image, cmap="gray")
plt.show()

This simple approach can be used as a starting point for displaying:

  • CT slices
  • MRI images
  • X-ray images
  • Ultrasound images
  • Processed medical images

As you progress through PyMedLab, you will learn how to control image intensity, window and level CT images, add colorbars, display multiple slices, and visualize three-dimensional image volumes.


Measuring Hounsfield Units

One of the important quantitative applications of Python in CT imaging is the analysis of Hounsfield Units (HU).

CT images contain stored pixel values that may need to be converted to the appropriate physical output values using information contained in the DICOM metadata. For conventional original CT images, the DICOM standard defines the relationship using Rescale Slope and Rescale Intercept: HU=Rescale Slope×SV+Rescale Intercept

where SV represents the stored pixel value. The DICOM standard specifies that, for applicable original CT images, the output units are Hounsfield Units.

Python can automate this process and then be used to calculate:

  • Mean HU
  • Minimum and maximum HU
  • Standard deviation
  • ROI statistics
  • HU histograms
  • Tissue-related quantitative measurements

This makes Python useful for quantitative CT analysis and research workflows.


Image Processing and Segmentation

Python can be used to process medical images and develop segmentation workflows.

Typical applications include:

  • Lung segmentation
  • Liver segmentation
  • Brain extraction
  • Tumor delineation
  • Organ segmentation
  • Region-of-interest analysis

Image-processing workflows can include operations such as:

  • Noise reduction
  • Filtering
  • Thresholding
  • Edge detection
  • Morphological processing
  • Registration
  • Segmentation
  • Feature extraction

These techniques form an important foundation for medical image analysis and later machine-learning applications.


Radiomics and Quantitative Imaging

Python is also useful for extracting quantitative features from medical images.

Radiomics involves extracting large numbers of quantitative features from medical images that may describe characteristics such as:

  • Intensity
  • Shape
  • Texture
  • Spatial relationships

Python-based tools can support reproducible radiomics workflows and integrate image analysis with statistical and machine-learning methods.

This creates a bridge between:

Medical Imaging → Quantitative Features → Data Analysis → Machine Learning

and is an important area for medical physics and medical imaging research.


Artificial Intelligence in Medical Imaging

Python has become an important programming language for artificial intelligence and machine learning research, including medical image analysis.

AI methods are being investigated for tasks such as:

  • Image classification
  • Lesion detection
  • Image segmentation
  • Image reconstruction
  • Image synthesis
  • Quality assessment
  • Workflow automation

Research in medical imaging has demonstrated applications of machine learning and deep learning across modalities such as CT, MRI, X-ray, ultrasound, PET, and other forms of medical imaging.

Examples of research applications include:

  • Pneumonia detection
  • Lung nodule detection
  • Breast lesion classification
  • Brain tumor segmentation
  • Organ segmentation
  • Fracture detection

These examples should be understood as research and development applications. A model that performs well on a dataset is not automatically suitable for clinical diagnosis. Clinical deployment requires appropriate validation, safety assessment, regulatory considerations, and monitoring. Recent reviews emphasize the importance of external validation, transparency, privacy, fairness, and clinical evaluation for trustworthy medical-imaging AI.


Real-World Applications for Medical Physicists

Python can support a wide range of tasks in medical physics and medical imaging research.

Examples include:

Quality Assurance

  • Automating QA calculations
  • Processing measurement data
  • Generating reports
  • Monitoring trends

Medical Image Analysis

  • CT image-quality analysis
  • MRI analysis
  • PET image analysis
  • Image statistics
  • ROI measurements

Quantitative Imaging

  • Hounsfield Unit analysis
  • Image-intensity measurements
  • Texture analysis
  • Radiomics

Research

  • Data analysis
  • Statistical calculations
  • Visualization
  • Reproducible research workflows
  • Development of research software

Artificial Intelligence

  • Machine-learning models
  • Deep-learning models
  • Image classification
  • Segmentation
  • Detection

Python therefore provides a practical bridge between programming, physics, medical imaging, and computational research.


Why Does PyMedLab Use Python?

At PyMedLab, we believe programming is most useful when it is connected to a real problem.

Instead of learning Python only through abstract examples, you will gradually apply programming concepts to medical imaging and medical physics problems.

For example, you will learn how to:

  • Read DICOM studies
  • Extract DICOM metadata
  • Display CT slices
  • Work with image arrays
  • Calculate Hounsfield Units
  • Analyze image statistics
  • Visualize MRI and CT data
  • Process medical images
  • Build segmentation workflows
  • Develop machine-learning models
  • Explore medical-imaging AI

The goal is not simply to learn Python syntax.

The goal is to learn how to use Python as a tool for solving medical physics and medical imaging problems.


Your Learning Journey at PyMedLab

Your learning pathway is designed to move from fundamental programming concepts toward real medical-imaging applications.

Module 1
Getting Started
│
├── Why Python?
├── Installing Python
├── VS Code
├── Anaconda
├── Jupyter Notebook
└── Virtual Environments
        │
        ↓
Module 2
Python Fundamentals
        │
        ↓
Module 3
Scientific Computing
        │
        ↓
Module 4
Medical Imaging
        │
        ↓
Module 5
Data Science
        │
        ↓
Module 6
Artificial Intelligence
        │
        ↓
Module 7
Real Medical Imaging Projects

Each module builds on the previous one.

You will move from:

Writing your first Python program

to:

Working with scientific data

to:

Analyzing medical images

to:

Working with DICOM

to:

Developing AI and medical-imaging projects.


From Python Beginner to Medical Imaging Developer

The overall learning philosophy of PyMedLab can be summarized as:

LEARN
  ↓
PRACTICE
  ↓
ANALYZE
  ↓
BUILD
  ↓
APPLY

You first learn a programming concept.

Then you practice it with small examples.

Next, you apply the concept to scientific or medical-imaging data.

Finally, you combine multiple skills to build a practical project.

This approach is designed to help learners move beyond simply writing code and toward using programming to solve meaningful problems.


Key Takeaways

By learning Python, you can develop skills that are useful across modern medical imaging and computational research.

  • Python is widely used in scientific computing, medical imaging research, and artificial intelligence.
  • Libraries such as pydicom make it possible to work with DICOM datasets and metadata.
  • Matplotlib provides tools for visualizing image data and scientific results.
  • CT pixel values can be transformed into appropriate physical units, including HU for applicable original CT images, using DICOM-defined rescale information.
  • Python can support image processing, segmentation, quantitative imaging, radiomics, and machine-learning workflows.
  • AI is increasingly important in medical imaging research, but clinical use requires rigorous validation and appropriate oversight.
  • Learning Python can provide a foundation for developing research tools, analysis workflows, and medical-imaging software.

Python is not the goal. It is the tool.

At PyMedLab, the goal is to use that tool to understand data, analyze medical images, solve problems, and build useful applications.


References

I would use a mixture of official technical standards/documentation and peer-reviewed scientific literature rather than relying only on general programming books.

1. DICOM Standard

Digital Imaging and Communications in Medicine (DICOM). CT Modules, PS3.3. The DICOM Standard.
DICOM Standard — CT Modules

Useful for the technical description of CT image attributes, including Rescale Slope, Rescale Intercept, and Hounsfield Units.

2. pydicom Documentation

pydicom developers. pydicom 3.0.2 Documentation — dcmread().
pydicom — dcmread documentation

Useful for the Python examples showing how DICOM datasets are read.

3. pydicom Dataset Tutorial

pydicom developers. Dataset basics: read, access, modify, write.
pydicom — Dataset Basics

4. Matplotlib Documentation

Matplotlib developers. matplotlib.pyplot.imshow() Documentation.
Matplotlib — imshow documentation

Useful for the medical-image visualization examples.

5. DICOM Standard Overview

Mildenberger, P., Eichelberg, M., and Martin, E. Thirty Years of DICOM: A Review. Journal of Digital Imaging, 2023.

This provides background on DICOM and its role in medical imaging and data exchange.

6. Medical Imaging AI

Barragán-Montero, A., et al. Artificial intelligence and machine learning for medical imaging: A technology review. Physica Medica, 2021;83:242–256.

7. AI in Medical Imaging Practice

Potočnik, J., Foley, S., & Thomas, E. Current and potential applications of artificial intelligence in medical imaging practice: A narrative review. Journal of Medical Imaging and Radiation Sciences, 2023;54(2):376–385.

8. Deep Learning in Radiology

Litjens, G., et al. Deep learning in radiology: an overview of the concepts and a survey of the state of the art.

9. Deep Learning in Medical Imaging and Radiation Therapy

Sahiner, B., et al. Deep learning in medical imaging and radiation therapy. Medical Physics, 2019.

10. Responsible Medical-Imaging AI

Fahad, N., et al. Responsible artificial intelligence in medical imaging: a systematic review. Frontiers in Digital Health, 2026.



Leave a Reply

Your email address will not be published. Required fields are marked *