Top Banner
Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1
30

Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

May 11, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Lecture 21Working with Diagnostic

Medical Images (in MATLAB)

1

Page 2: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Lecture 21 #goals

••••

••

••

2

Page 3: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Imaging for Medical Diagnostics

•••••

3

Page 4: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Imaging for Medical Diagnostics

4http://xrayphysics.com/ctsim.html

Page 5: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Imaging for Medical Diagnostics

•••••

5

Page 6: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Digital Imaging and Communications in Medicine (DICOM) Standard

•••

••••••

6https://www.dicomstandard.org/current/

Page 7: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

DICOM Standard Images

•••

••

7

Page 8: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Commercial DICOM Software

Many commercial software packages exist for viewing and editing DICOM standard images

• These packages are primarily developed for the medical community (radiologists, general practitioners, patients, etc.)

Examples:• OsiriX for OS X

• free “Lite” version• MicroDicom for Windows

• free viewer

8

Page 9: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

DICOM Images in MATLAB

MATLAB supports DICOM import/export since 2006• Part of the Image Processing Toolbox (optional installation

package)• Reads in DICOM standard files• Writes 3 types of DICOM files (Secondary capture, MRI, CT)

9

DICOM ultrasound “snapshots” plotted in MATLABSource: https://www.mathworks.com/help/images/ref/dicomread.html

Page 10: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

DICOM Images in MATLAB

dicomdisp(filename)

dicominfo(filename)

X = dicomread(filename)

[X, colormap, alpha, overlaps] = dicomread(filename)

dicomwrite(X, filename)

dicomreadVolume

10

Page 11: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

DICOM Images in MATLAB

11

>> x = dicomread('IM-0002-0003.dcm');>> imagesc(x)

>> whos x Name Size Bytes Class Attributes x 512x512 524288 int16

Page 12: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

MATLAB Graphics Properties

12

[X,Y] = meshgrid(-8:.5:8);R = sqrt(X.^2 + Y.^2) + eps;

Z = sin(R)./R;figuremesh(X,Y,Z)

Page 13: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

MATLAB Graphics Objects

13

Page 14: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

>> fh = figure;>> fh.Color = [1 1 1] % set background to white

>> x = plot(randn(1000,1));>> x.LineStyle = ':';>> x.LineWidth = 2;

>> x = get(fh, 'XScale');>> set(fh, 'XScale', 'log')

MATLAB Graphics Objects

14

Page 15: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

MATLAB Graphics Objects

>> x = get(gco, 'XScale');>> set(gcf, 'Position', [1 1 640 480])

15

Page 16: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Data Visualization

16

Page 17: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

x = flow(50);

%% plotting X-Y axisfh = figure;for n = 1:size(x,3)

xslice = x(:,:,n);contourf(xslice);

xlabel('x')ylabel('y')title(sprintf('Slice #%d',n))

pause(0.1)end

17

Page 18: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

x = flow(50);

%% plotting X-Z axisfh = figure;for n = 1:size(x,2)

xslice = squeeze(x(:,n,:));contourf(xslice);

xlabel('x')ylabel('z')title(sprintf('Slice #%d',n))

pause(0.1)end

18

Page 19: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

“slicing” into 3D Matrices

data = flow; % load ‘flow’ dataset

xIdx = 20:40;yIdx = 5:2:end;zIdx = 10:35;

subdata = data(xIdx,yIdx,zIdx);

19

Page 20: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

>> load mri % load built-in MRI data set>> whosName Size Bytes Class AttributesD 128x128x1x27 442368 uint8map 89x3 2136 doublesiz 1x3 24 double

>> D = squeeze(D); % remove 'singleton' dimension>> D(:,1:60,:) = []; % delete half of data about y-axis>> whosName Size Bytes Class AttributesD 128x68x1x27 235008 uint8map 89x3 2136 doublesiz 1x3 24 double

3D Volumetric Data in MATLAB

20

Page 21: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB%% plot volumetric surfaces

% create 'patch' objects for each surfacethresh = 5; % pick a threshold levelp1 = patch(isosurface(D, thresh),'FaceColor','red','EdgeColor','none');p2 = patch(isocaps(D, thresh),'FaceColor','interp','EdgeColor','none');

21

Page 22: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

%% manipulate viewview(3)axis tightdaspect([1,1,.4])

22

Page 23: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB%% modify color and lighting effectscolormap(gray(100))camlight leftcamlightlighting gouraud

23

Page 24: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

%% smooth out isosurface by computing normals from dataisonormals(D,p1)

24

Page 25: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

FV = isosurface(X,Y,Z,V,ISOVALUE) computes isosurface geometry for data V at isosurface value ISOVALUE.

FVC = isocaps(X,Y,Z,V,ISOVALUE) computes isosurface end cap geometry for data V at isosurface value ISOVALUE

N = isonormals(X,Y,Z,V,VERTICES) computes the normals of isosurface vertices VERTICES by using the gradient of the data V.

25

Page 26: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

26

>> [XX,YY,ZZ] = meshgrid(...)

Page 27: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Transformations of 3D Matrices

Translation along x-axis

X = X + deltaX;

Translation along y-axis

Y = Y + deltaY;

Translation along z-axis

Z = Z + deltaZ;

27

Page 28: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

Transformations of 3D Matrices

X = X;

Y = Y*cos(theta) - Z*sin(theta);

Z = Y*sin(theta) + Z*cos(theta);

X = X*cos(theta) + Z*sin(theta);

Y = Y;

Z = Z*cos(theta) - X*sin(theta);

X = X*cos(theta) - Y*sin(theta);

Y = X*sin(theta) + Y*cos(theta);

Z = Z;28

Page 29: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

3D Volumetric Data in MATLAB

29

1)V = zeros(M,N,numel(files));

2)x = dicomread(filename);

3)V(:,:,n) = x;

V(x,y,z)

Page 30: Lecture 21 Working with Diagnostic Medical Images (in MATLAB)cs.brown.edu/courses/cs004/lectures/lec21.pdf · Lecture 21 Working with Diagnostic Medical Images (in MATLAB) 1. Lecture

#puppiesrule

30