Imaging Modalities
X-Ray Imaging
| Property |
Value |
| Physics |
X-ray attenuation |
| Resolution |
50-200 μm |
| Acquisition time |
ms |
| Radiation dose |
0.1 mSv (chest) |
| Contrast |
Soft tissue: poor; Bone: excellent |
X-ray Attenuation (Beer-Lambert Law):
I = I₀ · e^(-μx)
Where:
- I = transmitted intensity
- I₀ = incident intensity
- μ = linear attenuation coefficient
- x = path length
Computed Tomography (CT)
| Property |
Value |
| Physics |
X-ray attenuation, fan-beam reconstruction |
| Resolution |
0.5-1 mm |
| Acquisition time |
0.3-2 s |
| Radiation dose |
5-10 mSv (routine) |
| Contrast |
Excellent soft tissue with IV contrast |
class CTReconstruction:
"""Simplified CT reconstruction concepts"""
def filtered_backprojection(self, sinogram, filter_type='ram-lak'):
"""
Analytical reconstruction from projections
Steps: Filter projections → Backproject
"""
# Filter (convolution with reconstruction kernel)
filtered = self.apply_filter(sinogram, filter_type)
# Backprojection
image = self.backproject(filtered)
return image
def iterative_reconstruction(self, projections, iterations=10):
"""
Iterative reconstruction (OS-SART, SIRT)
Advantages: Lower noise, can incorporate priors
"""
estimate = self.initialize_image()
for _ in range(iterations):
# Forward project current estimate
forward_proj = self.forward_project(estimate)
# Calculate correction
error = projections - forward_proj
correction = self.backproject(error)
# Update estimate
estimate += self.relaxation * correction
return estimate
Magnetic Resonance Imaging (MRI)
| Property |
Value |
| Physics |
Nuclear magnetic resonance |
| Resolution |
1-2 mm (clinical), μm (research) |
| Acquisition time |
min (anatomical), hr (functional) |
| Radiation dose |
0 mSv (no ionizing radiation) |
| Contrast |
Excellent soft tissue, multi-parametric |
class MRIContrast:
"""MRI contrast mechanisms"""
T1_WEIGHTING = {
"TR": "Repetition time (short < 1000 ms)",
"TE": "Echo time (short < 30 ms)",
"application": "Anatomy, T1 gadolinium enhancement"
}
T2_WEIGHTING = {
"TR": "Long (> 2000 ms)",
"TE": "Long (> 80 ms)",
"application": "Pathology, edema, fluid"
}
FLAIR = {
"description": "Fluid Attenuated Inversion Recovery",
"suppresses": "CSF signal",
"application": "White matter lesions, tumors"
}
DIFFUSION = {
"sequence": "DWI - echo planar",
"b-values": "0, 500, 1000 s/mm²",
"application": "Stroke (restricted diffusion), tumors"
}
FUNCTIONAL_MRI = {
"technique": "BOLD (Blood Oxygen Level Dependent)",
"principle": "Hemodynamic response to neural activity",
"temporal_resolution": "1-3 seconds",
"spatial_resolution": "2-3 mm"
}
Positron Emission Tomography (PET)
| Property |
Value |
| Physics |
Radioactive decay, annihilation photons |
| Resolution |
4-5 mm |
| Acquisition time |
10-30 min |
| Radiation dose |
2-5 mSv (FDG) |
| Contrast |
Functional/molecular (not anatomical) |
Image Processing
Basic Image Operations
import numpy as np
class MedicalImageProcessing:
"""Medical image processing utilities"""
def normalize_intensity(self, image, method='minmax'):
"""Normalize image intensities"""
if method == 'minmax':
imin, imax = image.min(), image.max()
if imax - imin > 0:
return (image - imin) / (imax - imin)
return image
elif method == 'zscore':
return (image - image.mean()) / image.std()
elif method == 'percentile':
p1, p99 = np.percentile(image, (1, 99))
return np.clip((image - p1) / (p99 - p1), 0, 1)
def gaussian_smoothing(self, image, sigma=1.0):
"""Apply Gaussian smoothing"""
from scipy.ndimage import gaussian_filter
return gaussian_filter(image, sigma)
def intensity_windowing(self, image, window_level):
"""
Window/level adjustment for CT
window: window width (contrast)
level: window center (brightness)
"""
window, level = window_level
lower = level - window / 2
upper = level + window / 2
return np.clip((image - lower) / (upper - lower), 0, 1)
# Common CT window settings
COMMON_WINDOWS = {
"brain": (80, 40),
"soft_tissue": (400, 50),
"lung": (1500, -600),
"bone": (2000, 400),
"liver": (150, 30)
}
Image Segmentation
class SegmentationMethods:
"""Medical image segmentation approaches"""
def threshold_segmentation(self, image, threshold):
"""Simple threshold-based segmentation"""
return (image > threshold).astype(np.uint8)
def otsu_threshold(self, image):
"""Automatic threshold using Otsu's method"""
from scipy import ndimage
# Compute histogram
hist, bins = np.histogram(image.flatten(), bins=256)
# Normalize
hist = hist.astype(float) / hist.sum()
# Find threshold
threshold = 0
max_variance = 0
for t in range(1, 256):
w0 = hist[:t].sum()
w1 = hist[t:].sum()
if w0 == 0 or w1 == 0:
continue
mu0 = np.sum(np.arange(t) * hist[:t]) / w0
mu1 = np.sum(np.arange(t, 256) * hist[t:]) / w1
variance = w0 * w1 * (mu0 - mu1) ** 2
if variance > max_variance:
max_variance = variance
threshold = t
return threshold
def region_growing(self, image, seed, threshold):
"""Region growing segmentation"""
import queue
mask = np.zeros_like(image, dtype=bool)
q = queue.Queue()
q.put(seed)
mask[seed] = True
while not q.empty():
x, y = q.get()
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
nx, ny = x + dx, y + dy
if (0 <= nx < image.shape[0] and
0 <= ny < image.shape[1] and
not mask[nx, ny] and
abs(image[nx, ny] - image[seed]) < threshold):
mask[nx, ny] = True
q.put((nx, ny))
return mask.astype(np.uint8)
Morphological Operations
| Operation |
Effect |
| Erosion |
Shrinks objects, removes small structures |
| Dilation |
Expands objects, fills small holes |
| Opening |
Erosion then dilation, removes small objects |
| Closing |
Dilation then erosion, fills small holes |
Deep Learning in Medical Imaging
Common Network Architectures
class MedicalImageNetworks:
"""Deep learning architectures for medical imaging"""
UNET_ARCHITECTURE = {
"type": "U-Net (encoder-decoder)",
"components": [
"Encoder: contracting path (feature extraction)",
"Bottleneck: lowest resolution features",
"Decoder: expanding path (upsampling)",
"Skip connections: preserve spatial information"
],
"application": "Segmentation (tumors, organs, lesions)",
"input": "2D/3D medical images",
"output": "Probability mask"
}
RESNET_ARCHITECTURE = {
"type": "ResNet (residual networks)",
"key_innovation": "Skip connections (residual blocks)",
"benefit": "Enables training very deep networks",
"application": "Classification, detection",
"variants": ["ResNet-50", "ResNet-101", "ResNet-152"]
}
DETECTION_ARCHITECTURES = {
"two_stage": ["Faster R-CNN", "Mask R-CNN"],
"single_stage": ["YOLO", "SSD", "RetinaNet"],
"application": "Lesion detection, organ localization"
}
Data Augmentation
class MedicalImageAugmentation:
"""Domain-specific augmentations for medical images"""
# Geometric transformations
GEOMETRIC = [
"Random rotation (limited angle)",
"Random scaling",
"Random flipping",
"Elastic deformation (for soft tissue)",
"Random crop/patch extraction"
]
# Intensity transformations
INTENSITY = [
"Random brightness",
"Random contrast",
"Random noise (Gaussian, Poisson)",
"Random gamma correction",
"Histogram equalization"
]
# Medical-specific
MEDICAL_SPECIFIC = [
"Simulate imaging artifacts",
"Motion blur simulation",
"Bias field simulation (MRI)",
"Partial volume simulation",
"Contrast variation (CT, MRI)"
]
Quantitative Imaging
Radiomics Features
| Category |
Features |
| Shape |
Volume, surface area, sphericity, compactness |
| First-order |
Mean, std, skewness, kurtosis, energy, entropy |
| Texture (GLCM) |
Contrast, correlation, energy, homogeneity |
| Texture (GLRLM) |
Run emphasis, gray level emphasis |
| Wavelet |
Decomposed texture at multiple scales |
Biomarkers
| Modality |
Biomarker |
Application |
| CT |
Emphysema percentage |
Lung disease |
| CT |
Lung nodule volume doubling time |
Cancer |
| MRI |
T1/T2 relaxation times |
Tissue characterization |
| PET |
SUVmax, SUVmean |
Tumor FDG uptake |
| DWI |
ADC value |
Stroke, tumors |
| DCE-MRI |
Ktrans, Ve, Vp |
Perfusion, permeability |
Radiation Safety
Dose Metrics
| Metric |
Unit |
Definition |
| Absorbed dose |
Gray (Gy) |
Energy deposited per kg |
| Equivalent dose |
Sievert (Sv) |
Absorbed dose × radiation weighting |
| Effective dose |
Sievert (Sv) |
Equivalent dose × tissue weighting |
Typical Doses
| Study |
Dose (mSv) |
Equivalent background |
| Chest X-ray |
0.1 |
10 days |
| CT Head |
2 |
8 months |
| CT Chest |
7 |
2 years |
| CT Abdomen/Pelvis |
10 |
3 years |
| PET/CT |
25 |
8 years |
| Mammography |
0.4 |
6 weeks |
Common Errors to Avoid
- Ignoring partial volume effects — Small structures appear larger/dimmer
- Inadequate normalization — Batch effects across scanners
- Overfitting deep learning models — Small datasets, heavy augmentation
- Not considering imaging artifacts — Motion, beam hardening, aliasing
- Confusing resolution with pixel spacing — Matrix size vs. physical size
- Ignoring contrast timing — Arterial, venous, delayed phases
- Insufficient training data — Medical imaging needs thousands of samples
- Not validating on external data — Scanner/protocol specific models
1---2name: medical-imaging3description: Imaging Modalities4---56## Imaging Modalities78### X-Ray Imaging910|Property|Value|11|---------|-----|12|Physics|X-ray attenuation|13|Resolution|50-200 μm|14|Acquisition time|ms|15|Radiation dose|0.1 mSv (chest)|16|Contrast|Soft tissue: poor; Bone: excellent|1718```19X-ray Attenuation (Beer-Lambert Law):20I = I₀ · e^(-μx)2122Where:23- I = transmitted intensity24- I₀ = incident intensity25- μ = linear attenuation coefficient26- x = path length27```2829### Computed Tomography (CT)3031|Property|Value|32|---------|-----|33|Physics|X-ray attenuation, fan-beam reconstruction|34|Resolution|0.5-1 mm|35|Acquisition time|0.3-2 s|36|Radiation dose|5-10 mSv (routine)|37|Contrast|Excellent soft tissue with IV contrast|3839```python40class CTReconstruction:41 """Simplified CT reconstruction concepts"""42 43 def filtered_backprojection(self, sinogram, filter_type='ram-lak'):44 """45 Analytical reconstruction from projections46 Steps: Filter projections → Backproject47 """48 # Filter (convolution with reconstruction kernel)49 filtered = self.apply_filter(sinogram, filter_type)50 51 # Backprojection52 image = self.backproject(filtered)53 54 return image55 56 def iterative_reconstruction(self, projections, iterations=10):57 """58 Iterative reconstruction (OS-SART, SIRT)59 Advantages: Lower noise, can incorporate priors60 """61 estimate = self.initialize_image()62 63 for _ in range(iterations):64 # Forward project current estimate65 forward_proj = self.forward_project(estimate)66 67 # Calculate correction68 error = projections - forward_proj69 correction = self.backproject(error)70 71 # Update estimate72 estimate += self.relaxation * correction73 74 return estimate75```7677### Magnetic Resonance Imaging (MRI)7879|Property|Value|80|---------|-----|81|Physics|Nuclear magnetic resonance|82|Resolution|1-2 mm (clinical), μm (research)|83|Acquisition time|min (anatomical), hr (functional)|84|Radiation dose|0 mSv (no ionizing radiation)|85|Contrast|Excellent soft tissue, multi-parametric|8687```python88class MRIContrast:89 """MRI contrast mechanisms"""90 91 T1_WEIGHTING = {92 "TR": "Repetition time (short < 1000 ms)",93 "TE": "Echo time (short < 30 ms)",94 "application": "Anatomy, T1 gadolinium enhancement"95 }96 97 T2_WEIGHTING = {98 "TR": "Long (> 2000 ms)",99 "TE": "Long (> 80 ms)",100 "application": "Pathology, edema, fluid"101 }102 103 FLAIR = {104 "description": "Fluid Attenuated Inversion Recovery",105 "suppresses": "CSF signal",106 "application": "White matter lesions, tumors"107 }108 109 DIFFUSION = {110 "sequence": "DWI - echo planar",111 "b-values": "0, 500, 1000 s/mm²",112 "application": "Stroke (restricted diffusion), tumors"113 }114 115 FUNCTIONAL_MRI = {116 "technique": "BOLD (Blood Oxygen Level Dependent)",117 "principle": "Hemodynamic response to neural activity",118 "temporal_resolution": "1-3 seconds",119 "spatial_resolution": "2-3 mm"120 }121```122123### Positron Emission Tomography (PET)124125|Property|Value|126|---------|-----|127|Physics|Radioactive decay, annihilation photons|128|Resolution|4-5 mm|129|Acquisition time|10-30 min|130|Radiation dose|2-5 mSv (FDG)|131|Contrast|Functional/molecular (not anatomical)|132133---134135## Image Processing136137### Basic Image Operations138139```python140import numpy as np141142class MedicalImageProcessing:143 """Medical image processing utilities"""144 145 def normalize_intensity(self, image, method='minmax'):146 """Normalize image intensities"""147 if method == 'minmax':148 imin, imax = image.min(), image.max()149 if imax - imin > 0:150 return (image - imin) / (imax - imin)151 return image152 153 elif method == 'zscore':154 return (image - image.mean()) / image.std()155 156 elif method == 'percentile':157 p1, p99 = np.percentile(image, (1, 99))158 return np.clip((image - p1) / (p99 - p1), 0, 1)159 160 def gaussian_smoothing(self, image, sigma=1.0):161 """Apply Gaussian smoothing"""162 from scipy.ndimage import gaussian_filter163 return gaussian_filter(image, sigma)164 165 def intensity_windowing(self, image, window_level):166 """167 Window/level adjustment for CT168 window: window width (contrast)169 level: window center (brightness)170 """171 window, level = window_level172 lower = level - window / 2173 upper = level + window / 2174 return np.clip((image - lower) / (upper - lower), 0, 1)175 176 # Common CT window settings177 COMMON_WINDOWS = {178 "brain": (80, 40),179 "soft_tissue": (400, 50),180 "lung": (1500, -600),181 "bone": (2000, 400),182 "liver": (150, 30)183 }184```185186### Image Segmentation187188```python189class SegmentationMethods:190 """Medical image segmentation approaches"""191 192 def threshold_segmentation(self, image, threshold):193 """Simple threshold-based segmentation"""194 return (image > threshold).astype(np.uint8)195 196 def otsu_threshold(self, image):197 """Automatic threshold using Otsu's method"""198 from scipy import ndimage199 200 # Compute histogram201 hist, bins = np.histogram(image.flatten(), bins=256)202 203 # Normalize204 hist = hist.astype(float) / hist.sum()205 206 # Find threshold207 threshold = 0208 max_variance = 0209 210 for t in range(1, 256):211 w0 = hist[:t].sum()212 w1 = hist[t:].sum()213 214 if w0 == 0 or w1 == 0:215 continue216 217 mu0 = np.sum(np.arange(t) * hist[:t]) / w0218 mu1 = np.sum(np.arange(t, 256) * hist[t:]) / w1219 220 variance = w0 * w1 * (mu0 - mu1) ** 2221 222 if variance > max_variance:223 max_variance = variance224 threshold = t225 226 return threshold227 228 def region_growing(self, image, seed, threshold):229 """Region growing segmentation"""230 import queue231 232 mask = np.zeros_like(image, dtype=bool)233 q = queue.Queue()234 q.put(seed)235 mask[seed] = True236 237 while not q.empty():238 x, y = q.get()239 240 for dx in [-1, 0, 1]:241 for dy in [-1, 0, 1]:242 nx, ny = x + dx, y + dy243 244 if (0 <= nx < image.shape[0] and 245 0 <= ny < image.shape[1] and246 not mask[nx, ny] and247 abs(image[nx, ny] - image[seed]) < threshold):248 249 mask[nx, ny] = True250 q.put((nx, ny))251 252 return mask.astype(np.uint8)253```254255### Morphological Operations256257|Operation|Effect|258|----------|------|259|Erosion|Shrinks objects, removes small structures|260|Dilation|Expands objects, fills small holes|261|Opening|Erosion then dilation, removes small objects|262|Closing|Dilation then erosion, fills small holes|263264---265266## Deep Learning in Medical Imaging267268### Common Network Architectures269270```python271class MedicalImageNetworks:272 """Deep learning architectures for medical imaging"""273 274 UNET_ARCHITECTURE = {275 "type": "U-Net (encoder-decoder)",276 "components": [277 "Encoder: contracting path (feature extraction)",278 "Bottleneck: lowest resolution features",279 "Decoder: expanding path (upsampling)",280 "Skip connections: preserve spatial information"281 ],282 "application": "Segmentation (tumors, organs, lesions)",283 "input": "2D/3D medical images",284 "output": "Probability mask"285 }286 287 RESNET_ARCHITECTURE = {288 "type": "ResNet (residual networks)",289 "key_innovation": "Skip connections (residual blocks)",290 "benefit": "Enables training very deep networks",291 "application": "Classification, detection",292 "variants": ["ResNet-50", "ResNet-101", "ResNet-152"]293 }294 295 DETECTION_ARCHITECTURES = {296 "two_stage": ["Faster R-CNN", "Mask R-CNN"],297 "single_stage": ["YOLO", "SSD", "RetinaNet"],298 "application": "Lesion detection, organ localization"299 }300```301302### Data Augmentation303304```python305class MedicalImageAugmentation:306 """Domain-specific augmentations for medical images"""307 308 # Geometric transformations309 GEOMETRIC = [310 "Random rotation (limited angle)",311 "Random scaling",312 "Random flipping",313 "Elastic deformation (for soft tissue)",314 "Random crop/patch extraction"315 ]316 317 # Intensity transformations318 INTENSITY = [319 "Random brightness",320 "Random contrast",321 "Random noise (Gaussian, Poisson)",322 "Random gamma correction",323 "Histogram equalization"324 ]325 326 # Medical-specific327 MEDICAL_SPECIFIC = [328 "Simulate imaging artifacts",329 "Motion blur simulation",330 "Bias field simulation (MRI)",331 "Partial volume simulation",332 "Contrast variation (CT, MRI)"333 ]334```335336---337338## Quantitative Imaging339340### Radiomics Features341342|Category|Features|343|---------|--------|344|Shape|Volume, surface area, sphericity, compactness|345|First-order|Mean, std, skewness, kurtosis, energy, entropy|346|Texture (GLCM)|Contrast, correlation, energy, homogeneity|347|Texture (GLRLM)|Run emphasis, gray level emphasis|348|Wavelet|Decomposed texture at multiple scales|349350### Biomarkers351352|Modality|Biomarker|Application|353|--------|---------|-----------|354|CT|Emphysema percentage|Lung disease|355|CT|Lung nodule volume doubling time|Cancer|356|MRI|T1/T2 relaxation times|Tissue characterization|357|PET|SUVmax, SUVmean|Tumor FDG uptake|358|DWI|ADC value|Stroke, tumors|359|DCE-MRI|Ktrans, Ve, Vp|Perfusion, permeability|360361---362363## Radiation Safety364365### Dose Metrics366367|Metric|Unit|Definition|368|------|-----|----------|369|Absorbed dose|Gray (Gy)|Energy deposited per kg|370|Equivalent dose|Sievert (Sv)|Absorbed dose × radiation weighting|371|Effective dose|Sievert (Sv)|Equivalent dose × tissue weighting|372373### Typical Doses374375|Study|Dose (mSv)|Equivalent background|376|-----|----------|---------------------|377|Chest X-ray|0.1|10 days|378|CT Head|2|8 months|379|CT Chest|7|2 years|380|CT Abdomen/Pelvis|10|3 years|381|PET/CT|25|8 years|382|Mammography|0.4|6 weeks|383384---385386## Common Errors to Avoid3873881. **Ignoring partial volume effects** — Small structures appear larger/dimmer3892. **Inadequate normalization** — Batch effects across scanners3903. **Overfitting deep learning models** — Small datasets, heavy augmentation3914. **Not considering imaging artifacts** — Motion, beam hardening, aliasing3925. **Confusing resolution with pixel spacing** — Matrix size vs. physical size3936. **Ignoring contrast timing** — Arterial, venous, delayed phases3947. **Insufficient training data** — Medical imaging needs thousands of samples3958. **Not validating on external data** — Scanner/protocol specific models396