Image Data Stephen Bailey Instructor DataCamp Biomedical Image - - PowerPoint PPT Presentation

image data
SMART_READER_LITE
LIVE PREVIEW

Image Data Stephen Bailey Instructor DataCamp Biomedical Image - - PowerPoint PPT Presentation

DataCamp Biomedical Image Analysis in Python BIOMEDICAL IMAGE ANALYSIS IN PYTHON Image Data Stephen Bailey Instructor DataCamp Biomedical Image Analysis in Python Biomedical imaging: more than a century of discovery 1895 2017 DataCamp


slide-1
SLIDE 1

DataCamp Biomedical Image Analysis in Python

Image Data

BIOMEDICAL IMAGE ANALYSIS IN PYTHON

Stephen Bailey

Instructor

slide-2
SLIDE 2

DataCamp Biomedical Image Analysis in Python

Biomedical imaging: more than a century of discovery

1895 2017

slide-3
SLIDE 3

DataCamp Biomedical Image Analysis in Python

Course objectives

Toolbox ImageIO NumPy SciPy matplotlib

slide-4
SLIDE 4

DataCamp Biomedical Image Analysis in Python

Loading images

imageio: read and save images Image objects are NumPy arrays.

Slice the array by specifying values along each available dimension.

import imageio im = imageio.imread('body-001.dcm') type(im) imageio.core.Image im Image([[125, 135, ..., 110], [100, 130, ..., 100], ..., [100, 150, ..., 100]], dtype=uint8) im[0, 0] 125 im[0:2, 0:2] Image([[125, 135], [100, 130]], dtype=uint8)

slide-5
SLIDE 5

DataCamp Biomedical Image Analysis in Python

Metadata

Metadata: the who, what, when, where and how of image acquisition Accessible in Image objects through the meta dictionary attribute

im.meta Dict([('StudyDate', '2017-01-01'), ('Modality', 'MR'), ('PatientSex', F), ... ('shape', (256, 256)]) im.meta['Modality'] 'CT' im.meta.keys()

  • dict_keys(['StudyDate',

'SeriesDate', 'PatientSex', ... 'shape'])

slide-6
SLIDE 6

DataCamp Biomedical Image Analysis in Python

Plotting images

Matplotlib's imshow() function displays 2D image data Many colormaps available but often shown in grayscale (cmap='gray') Axis ticks and labels are often not useful for images

import matplotlib.pyplot as plt plt.imshow(im, cmap='gray') plt.axis('off') plt.show()

slide-7
SLIDE 7

DataCamp Biomedical Image Analysis in Python

Let's practice!

BIOMEDICAL IMAGE ANALYSIS IN PYTHON

slide-8
SLIDE 8

DataCamp Biomedical Image Analysis in Python

N-dimensional images

BIOMEDICAL IMAGE ANALYSIS IN PYTHON

Stephen Bailey

Instructor

slide-9
SLIDE 9

DataCamp Biomedical Image Analysis in Python

Images of all shapes and sizes

im[row, col]

slide-10
SLIDE 10

DataCamp Biomedical Image Analysis in Python

Images of all shapes and sizes

vol[pln, row, col]

slide-11
SLIDE 11

DataCamp Biomedical Image Analysis in Python

Images of all shapes and sizes

im[row, col, ch]

slide-12
SLIDE 12

DataCamp Biomedical Image Analysis in Python

Images of all shapes and sizes

im_ts[time, row, col, ch]

slide-13
SLIDE 13

DataCamp Biomedical Image Analysis in Python

N-dimensional images are stacks of arrays

import imageio import numpy as np im1=imageio.imread('chest-000.dcm') im2=imageio.imread('chest-001.dcm') im3=imageio.imread('chest-002.dcm') im1.shape (512, 512) vol = np.stack([im1, im2, im3]) vol.shape (3, 512, 512)

slide-14
SLIDE 14

DataCamp Biomedical Image Analysis in Python

Loading volumes directly

imageio.volread():

read multi-dimensional data directly assemble a volume from multiple images

import os

  • s.listdir('chest-data')

['chest-000.dcm', 'chest-001.dcm', 'chest-002.dcm', ..., 'chest-049.dcm'] import imageio vol = imageio.volread('chest-data') vol.shape (50, 512, 512)

slide-15
SLIDE 15

DataCamp Biomedical Image Analysis in Python

Shape, sampling, and field of view

Image shape: number of elements along each axis Sampling rate: physical space covered by each element Field of view: physical space covered along each axis

import imageio vol = imageio.volread('chest-data') # Image shape (in voxels) n0, n1, n2 = vol.shape n0, n1, n2 (50, 512, 512) # Sampling rate (in mm) d0, d1, d2 = vol.meta['sampling'] d0, d1, d2 (2, 0.5, 0.5) # Field of view (in mm) n0 * d0, n1 * d1, n2 * d2 (100, 256, 256)

slide-16
SLIDE 16

DataCamp Biomedical Image Analysis in Python

Let's practice!

BIOMEDICAL IMAGE ANALYSIS IN PYTHON

slide-17
SLIDE 17

DataCamp Biomedical Image Analysis in Python

Advanced plotting

BIOMEDICAL IMAGE ANALYSIS IN PYTHON

Stephen Bailey

Instructor

slide-18
SLIDE 18

DataCamp Biomedical Image Analysis in Python

To plot N-dimensional data slice it!

slide-19
SLIDE 19

DataCamp Biomedical Image Analysis in Python

Plotting multiple images at once

plt.subplots: creates a figure canvas

with multiple AxesSubplots objects.

import imageio vol = imageio.volread('chest-data') fig, axes = plt.subplots(nrows=1, ncols=3) axes[0].imshow(vol[0],cmap='gray') axes[1].imshow(vol[10],cmap='gray') axes[2].imshow(vol[20],cmap='gray') for ax in axes: ax.axis('off') plt.show()

slide-20
SLIDE 20

DataCamp Biomedical Image Analysis in Python

Plotting multiple images at once

slide-21
SLIDE 21

DataCamp Biomedical Image Analysis in Python

Non-standard views

Axial

import imageio vol = imageio.volread('chest-data') view_1v2 = vol[pln, :, :] view_1v2 = vol[pln]

slide-22
SLIDE 22

DataCamp Biomedical Image Analysis in Python

Non-standard views

Coronal

import imageio vol = imageio.volread('chest-data') view_1v2 = vol[pln, :, :] view_1v2 = vol[pln] view_0v2 = vol[:, row, :]

slide-23
SLIDE 23

DataCamp Biomedical Image Analysis in Python

Non-standard views

Sagittal

import imageio vol = imageio.volread('chest-data') view_1v2 = vol[pln, :, :] view_1v2 = vol[pln] view_0v2 = vol[:, row, :] view_0v1 = vol[:, :, col]

slide-24
SLIDE 24

DataCamp Biomedical Image Analysis in Python

Modifying the aspect ratio

Pixels may adopt any aspect ratio:

im = vol[:,:,100] d0, d1, d2 = vol.meta['sampling'] d0, d1, d2 (2, 0.5, 0.5) asp = d0 / d1 asp 3 plt.imshow(im, cmap='gray', aspect=asp) plt.show()

slide-25
SLIDE 25

DataCamp Biomedical Image Analysis in Python

Modifying the aspect ratio

slide-26
SLIDE 26

DataCamp Biomedical Image Analysis in Python

Let's practice!

BIOMEDICAL IMAGE ANALYSIS IN PYTHON