Professional Documents
Culture Documents
Lecture 2 Merged
Lecture 2 Merged
• 2D and 3D images
• Data format
H06W8a: Medical image analysis • Basic intensity transformations
– Histogram
Class 2: Basic concepts – Window/level
– Maximum intensity projection
– Filtering
Prof. Frederik Maes • Spatial transformations
– Coordinate systems
frederik.maes@esat.kuleuven.be
– Coordinate transformations
– Image resampling
– Image interpolation
2D images 3D images
• 2D matrix of picture elements (= pixels) of size Nc x Nr (= dimensions), e.g. 256 x 256 • 3D matrix of volume elements (= voxels), i.e. a stack of 2D image planes (= slices)
• Pixel size: each pixel ‘covers’ an area in the plane of vc x vr mm2, depending on field of • Image dimensions = Nc x Nr x Np, e.g. 256 x 256 x 160
view (FOV) and dimensions, e.g. FOV = 25cm, Nc = 256 è Vc = 250/256 = 0.97mm • Voxel size: vc x vr x vp (in mm3) depends on FOV and slice distance
• Pixel value: each pixel holds a number which is converted into greyscale value when • Caveat: voxel size >< resolution
displaying the image on screen (“image intensity”, “grey value”) – Voxel size = geometric property vc
• Image data: pixel values stored in 1D array row-by-row (= row-major) or column-by- Plane p vr
– Resolution = physical property v vp
p
column (= column-major, e.g. Matlab)
Nr
...
1st plane 2nd plane last plane
• 3 spatial dimensions + time as 4th dimension (= 3D images at different time points) • 3 spatial dimensions + channel as 4th dimension (e.g. RGB)
• Image dimensions = ncols x nrows x nplanes x ntimepoints • Image dimensions = ncols x nrows x nplanes x nchannels
• Created by acquisition, e.g. multi-slice cine cardiac MR images, 256 x 256 x 10 x 20 • Created by acquisition, e.g. PD and T2-weighted brain images, 256 x 256 x 40 x 2
• Generated by construction, e.g. aligned (= registered and resampled) follow-up images • Generated by construction, e.g. aligned (= registered and resampled) multi-
parametric MRI images
Wattjes, M. P. et al. (2015) MAGNIMS consensus guidelines on the use of MRI in multiple sclerosis—establishing disease prognosis and
monitoring patients, Nat. Rev. Neurol. doi:10.1038/nrneurol.2015.157
Image data indexing: 2D Image data indexing: 3D
• Pixel at column c and row r in image I: I(c,r) (row-major) or I(r,c) (column-major)
• First pixel at index 0 or 1 by convention: I(0,0) (e.g. C++) or I(1,1) (e.g. Matlab) • I(c,r,p) = voxel at column c, row r and plane p in image I
• Index of element (c,r) in the data array: i = c + r*Nc (if row-major, first index = 0) • I(c,r,p) = I(i) with i = c + r*Nc + p*Nc*Nr (if row-major, first index = 0)
• Indexing neighbouring pixels: the index of each neighbour differs by a constant offset • Indexing neighboring voxels:
from that of the central pixel, independently of the position of that pixel in the image Absolute:
• Application: image filtering using local neighbourhood operators (e.g. c-1 c c+1 i1 = I(c-1,r+1,p-1) = (c-1)+(r+1)*Nc+(p-1)*Nc*Nr
convolution) r-1 i2 = I(c+1,r-1,p) = (c+1)+(r-1)*Nc+(p)*Nc*Nr
r
r+1
c Relative to voxel i = I(c,r,p):
c-1 c c+1 c-1 c c+1 p-1 i1 i1 = i + (-1 + Nc - Nc*Nr)
i i2
i2 = i + (1 - Nc)
r-1 i3 r-1 -1-n -n 1-n p in = i + Δc * Oc + Δr * Or + Δp * Op
r (Δc , Δr , Δp = offsets of in relative to i)
r i i2 r -1 0 1 p+1 Neighbour index offsets (row-major):
column direction: Oc = 1
row direction: Or = Nc
r+1 i1 r+1 -1+n n 1+n plane direction: Op = Nc* Nr
Index offsets
3x3 neighbourhood (row-major, n = Nc)
• Numerical values in a computer are represented by a sequence of bytes: NAME REPRESENTATION RANGE
1 byte = sequence of 8 bits = the elementary computer unit, e.g. [10001111]
unsigned char, uint8 1 byte: no sign bit, 8 data bits [0…28-1] = [0…255]
• Decimal numbers are encoded in bytes using base 2 representation:
base 10: digits 0,1,2,3,4,5,6,7,8,9 ➔ 143 = 3 * 100
+4* +1* 101 102 char, int8 1 byte: 1 sign bit + 7 data bits -128,...,127
base 2: digits 0,1 ➔ 10001111 = 1*20+1*21+1*22+1*23+0*24+0*25 +0*26+1*27 = 143
e.g. 143 in base 10 = 10001111 in base 2 unsigned short, uint16 2 bytes: no sign bit, 16 data bits [0…216-1] = [0…65535]
e.g. 3445 in base 10 = 110101110101 in base 2 = [00001101] [01110101] in bytes
signed short, int16 2 bytes: 1 sign bit + 15 data bits -32268, ..., 32267
• Image data is encoded as an array of bytes:
number of bytes = (number of pixels) x (number of bytes per pixel) unsigned integer, uint32 4 bytes: 32 data bits [0…232-1] = [0…4294967295]
e.g. 256x256, 2 bytes per pixel = 256 x 256 x 2 = 131072 bytes = 1048575 bits
signed integer, int16 4 bytes: 1 sign bit + 31 data bits -231,...,231-1
• Number of bytes per pixel depends on the data type:
– Signed / unsigned, integer / floating point data types single precision floating 4 bytes: 1 sign bit, 8 bits exponent, e* = 2-23 = 1.19209289 x 10-7
– Limited number of bits ➔ discretisation ➔ limited floating point precision point (float) 23 bits mantissa
double precison floating 8 bytes: 1 sign bit, 11 bits e* = 2-52 = 2.22044604 x 10-16
point (double) exponent, 52 bits mantissa
* ε = relative accuracy = the distance from 1 to the next largest floating point number
I(0,0,0)
Image “cropping”
c1 c2 I2 = I1(c1:c2,r1:r2,p1:p2)
I2(c,r,p) = I1(c1+c,r1+r,p1+p) (if first index = 0)
r1
r2 Image “downsampling”
p1 I2 = I1(c1:2:c2,r1:2:r2,p1:2:p2) (factor 2x2x2)
Image “upsampling” ?
I2 = I1(c1:0.5:c2,r1:0.5:r2,p1:0.5:p2)
p2 è Requires interpolation !
I(C-1,R-1,P-1)
Orthogonal re-slicing of 3D images Anatomical orientations in 3D images
I(0,0,0) I(0,0,0) I(0,0,0) c
dimensions = C x R x P
r
I(:,:,p) I(:,r,:)
I(c,:,:)
p
Radiological
convention
DICOM standard:
X: right to left (RàL) Plane X-Y = transversal / axial
Y: anterior to posterior (AàP) Plane Y-(—Z) = sagittal
Z: inferior (foot) to posterior (head) Plane X-(—Z) = coronal
(FàH or IàS)
Picture from www.vtk.org
I A R
First index (c or X axis) Second index (r or Y axis) Third index (p or Z axis) R/A R/S A/S
R L Anterior Superior
Native MRI slices acquired with oblique orientation, aligned with the main
cardiac axes (long axis view, short axis view)
Orientation of the image planes can be retrieved from the DICOM header
(origin + direction vectors of column and row axis)
Slice orientation and location Intensity operations
Op P = ImagePositionPatient (DICOM)
Oc,Or = ImageOrientationPatient (DICOM) • Histogram
z2 Op (Oc,Or = unit vectors)
Op = Oc x Or (cross product) • Colormap
P2 (Op = orthogonal to image plane) • Intensity windowing
z1 zi = Pi.Op (dot product)
z1 < z2 è slice 1 more inferior than slice 2 • Intensity thresholding
P1 Sort slices based on z • Intensity filtering
• Linear filtering (‘convolution’)
• Examples:
Origin – median filtering, smoothing, edge detection
Oc
Mediastinum
Maximum intensity projection Maximum intensity projection
R L R L
S S
I I
A P A P
Example: MR angiography of the upper legs Example: MR angiography of the upper legs
First image: before MR contrast agent injection Second image: after MR contrast agent injection ➔ vessels enhanced
stenosis
Orthogonal MIP:
MIP(x,y) = max z I(x,y,z)
Oblique MIP:
MIPa(u,y) = max t I(x,y,z)
x = cos(a).u — sin(a). t
z = sin(a).u + cos(a). t
I
A P
Example: MR angiography of the upper legs
Subtraction image: non-enhancing structures suppressed MIP: maximum intensity along the third dimension
➔ mapping 3D image onto 2D plane
➔ facilitates interpretation of connectivity of 3D structures
r+1 i6 i7 i8 r+1
N(i)
Neighborhood N around pixel i in original image I Filtered image: j = J(c,r) = f(i, ik ∈ N(i))
It1 It2
Filtered
r i4 i0 i5 * w4 w0 w5 r j
j = median(i,i1,i2,i3,…,i8)
E.g.: 3x3 neighborhood filter W filtered image J
Effect: noise suppression
The basic operation in
Deep Learning using CNN!
vy
(x,y)
Y (pixels)
1
(x,y)
2*vy
2 Z
y
y
Y (mm)
(mm) X
Y
(c,r,p start counting from 0,
x,y,z start counting from 0)
Pixel representation: pixel is tile on a plane, voxel is cube in 3D space
Spatial representation: pixel / voxel is centered around point in 2D / 3D space (c,r,p start counting from 0,
x,y,z start counting from 0)
➔ pixel / voxel coordinates = center of each pixel / voxel
(vx,vy,vz = voxel size)
Z
Application: distance measurement 2D coordinate transformation (1)
X
(x0,y0) X’
p1(x1,y1)
p2(x2,y2)
Y
Y’
Y
translation
(move the origin of (x,y) from (0,0)
to (x0,y0))
X’
(x0,0) X (sx.x0,0) X’ X θ
(0,y0) (0,sy.y0)
γ
X
X’ X’
• The 2D affine coordinate transformation from (x,y) to (x’,y’) can be written in matrix
notation:
(‘Euler angles’,
different choices possible)
skew G rotation R scaling S translation T
Linear transformation
• Translation: A = T (x0,y0)
2 parameters in 2D, 3 parameters in 3D θ
• Rigid body transformation: A = T* R
translation & rotation X’
3 parameters in 2D, 6 parameters in 3D Y’
column
A-1 c c+1
p(x’,y’)
p1 p3
r
p(x,y) p(x,y) row
p
r+1
! p2 p4
Solution: use the inverse transformation Problem: p(x,y) in general does not coincide with a pixel position of I
I’(x’,y’) = I(x,y) with p(x,y,1) = A-1 * p(x’,y’,1), ∀(x’,y’ ) ⇒ resampling requires interpolation to determine intensity of p
with A-1 the inverse transformation of A ⇒ spatial transformation implies intensity transformation
➔ run over I’, (inverse) transform (x’,y’) into (x,y), get I(x,y)
p1 p3 p1 p3 p1 p3
A?
(x,y,z) (x’,y’,z’)
(x,y,z) (x,y,z)
x x’
y
z y’
A
(A is 4x3 2D to 3D affine
3D interpolation transformation)
MRA or
(MIP) extracted vessel
(u,v,w) X
crossection
(x1,y1,z1)
Y
(x2,y2,z2)