Guide to AI and Data Courses · Lecture Notes
Chapter 20: Medical Image Processing
A radiologist sees a nodule on a lung CT scan and wants to know whether it has grown by the scan taken three months later. To answer, she has to outline the nodule, measure its volume and bring the two scans into the same alignment. Medical image processing is the course about these three jobs: displaying the image correctly, separating a structure, and comparing images. These notes introduce the course and show its core ideas with small numbers you can compute by hand.
Learning outcomes
- Pixel values
- Compute the Hounsfield unit from an attenuation coefficient; turn a CT value into a display gray level with a window level and width.
- Segmentation
- Apply region growing step by step on a small image and show how the tolerance changes the result.
- Measurement
- Compute Dice and intersection over union; find a volume from the voxel count and voxel size.
- Registration
- Search for the shift that minimizes a similarity measure; apply a rigid transform to landmarks and find the target registration error.
- Place of the course
- State what separates medical image processing from image processing, computer vision, explainable AI and bioinformatics.
20.1What question does the course ask?
How do X-ray, CT and MRI images help diagnosis and treatment?
Medical image processing enhances, segments, measures and compares X-ray, CT, MRI and ultrasound images to support diagnosis and treatment. It applies image processing and computer vision methods under the constraints of little data, expensive labels and patient safety.
In an ordinary photograph a pixel describes brightness, and changing the brightness a little does not spoil the picture. In a medical image the values carry physical meaning: in CT a pixel tells how strongly the tissue absorbs X-rays, in MRI it reflects the magnetic properties of the tissue. So every operation also asks: does it keep the meaning of the measurement?
The question of the course can be summed up in three steps. First the image is read and displayed correctly (DICOM, windowing). Then the structure of interest, an organ or a tumor, is separated and measured (segmentation). Finally the images of the same patient at different times or from different scanners are placed in the same coordinate system (registration). Success is also measured differently from ordinary image processing: the result is compared with a boundary drawn by a physician and with clinical decision criteria.
20.1.1Pixel or voxel?
CT and MRI give not a single image but a volume made of stacked slices. The smallest element of a volume is the voxel, and a voxel has size in three directions, for example 0.8 × 0.8 × 2.5 mm. The slice thickness is often larger than the in-plane pixel spacing. To find the volume of a structure the voxel count must be multiplied by these dimensions; a measurement made without knowing them comes out wrong.
20.1.2At a glance
| Criterion | Medical Image Processing |
|---|---|
| Approach | image processing plus clinical knowledge |
| Input | CT, MRI, X-ray, ultrasound |
| Output | segmentation, measurement, diagnostic suggestion |
| Success measure | sensitivity, specificity, Dice |
| Math load | medium-high |
| Data needs | little; labels are expensive |
20.2A short history
| Year | Milestone |
|---|---|
| 1895 | Röntgen discovers X-rays; the first medical image is an X-ray of his wife's hand. |
| 1972 | Hounsfield's computed tomography (CT) scanner is introduced: cross-sections are obtained by computation. |
| 1973 | Lauterbur publishes the first imaging paper using magnetic resonance, laying the foundation of MRI. |
| 1993 | The DICOM 3.0 standard is published; devices from different vendors speak the same file format. |
| 2015 | U-Net is published: an encoder-decoder network for segmentation with few labeled medical images. |
| 2018 | The US FDA authorizes IDx-DR, which screens for diabetic retinopathy without a physician. |
20.3Core concepts
The rest of the course is built on the concepts below. The following sections work through the most important ones with examples.
| Concept | Meaning |
|---|---|
| Imaging modalities | X-ray, CT, MRI, ultrasound, PET: each a different physics. |
| DICOM | A standard that carries the image and patient data together. |
| Voxels and volumes | CT and MRI are 3D; voxels instead of pixels. |
| Denoising | Preserving quality in low-dose CT and in MRI. |
| Segmentation | Outlining an organ, tumor or vessel. |
| Registration | Aligning two images (before/after, CT/MRI). |
| Computer-aided diagnosis (CAD) | The computer flags suspicious regions for the physician. |
| Clinical evaluation | Sensitivity, specificity, Dice; comparison with physicians. |
20.4The Hounsfield unit and windowing
A CT scanner measures how much an X-ray beam weakens as it passes through tissue and computes an attenuation coefficient μ for every voxel. This number depends on the scanner and the beam energy, so scanners convert it to a unit scaled against water.
HU = 1000 · (μ − μwater) / μwater. Water is 0 HU and air is about −1000 HU; soft tissue lies between 0 and 100, bone from a few hundred HU upward.
Medical images are stored with 12 bits or more (for example −1024 to 3071, 4096 levels); a display shows 256 gray levels, and the eye cannot tell that many apart anyway. Windowing spreads one range of HU values linearly over 0–255. The range is given by two numbers: the window level L (the center) and the window width W. Everything below L − W/2 becomes black and everything above L + W/2 becomes white: g = 255 · (HU − (L − W/2)) / W (clipped to 0–255).
The attenuation values are illustrative; the coefficient of water is taken as μwater = 0.20 cm−1.
- Fat, μ = 0.18: HU = 1000 · (0.18 − 0.20)/0.20 = −100.
- Soft tissue, μ = 0.208: HU = 1000 · 0.008/0.20 = 40.
- Bone, μ = 0.38: HU = 1000 · 0.18/0.20 = 900.
- Soft-tissue window, L = 40, W = 400: the range is [−160, 240]. For fat, g = 255 · (−100 + 160)/400 ≈ 38; for tissue 255 · 200/400 = 127.5 ≈ 128; for a lesion of 70 HU 255 · 230/400 ≈ 147; bone is above 240, so it is 255 (white).
- Lung window, L = −600, W = 1500: the range is [−1350, 150]. For lung tissue (−800 HU), g = 255 · 550/1500 = 93.5; for soft tissue (40 HU) 255 · 1390/1500 ≈ 236, almost white.
The same 40 HU tissue is mid-gray (128) in one window and almost white (236) in the other. The 140 HU difference between fat and tissue is spread over 89 gray levels in the soft-tissue window but gets only 24 in the lung window. A narrow window magnifies small differences; a wide window keeps very different tissues in one picture.
This is why a radiologist looks at the same slice through lung, soft-tissue and bone windows. A window changes only the display; the data stays at its 12-bit values. For measurement and model training the original HU values or a deliberately chosen window are used.
Saving a windowed 8-bit image and later using it as if it held "HU values". Every value outside the window has been clipped to 0 or 255 and cannot be recovered: in the soft-tissue window above, a material of 300 HU and bone at 900 HU both come out the same white. For measurement the original DICOM values are kept.
20.5Segmentation and the Dice coefficient
Segmentation assigns every voxel to a class; in its simplest form "tumor" or "not tumor". The result is a mask: 1 for the voxels of interest and 0 for the rest. The most intuitive classical method is region growing: the user places a seed inside the tumor; a neighbor of the seed joins the region if its value differs from the seed by at most T, the neighbors of the new members are examined by the same rule, and growing stops when no neighbor is left to join.
A small part of a contrast-enhanced slice (the values are illustrative). The tumor is bright, its surroundings dark:
| 40 | 42 | 45 | 41 | 38 |
| 39 | 85 | 90 | 44 | 40 |
| 41 | 88 | 92 | 87 | 43 |
| 40 | 43 | 86 | 41 | 42 |
| 38 | 40 | 41 | 39 | 40 |
The seed is the central 92, the neighborhood is four-way (up, down, left, right), the tolerance is T = 10: the acceptance range is 82–102.
- The neighbors of the seed are 90 (up), 88 (left), 87 (right) and 86 (down). All four are in range and all join.
- The new neighbors of 90 are 42 (up) and 44 (right); of 88, 41 and 43; of 87, 44, 43 and 41; of 86, 43, 41 and 41. All of them are below 45, nowhere near 82, so none joins. The one exception is the 85 at the upper left, a neighbor of both 90 and 88: it is in range and joins.
- The neighbors of 85 are 42, 39, 88 and 90: nothing new joins, growing stops.
- The region has 6 pixels: 85, 90, 88, 92, 87, 86.
Suppose the expert's mask contains all six of these pixels and also the 44 to the right of the 90, so 7 pixels. The intersection of the two masks is 6 pixels.
Let the two masks be A (algorithm) and B (expert). Dice = 2 |A ∩ B| / (|A| + |B|); IoU = |A ∩ B| / |A ∪ B| (intersection over union). Both run from 0 (no overlap) to 1 (perfect overlap), and they convert into each other by Dice = 2·IoU / (1 + IoU).
In the example |A| = 6, |B| = 7, |A ∩ B| = 6: Dice = 2·6/(6 + 7) = 12/13 ≈ 0.92; the union has 7 pixels, so IoU = 6/7 ≈ 0.86. Volume also comes from the segmentation: with a voxel size of 1 × 1 × 3 mm one voxel is 3 mm³, and 6 voxels make 18 mm³. This is how region volumes are found in radiotherapy, tumor follow-up and brain MRI.
20.5.1Why Dice and not accuracy?
A lesion is a tiny part of the scanned volume. Even a completely empty mask that finds nothing classifies most voxels correctly: its accuracy is high but its Dice is 0. In segmentation, success is therefore reported with measures that look at the lesion itself (Dice, IoU, surface distance).
Expecting a "better" result from a larger tolerance. In the same example, with T = 50 the acceptance range becomes 42–142; surrounding values such as 42, 43, 44 and 45 also join and the region leaks to 12 pixels. Then Dice = 2·6/(12 + 7) ≈ 0.63. The tolerance is tuned to the image; denoising comes first and the result is always compared with the expert mask.
20.6Image registration
Two scans of the same patient are never taken in exactly the same position: the patient may have shifted, rotated or held the breath differently. Registration finds the transform that brings a moving image into the same coordinate system as a fixed one. The transform can be rigid (translation and rotation only) or deformable, which also describes the stretching of tissue. Finding it is an optimization problem: change the transform, measure how similar the two images are with a similarity measure, and keep the transform that makes the measure best.
For images from the same scanner the sum of squared differences (SSD = Σ (fi − mi)2) is used; the transform that makes it smallest is the best one. In different modalities such as CT and MRI the same tissue has a different brightness, so measures based on the information two intensity distributions share (mutual information) are used.
A profile from the fixed image is f = [0, 1, 5, 9, 5, 1, 0, 0] and one from the moving image is m = [0, 0, 0, 1, 5, 9, 5, 1]. The moving profile looks like a copy of the fixed one shifted to the right. We compare fi with mi+s (that is, m is pulled left by s) and compute the mean squared difference only over the points that overlap.
| s | Overlapping points | Sum of squared differences | Mean |
|---|---|---|---|
| 0 | 8 | 180 | 22.5 |
| 1 | 7 | 66 | 9.43 |
| 2 | 6 | 0 | 0 |
| 3 | 5 | 65 | 13 |
| 4 | 4 | 153 | 38.25 |
For s = 0 the differences are 0, −1, 5, 8, 0, −8, −5, −1; their squares sum to 0 + 1 + 25 + 64 + 0 + 64 + 25 + 1 = 180. For s = 2 the two profiles coincide and the difference is zero. So the moving image is shifted 2 pixels to the right, and registration pulls it 2 pixels to the left.
Real registration applies the same logic in three dimensions, with rotations and many parameters. Because trying every transform is impossible, an optimizer such as gradient descent is used. The transform can also be found from landmarks (the same anatomical points marked by hand or automatically in both images). The quality of the result is measured by the target registration error (TRE): the distance between the transformed position of a point that was not used in the registration and its true position.
Assuming that registration is correct because the similarity measure went down. If the two images share little structure, or the measure has several good solutions, the optimizer can stop in the wrong place. The result is checked with TRE on landmarks that were not used in the registration, and by eye.
20.7How is the course taught?
20.7.1A typical workflow
Hundreds of slices from a lung CT scan are read as DICOM, the lung region is segmented and a network flags suspicious nodules. Registered against the previous scan, the growth in nodule volume is measured. The radiologist makes the final call; the system only draws attention.
20.7.2Topics over the semester
- Imaging physics: X-ray, CT, MRI, ultrasound
- DICOM, NIfTI and medical image data
- Image reconstruction: filtered back-projection
- Denoising and image enhancement
- Classical segmentation: thresholds, regions, level sets
- Deep segmentation: U-Net and nnU-Net
- Rigid and deformable registration
- Atlas-based analysis and volumetry
- Classification and computer-aided diagnosis
- Learning from little data: augmentation, transfer
- Clinical validation: Dice, ROC, reader studies
- Regulation, privacy and clinical deployment
This is a typical semester; the order and coverage vary between universities.
20.7.3Skills you will gain
- reading DICOM with pydicom
- annotating images in 3D Slicer
- training segmentation models with MONAI
- registration with SimpleITK
- reporting Dice and ROC results
20.7.4Try it yourself
The Try It: Segment the Tumor in an MRI Slice slide in the presentation lets you solve a typical problem of this course yourself: In a contrast-enhanced brain MRI slice the tumor appears bright; the radiologist wants its volume. Click inside the tumor to place a seed and change the tolerance: does the region cover the tumor or leak into healthy tissue?
20.8Are you ready for this course?
20.8.1Prerequisites
| Course | Why it is needed |
|---|---|
| Image Processing | denoising, segmentation, registration |
| Computer Vision | lesion detection, classification |
| Programming | working with multidimensional arrays in Python |
| Physics | basics of X-ray absorption and magnetic resonance |
| Intro to anatomy and physiology | recognizing organs and how they appear in images |
20.8.2Ask yourself
For every "no", the right-hand column shows where to start. If you can say "yes" to most of them, you are ready.
| Question | If not, start with |
|---|---|
| Can you apply filtering, thresholding and edge detection to an image? | Image Processing |
| Can you explain how a convolutional neural network is trained? | Deep Learning |
| Can you compute and interpret sensitivity and specificity? | Probability and Statistics |
| Can you slice a three-dimensional NumPy array in Python? | An intro programming course, then a short NumPy tutorial |
20.9Neighboring courses
20.9.1Where it overlaps
| Relation | Course | Shared ground |
|---|---|---|
| application | This course applies the methods of Image Processing | denoising, segmentation, registration |
| application | This course applies the methods of Computer Vision | lesion detection, classification |
| shares methods | Shares methods with Explainable AI and AI Ethics | explainability and accountability in diagnosis |
20.9.2Where it differs
- Image Processing: Image processing provides the general methods; this course applies them to 3D medical volumes, with device physics and clinical constraints.
- Computer Vision: Vision works with millions of labeled photos; in medical imaging labels are scarce, need experts, and errors are costly.
- Explainable AI and AI Ethics: The ethics course treats explainability in general; this course uses it for physician trust and accountability.
- Bioinformatics: Bioinformatics looks at sequence and molecular data; medical image processing looks at images of organs and tissue.
20.10In practice
20.10.1Applications
| Area | What is done |
|---|---|
| Radiology | Finding lung nodules and fractures. |
| Oncology | Tumor segmentation, radiotherapy planning. |
| Ophthalmology | Screening retinal images for retinopathy. |
| Neurology | Lesion and volume measurement in brain MRI. |
| Pathology | Counting cells in tissue sections. |
| Surgery | Preoperative 3D models and navigation. |
20.10.2Risks and ethics
| Risk | Explanation |
|---|---|
| Shortcut learning | A model can learn scanner labels or hospital markers instead of disease; this has been shown in chest X-ray models. |
| Failure at another hospital | Performance drops with other scanners, protocols and patients; validation at a single site is not enough. |
| Re-identification | DICOM headers hold identifiers and faces can be rebuilt from head MRI; anonymization is more than deleting a name. |
| Automation bias | Clinicians may miss a lesion the model did not flag; a support tool can loosen human scrutiny. |
These issues are discussed in depth in Explainable AI and AI Ethics.
20.10.3Tools and datasets
Tools: 3D Slicer, ITK / SimpleITK, MONAI, nnU-Net, pydicom, NiBabel, ITK-SNAP.
Well-known datasets: BraTS (brain tumor), LIDC-IDRI (lung CT), ChestX-ray14, CheXpert, Medical Segmentation Decathlon.
Medical datasets are personal health data: they cannot be shared without anonymization, ethics board approval and a data use agreement.
20.11Common misconceptions
AI will soon replace radiologists.
Systems support narrow tasks; diagnosis, context and responsibility stay with the physician.
High accuracy means clinical success.
For rare diseases sensitivity and specificity matter; performance may drop at another hospital.
A medical image is an ordinary photo.
CT and MRI are often 3D, and pixel values carry physical meaning (Hounsfield units).
Collecting lots of data is easy.
Labels take expert time, and the data is protected by privacy law.
20.12Summary
- Pixel values in medical images carry physical meaning; CT values are given in Hounsfield units, scaled against water, and the element of a volume is the voxel.
- Windowing spreads a range of HU over 0–255 and changes only the display; the window level and width decide which tissue is visible, and the original data must be kept.
- Segmentation assigns classes to voxels; in region growing the tolerance decides the result directly. A volume is the voxel count times the voxel size.
- Segmentation is measured against an expert mask with Dice or IoU; accuracy alone is not used because it misleads for small lesions.
- Registration searches for the transform that makes a similarity measure best; success is checked with the target registration error on landmarks that were not used.
20.13Test Yourself
The attenuation coefficient of water is 0.20 and that of a material is 0.30 cm−1. What is the material's HU value? Compute it also for a material (air-like) with coefficient 0.12.
Answer
HU = 1000 · (0.30 − 0.20)/0.20 = 500. For the second material 1000 · (0.12 − 0.20)/0.20 = −400. A coefficient smaller than water's gives a negative HU.
In the soft-tissue window (L = 40, W = 400), what gray levels do voxels of 140, 300 and −200 HU get?
Answer
The range is [−160, 240]. For 140: 255 · 300/400 = 191.25 ≈ 191. 300 is above 240, so it is 255. −200 is below −160, so it is 0.
The algorithm's mask has 50 voxels, the expert's has 60, and they overlap on 40 voxels. What are Dice and IoU?
Answer
Dice = 2·40/(50 + 60) = 80/110 ≈ 0.73. The union is 50 + 60 − 40 = 70, IoU = 40/70 ≈ 0.57.
In a CT with a voxel size of 0.8 × 0.8 × 2.5 mm, a segmented organ has 12 500 voxels. What is its volume in mL? (1 mL = 1000 mm³)
Answer
One voxel is 0.8 · 0.8 · 2.5 = 1.6 mm³. The volume is 12 500 · 1.6 = 20 000 mm³ = 20 mL. Forgetting the slice thickness (2.5) and multiplying by 0.64 only would give a result about 4 times too small.
In the fixed image two landmarks are A′ = (1, 1) and B′ = (−1, 2); in the moving image they are A = (2, 0) and B = (2, 2). The moving points are first rotated by 90° counterclockwise, (x, y) → (−y, x), then translated by (1, −1). Where do the points end up, and what is the error for B?
Answer
A: rotation gives (0, 2), translation (1, 1); it coincides with A′ (error 0). B: rotation gives (−2, 2), translation (−1, 1); since B′ = (−1, 2) the difference is (0, −1), an error of 1 unit.
A CT volume has 1 000 000 voxels and the lesion has 100. What are the accuracy and the Dice of an empty mask that finds nothing? What does this show?
Answer
999 900 voxels are classified correctly: accuracy 999 900/1 000 000 = 99.99%. The intersection is 0, so Dice = 0. Because the lesion is a tiny part of the volume, accuracy does not show segmentation success; measures that look at the lesion, such as Dice, are used.
20.14After this course
Medical image processing is the most tightly regulated application of image processing and computer vision. From here you can move on to segmentation with deep learning, to clinical trust with explainable AI, or to the molecular level with bioinformatics.
Related careers: Medical imaging engineer, Biomedical software developer, Clinical AI researcher, Medical device regulatory specialist.
20.15Further reading
- P. Suetens, Fundamentals of Medical Imaging (3rd ed., 2017): explains the physics of X-ray, CT, MRI and ultrasound and how the image is formed.
- I. Bankman (ed.), Handbook of Medical Image Processing and Analysis (2nd ed., 2008): a broad reference covering segmentation, registration and quantification methods chapter by chapter.
- G. Litjens et al., "A Survey on Deep Learning in Medical Image Analysis", Medical Image Analysis 42 (2017): reviews deep learning applications in medical image classification, segmentation and registration.
20.16References
- Suetens, Fundamentals of Medical Imaging, 3rd ed., Cambridge University Press, 2017.
- Bankman (ed.), Handbook of Medical Image Processing and Analysis, 2nd ed., Academic Press, 2008.
- Ronneberger, Fischer and Brox, "U-Net: Convolutional Networks for Biomedical Image Segmentation", MICCAI, 2015.
- Litjens et al., "A Survey on Deep Learning in Medical Image Analysis", Medical Image Analysis 42, 2017.
Related pages: Slides · Slides (PDF) · Course page