Spatial transformations

Biomedical Image Analysis in Python

Stephen Bailey

Instructor

OASIS Database

OASIS logo

Biomedical Image Analysis in Python

Significant variability

multi-brain-array

Biomedical Image Analysis in Python

Registration

  • Align images to template
  • Minimize spatial variability

  • Templates:

    • may represent multiple subjects
    • may be an "average" image
  • Entails many spatial transformations

three-images-registering

Biomedical Image Analysis in Python

Affine transformations preserve points, lines, and planes

trasformation-example

Biomedical Image Analysis in Python

Translation

shifted-head

import imageio
import scipy.ndimage as ndi

im=imageio.imread('OAS1036-2d.dcm')
im.shape
(256, 256)
com = ndi.center_of_mass(im)

d0 = 128 - com[0] d1 = 128 - com[1]
xfm = ndi.shift(im, shift=[d0, d1])
Biomedical Image Analysis in Python

Rotation

ndi.rotate(im,
           angle=25,
           axes=(0,1))

rotated-head

Biomedical Image Analysis in Python

Image rotation

xfm = ndi.rotate(im, angle=25)

xfm.shape
(297, 297)

reshaped-rotation

xfm = ndi.rotate(im, angle=25, 
              reshape=False)
xfm.shape
(256, 256)

normal-rotation

Biomedical Image Analysis in Python

Transformation matrix

Transformation matrix: applied to one image for registration.

Elements of the matrix encode "instructions" for different affine transformations.

image-with-four-transforms

Biomedical Image Analysis in Python

Applying a transformation matrix

# Identity matrix
mat = [[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1]]

xfm = ndi.affine_transform(im, mat)

original-image

# Translate and rescale
mat = [[0.8, 0,   -20],
       [0,   0.8, -10],
       [0,   0,   1]]
xfm = ndi.affine_transform(im,
                           mat)

transformed-image

Biomedical Image Analysis in Python

Let's practice!

Biomedical Image Analysis in Python

Preparing Video For Download...