Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by:...
-
Upload
domenic-stevenson -
Category
Documents
-
view
215 -
download
0
Transcript of Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by:...
![Page 1: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/1.jpg)
Computers in Medicine
Bone visualization and analyses - An introduction to Matlab -
Presented by: Kathryn Stok
ETH Zurich
Prepared by: Steven Boyd
University of Calgary
![Page 2: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/2.jpg)
Objectives (I)
Provide an overview of Matlab– What is Matlab?– Basic commands– Accessing online help– Writing M-files– Programming style– Create plots
![Page 3: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/3.jpg)
Objectives (II)
Work through examples– Reading an image file– Probe the data– Filtering– Create a histogram– Thresholding– Counting voxels– Calculating 2nd moment of area
![Page 4: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/4.jpg)
Why bone visualization?
Carries the body→ it should be strong
But in many cases, bone strength is impaired.– congenital deformities– osteoporosis– fracture– fatigue (stress fracture)
![Page 5: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/5.jpg)
Bone architecture
![Page 6: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/6.jpg)
Bone structure – femoral head
Young Normal Osteoporotic
![Page 7: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/7.jpg)
Bone structure – lumbar spine
Young Normal Osteoporotic
![Page 8: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/8.jpg)
Why bone visualization?
Bone (structure) analyses and visualization are of great importance in – Diagnosis– Treatment– Prevention
![Page 9: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/9.jpg)
Why Matlab?
High-performance language for technical computing.– Matrix Laboratory
Advantages– Easy to use:
– No dimensioning required.– No compiling– Good for prototyping, testing
– Functionality is greatly expanded by toolboxes. – Many fields of application.
Disadvantages:– Uses much memory (slow for large applications)– Not good for final software design
![Page 10: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/10.jpg)
What is matlab?
Matlab language– matrix/array language– control flow (if, for, while)– functions
Working environment– workspace for computing, importing, and
exporting data– text editor for creating M-files
![Page 11: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/11.jpg)
This Matlab course
It covers: • Using the development environment.• Syntax of the language. • Basic matrix operations. • Basic graphics features. • Writing Matlab scripts and functions (m-files)
It does not cover: • Any of the toolboxes including Simulink. • c-mex and f-mex files, Matlab compilers.
![Page 12: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/12.jpg)
Possibilities…
Develop tools for:– Image processing and basic analysis.– Visualization: 2D and 3D.– Simulation: Simulate bone loss.
![Page 13: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/13.jpg)
Matlab Environment
![Page 14: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/14.jpg)
Matrices
Albrecht Dürer
Magic square
![Page 15: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/15.jpg)
Matrices
semicolon
Entering matrices– explicitly
![Page 16: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/16.jpg)
Matrices
Sum, transpose
![Page 17: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/17.jpg)
Matrices
Diagonal (diag)
![Page 18: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/18.jpg)
Matrices
Subscripts: A(i,j)
row column
![Page 19: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/19.jpg)
Matrices
Colon operator ' : '
![Page 20: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/20.jpg)
Matrices
Colon operator ' : '
Matlab is 1-based
![Page 21: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/21.jpg)
Matrix multiplication ( * )
![Page 22: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/22.jpg)
Matrix multiplication ( .* )
![Page 23: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/23.jpg)
Variables
Scalar, vector, matrix
![Page 24: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/24.jpg)
Variables
Check workspace– command line– window
![Page 25: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/25.jpg)
Numbers
Integer
Real
Exponential
Imaginary
-3
0.0001
1.60210e-20
5 + 2i
![Page 26: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/26.jpg)
Operators: Arithmetic
+ Addition - Subtraction * Multiplication (or .* element-wise) / Division ^ Power (or .^ element-wise) ' Transpose () Brackets for evaluation order
A = [ 4 1 3]A.^2 = [16 1 9]A.*2 = [ 8 2 6]
A '* A 16 4 124 1 312 3 9
![Page 27: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/27.jpg)
Operators: Relational
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
~= Not equal to
![Page 28: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/28.jpg)
Operators: Logical
& AND
| OR
~ NOT
Type help ops to see: the arithmetic,relational and logical functions.
![Page 29: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/29.jpg)
Matrices
Entering matrices– explicitly– load from external file– your own M-files– built-in function
Albrecht Dürer
![Page 30: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/30.jpg)
Generating matrices
Loaddata file
![Page 31: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/31.jpg)
Generating matrices
M-files
![Page 32: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/32.jpg)
Generating matrices
Built-in functions
![Page 33: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/33.jpg)
Help
Help Window– pop-up window
Type help
![Page 34: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/34.jpg)
Online help
![Page 35: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/35.jpg)
Online help
![Page 36: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/36.jpg)
Online help
![Page 37: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/37.jpg)
Useful commands
(up arrow)– recall previous command– p recalls previous command starting with ‘p’
clear– clear workspace– clear A Z Q clears only A, Z, and Q.
size– size(A) returns size of matrix A
![Page 38: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/38.jpg)
Multidimensional matrices
page k,Z
rowi, X
column j, Y
![Page 39: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/39.jpg)
Multidimensional matrices
Generate a 3D array manually
![Page 40: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/40.jpg)
Advanced indexing
Matrices are always stored as columns– subscripts (i,j,k)– array dimension [d1 d2 d3]
– if A is of dimension 3 x 3 x 3 then A(3,3,3) = A(27) = 8
3 2 7 5 1 1 4 6 8 6 2 6 1 4 9 3 6 7 5 6 7 9 5 6 1 2 8
3 5 4 2 1 6 7 1 8
3 5 4 2 1 6 7 1 8
6 1 3 2 4 6 6 9 7
6 1 3 2 4 6 6 9 7
5 9 1 6 5 2 7 6 8
5 9 1 6 5 2 7 6 8
ij
k
![Page 41: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/41.jpg)
Characters and Text
s = 'myimage'– 7 character array (string)
num2str() - convert a number to string
![Page 42: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/42.jpg)
User input
Keyboard inputa_number = input('Enter number');a_string = input('Enter filename', 's');
[filename,path] = uigetfile('*.*');
Using GUI
![Page 43: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/43.jpg)
Graphics: plot
![Page 44: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/44.jpg)
Graphics: plot(s)
‘hold on’allows more plots to be added
![Page 45: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/45.jpg)
Graphics: contours
![Page 46: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/46.jpg)
Graphics: subplots
![Page 47: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/47.jpg)
Graphics: labels and titles
![Page 48: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/48.jpg)
Graphics: labels and titles
… or use the Figure window !
![Page 49: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/49.jpg)
Graphics: mesh
![Page 50: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/50.jpg)
Flow control
if, else, and elseif
switch
while
for
![Page 51: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/51.jpg)
if, else, and elseif
if logical_expression statementsend
if (rem(a,2) == 0) disp(‘a is even’)end
if (n<0) disp(‘Input must be positive’)elseif (rem(n,2) == 0) disp(‘a is even’)else disp(‘a is odd’)end
![Page 52: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/52.jpg)
switch
switch expression case value1 statements case value2 statements otherwise statementsend
switch (input_num) case (-1) disp(‘negative one’) case (0) disp(‘zero’) case (1) disp(‘positive one’) otherwise disp(‘othervalue’)end
![Page 53: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/53.jpg)
while, for
while expression statementsend
n = 1;while (prod(1:n) < 1e10) n = n + 1;end
for index = start:inc:end statementsend
for i = 2:6 x(i) = 2*x(i-1);end
for i = 1:m for j = 1:n A(i,j) = 1/(i + j - 1); endend
![Page 54: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/54.jpg)
Vectorization
Efficiency!– Example: Table of logarithms
–Find log10 of numbers between 0 and 10.
x = 0;for k = 1:1001 y(k) = log10(x); x = x + 0.01;end
x = 0:0.01:10;y = log10(x);
Looped code Vectorized code
AVOID LOOPS!
![Page 55: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/55.jpg)
Scripts and functions
Scripts– No input arguments nor
output arguments.
– Operate on data in the workspace
– Useful for automating a series of steps that will be performed many times
Functions– Can accept input
arguments and return output arguments
– Variables are local to the function
– Useful for extending the MATLAB language beyond the built-in functions
![Page 56: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/56.jpg)
Script example
Comment lines
Computations
Graphicsoutput
Create m-files:– type edit – use the interface
![Page 57: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/57.jpg)
Script example
Hit return to advance plot
![Page 58: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/58.jpg)
Script Example
![Page 59: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/59.jpg)
Function example
Function definition
Help comments
Error check
Calculations
function [y] = average(x)
keyword
output argumentfunction name
input argument
![Page 60: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/60.jpg)
Function example
semi-colon
![Page 61: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/61.jpg)
M-files
Tips:– use descriptive variable names
–e.g. number_students = 20– functions end with “_fcn”
–e.g. an_example_fcn(number_students)– indent if, for, while statements 3-4 spaces– add comments using ‘%’– develop with smaller portions of data– debug by pasting line-by-line from M-file
![Page 62: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/62.jpg)
Online tutorial
http://www.imrtweb.ethz.ch/matlab/
Or google “mathworks tutorial”
Fundamentals
Exercises
Examples
![Page 63: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/63.jpg)
Part II: Practical Programming
Image analysis on 2D section– Read image data (micro-CT)– Plot the image– Examine image– Filter the image– Create a histogram– Threshold (distinguish between bone and marrow)
– Calculate porosity– Centroid, principal axes
![Page 64: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/64.jpg)
Read 2D Image
Want to import the image from micro-CT
Write a program to:– clear workspace– set filename– load file
– Image data to visualize:/Phalanx/hp2d_34-95_380.bmp
![Page 65: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/65.jpg)
Set up main program (a script file)
comments
clear workspace
close all figure windows
file to load
load it
Note: You need to write the 2D image reading function.
![Page 66: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/66.jpg)
Read in 2D image
Read the file
Convert data
![Page 67: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/67.jpg)
Display input data
![Page 68: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/68.jpg)
Display input data
![Page 69: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/69.jpg)
Display input data
![Page 70: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/70.jpg)
Examine image
min, max, mean
![Page 71: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/71.jpg)
Examine image
min, max, mean
![Page 72: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/72.jpg)
Image Processing
Filter
Thresholding– histogram
Porosity = 1 - (bone area / total area)
Moment of area– First moment of area– Centroid– Second moment of area
![Page 73: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/73.jpg)
Filtering – example 1
![Page 74: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/74.jpg)
Filtering – example 2
filtered original image filtered noisy image
original image noisy image
![Page 75: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/75.jpg)
Filtering the data
Apply Gaussian filtration– Shape of filter depends on:
window size [n1 n2] and
![Page 76: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/76.jpg)
Filtering
Window = 3 = 1.2
Filter
![Page 77: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/77.jpg)
Filtering
Window = 5 = 1.2
Filter
![Page 78: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/78.jpg)
Filtering
Window = 15 = 1.2
Filter
![Page 79: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/79.jpg)
Filtering
Window = 15 = 7
Filter
![Page 80: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/80.jpg)
Filtering
Window = 15 = 100
Filter
![Page 81: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/81.jpg)
Filtering: Convolution
zyx fff
![Page 82: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/82.jpg)
Filtering: Edge Effects
edge data nulled
• Important to begin with image dimensions large enough to account for edge effects
![Page 83: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/83.jpg)
Filtering
Use built-in functions:– fspecial– imfilter– (smooth3)
![Page 84: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/84.jpg)
Thresholding
• Good to try different thresholds to see the effect.
Segmentation of bone– divides bone from other tissue
![Page 85: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/85.jpg)
Thresholding
threshold2D = zeros matrixFind all indices (i,j) where element(i,j) > threshold threshold2D(i,j) = 1
![Page 86: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/86.jpg)
Thresholding
![Page 87: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/87.jpg)
Thresholding
Threshold = 90 Threshold = 120
![Page 88: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/88.jpg)
Histogram
– lookfor and help
![Page 89: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/89.jpg)
Histogram
hist works on vectors, not 2D matrices– need reshape function to vectorize
![Page 90: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/90.jpg)
Porosity
Porosity = 1 - (Bone volume divided by total volume)
Need total bone volume (area)– Create mask:
– filter image to remove holes– threshold filtered image
– Count total “mask” pixels– Count total “bone” pixels
within mask
![Page 91: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/91.jpg)
Porosity
Create mask:
original image
filtered image
threshold filtered image
Image 3 super-imposedon image 1
1 2 3
![Page 92: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/92.jpg)
Porosity
Porosity = 1 -Mask pixels
Bone pixels within mask
Thresholded image (bone)
Mask image
Image of bone within the mask
![Page 93: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/93.jpg)
Image analysis – determine porosity
Original
Segmenting the boneFiltered Thresholded
Creating the maskFiltered Thresholded
Find bone within mask
Porosity = 1 - Areabone
Areamask
![Page 94: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/94.jpg)
Erosion, dilation
Erode Erode = 2 Erode = 4
Dilate Dilate = 2 Dilate = 4
![Page 95: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/95.jpg)
Part of MAIN program
![Page 96: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/96.jpg)
Stress in Pure Bending
Mechanical stiffness– First moment of area– Centroid of area– Second moment of area
![Page 97: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/97.jpg)
First moment of an area
First moment of area with respect to the X axis:
First moment of area with respect to the Y axis:
Can be positive, negative, or zero depending on the axis location
(mm3)
(mm3)
![Page 98: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/98.jpg)
Centroid of an area
Centroid of area defined as:
Knowing the first moment:
![Page 99: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/99.jpg)
First moment of area
![Page 100: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/100.jpg)
Second moment of area
Stress resulting from bending: σ = My/I
Resistance against bending.– Take Ix, Iy, Ixy about centroid C
– Or use the parallel axis theorem: Ix = Ixc + Ad2
![Page 101: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/101.jpg)
Second moment of area - rotation
Transformation of 2nd moments:
![Page 102: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/102.jpg)
Second moment of area - principal axes
Two values of for which Ixy = 0.
Can calculate the max/min 2nd moments:
maximum associatedwith Ix
minimum associatedwith Iy
![Page 103: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/103.jpg)
Principal axes & Transformation
![Page 104: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/104.jpg)
2D: Pompe Disease
Radius Tibia
![Page 105: Computers in Medicine Bone visualization and analyses - An introduction to Matlab - Presented by: Kathryn Stok ETH Zurich kas@ethz.ch Prepared by: Steven.](https://reader035.fdocuments.us/reader035/viewer/2022062500/56649e685503460f94b639eb/html5/thumbnails/105.jpg)
Mouse knees
NTRTCTRL