Biomedical Image Analysis in Python
Stephen Bailey
Instructor
Goal: define a metric of similarity between two images.
Cost functions produce metrics to be minimized.
Objective functions produce metrics to be maximized.
import imageio import numpy as np i1=imageio.imread('OAS1035-v1.dcm') i2=imageio.imread('OAS1035-v2.dcm')
err = i1 - i2
plt.imshow(err)
abs_err = np.abs(err) plt.imshow(abs_err)
mae = np.mean(abs_err) mae
29.8570
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
$$ IOU = \frac{I_1 \cap I_2 }{I_1 \cup I_2}$$
mask1 = im1 > 0 mask2 = im2 > 0
intsxn = mask1 & mask2 plt.imshow(intsxn)
union = mask1 | mask2 plt.imshow(union)
iou = intsxn.sum() / union.sum() iou
0.68392
Biomedical Image Analysis in Python