Get Started:
hw3_dicom.pyTwo-Track Structure: This assignment has a Core Track (Parts 1-3) that everyone completes, and an Advanced Track (Part 4) for students who want to dive deeper into radiation therapy data. The Advanced Track is optional but can earn you extra credit.
By completing this assignment, you will:
DICOM (Digital Imaging and Communications in Medicine) is the universal standard for medical imaging. Every CT scan, MRI, X-ray, and most other medical images you’ll encounter in clinical AI are stored as DICOM files.
Understanding DICOM is essential because:
1.1 Reading DICOM Files (10 pts)
Load a CT DICOM file and extract key metadata:
1.2 Understanding DICOM Tags (10 pts)
DICOM uses a tag system (Group, Element) to organize data. For the provided CT file:
1.3 Pixel Data Access (10 pts)
Extract and examine the pixel array:
2.1 Basic Visualization (10 pts)
Display a CT slice using matplotlib:
2.2 Window/Level for Different Tissues (15 pts)
The same CT data looks completely different depending on window/level settings. Create a figure showing the same slice with four different window/level presets:
| Preset | Window Width (W) | Window Level (L) | Use Case |
|---|---|---|---|
| Lung | 1500 | -600 | Lung parenchyma, airways |
| Soft Tissue | 400 | 40 | Abdomen, organs |
| Bone | 2000 | 400 | Skeletal structures |
| Brain | 80 | 40 | Brain parenchyma |
Display all four in a 2x2 subplot figure.
2.3 Custom Window/Level Function (5 pts)
Write a reusable function apply_window_level(image, window, level) that:
3.1 Image Position and Orientation (10 pts)
For medical imaging AI, understanding spatial relationships is critical. Extract and explain:
ImagePositionPatient — Where is the top-left pixel in 3D space?ImageOrientationPatient — How is the image oriented?3.2 Loading a CT Series (15 pts)
A CT scan consists of many slices. Write code to:
SliceLocation or ImagePositionPatient[2])Optional: This section is for students who want to explore radiation therapy data. It covers RT Structure Sets, RT Dose, and DVH calculation. Complete Parts 1-3 first!
4.1 RT Structure Set Basics (8 pts)
RT Structure Sets (RTSTRUCT) contain contoured regions of interest (ROIs) like organs and tumors.
4.2 RT Dose Visualization (8 pts)
RT Dose files contain 3D dose distributions from radiation treatment planning.
jet or hot) with transparency4.3 DVH Calculation (9 pts)
A Dose-Volume Histogram (DVH) is a fundamental tool in radiation oncology, showing what percentage of a structure receives at least a given dose.
hw3_dicom.pygit add hw3_dicom.py
git commit -m "Complete Part 2: window/level visualization"
git push
| Component | Points |
|---|---|
| Part 1: DICOM Basics | 30 |
| 1.1 Reading DICOM files | 10 |
| 1.2 Understanding DICOM tags | 10 |
| 1.3 Pixel data access | 10 |
| Part 2: Visualization | 30 |
| 2.1 Basic visualization | 10 |
| 2.2 Window/level presets | 15 |
| 2.3 Custom W/L function | 5 |
| Part 3: Geometry | 25 |
| 3.1 Position and orientation | 10 |
| 3.2 Loading CT series | 15 |
| Git Workflow | 15 |
| Multiple meaningful commits | 8 |
| Clear commit messages | 7 |
| Core Total | 100 |
| Component | Points |
|---|---|
| 4.1 RT Structure basics | 8 |
| 4.2 RT Dose visualization | 8 |
| 4.3 DVH calculation | 9 |
| Advanced Total | +25 |
Your repository includes sample DICOM data in the data/ directory:
data/ct/ — A small CT series (10-15 slices)data/rt/ — RT Structure and RT Dose files (for Advanced Track)This data is de-identified and safe to use for educational purposes.