Comparing images

Biomedical Image Analysis in Python

Stephen Bailey

Instructor

Comparing images

both-images-and-stacked

Biomedical Image Analysis in Python

Summary metrics

Goal: define a metric of similarity between two images.

Cost functions produce metrics to be minimized.

Objective functions produce metrics to be maximized.

Biomedical Image Analysis in Python

Mean absolute error

import imageio
import numpy as np
i1=imageio.imread('OAS1035-v1.dcm')
i2=imageio.imread('OAS1035-v2.dcm')

err = i1 - i2
plt.imshow(err)

mask-error

abs_err = np.abs(err)
plt.imshow(abs_err)

mae = np.mean(abs_err) mae
29.8570

mask-abs-error

Biomedical Image Analysis in Python

Mean absolute error

Goal: minimize the cost function

# Improve im1 alignment to im2
xfm=ndi.shift(im1, shift=(-8, -8))
xfm=ndi.rotate(xfm, -18,
                 reshape=False)

# Calculate cost abs_err = np.abs(im1 - im2) mean_abs_err = np.mean(abs_err)
mean_abs_err
13.0376

adjusted-overlay

Biomedical Image Analysis in Python

Intersection of the union

$$ IOU = \frac{I_1 \cap I_2 }{I_1 \cup I_2}$$

mask1 = im1 > 0
mask2 = im2 > 0

intsxn = mask1 & mask2 plt.imshow(intsxn)

mask-intersection

union = mask1 | mask2
plt.imshow(union)

iou = intsxn.sum() / union.sum() iou
0.68392

mask-union

Biomedical Image Analysis in Python

Let's practice!

Biomedical Image Analysis in Python

Preparing Video For Download...