Matlab and Medical Image Analysis basics / Human Image Perception Kostas Marias... What is MATLAB?• MATLAB is a tool for doing numerical computations with matrices and vectors.. Matl
Trang 1Matlab and Medical Image
Analysis basics / Human Image
Perception
Kostas Marias
Trang 3Introduction
Trang 4What is MATLAB?
• MATLAB is a tool for doing
numerical computations with
matrices and vectors It is
very powerful and easy to use
In fact, it integrates
computation, visualization and programming all together in an easy-to-use environment and
can be used on almost all the
platforms: windows, Unix, and
Apple Macintosh, etc.
• MATLAB stands for Matrix “
Laboratory ”
Trang 5What is Matlab?
• A software environment for interactive numerical computations
• Examples:
– Matrix computations and linear algebra
– Solving nonlinear equations
– Numerical solution of differential equations
– Mathematical optimization
– Statistics and data analysis
– Signal processing
– Modelling of dynamical systems
– Solving partial differential equations
– Simulation of engineering systems
Trang 6Matlab Background
•Matlab = Matrix Laboratory
•Originally a user interface for numerical linear algebra routines (Lapak/Linpak)
•Commercialized 1984 by The Mathworks
•Since then heavily extended (defacto-standard)
•Alternatives Complements
Octave (free; GNU) Mathematica (symbolic)Lyme (free; Palm)
Trang 7Environment
Trang 8Display Windows
Trang 10Matlab Workspace
• Variables are stored here in
the form of numerical matrices which can be of different
– All numerical operations need to be
performed on double precision, takes 8 bytes per value
– Other types are efficient for storage (<= 2 bytes)
– Who, whos – current variables in workspace
– Save, load – save or load variables to *.mat
file
– Clear all – clear all variables
Trang 11– using one number to index: A(8) – result = 6 – matrix is written out as a single column.
– A(:,2) – obtain second column of the matrix
Trang 13Programming in Matlab
• Script Files
– List of commands to be executed sequentially
Useful when same sequence is executed many times They should be saved with extension script.m and should be placed on work path to be called.
• >>script runs the sequence
• Functions
– Similar to script, but takes arguments
function [output]=funcname(input)
– Any function can be listed with: >>type funcname
• See Matlab editor
(File>New>m-file)
Trang 15What kind of graphics is possible in Matlab ?
Trang 16What kind of graphics is possible in Matlab ?
Trang 17Vectors and Matrices
• Vectors (arrays) are defined as
• >> v = [1, 2, 4, 5]
• >> w = [1; 2; 4; 5]
• Matrices (2D arrays) defined similarly
• >> A = [1,2,3;4,-5,6;5,-6,7]
Trang 18A and a are two different variables
• Transponate conjugates complex entries; avoided by
• >> B=A.’
Trang 19Indexing Matrices
•Indexing using parentheses
•>> A(2,3)
•Index submatrices using vectors
of row and column indices
•>> A([2 3],[1 2])
•Ordering of indices is important!
•>> B=A([3 2],[2 1])
•>> B=[A(3,2),A(3,1);A(2,2);A(2,1)]
Trang 20Indexing Matrices
•Index complete row or column using
the colon operator
Trang 22Numerical Linear Algebra
• Basic numerical linear algebra
• The number of input/output
arguments can often be varied
• >> [V,D]=eig(A)
Trang 23• Can change plot properties in
• >> h=plot(x,y); set(h, ’LineWidth’, 4);
• Many other plot functions available
• >> v=1:4; pie(v)
Trang 26Basic concepts from
Trang 27Inner (dot) Product
v
w
α
2 2
1 1 2
1 2
( w x x y y x y x y
The inner product is a
The inner product is a SCALAR! SCALAR!
).(
, (
w x1 x2 y1 y2 v w
w v
w
Trang 28m m m
m
n
a a
a
a a
a
a a
a
a a
a A
3 32
31
2 22
21
1 12
11
m n m
n m
n A B
C × = × + ×Sum:
ij ij
ij a b
c = +
A and B must have the same dimensions
Trang 29p m m n p
n n
n B B A
A × × ≠ × ×
Identity Matrix:
A AI
0
0 1
0
0 0
Trang 30m n
T n
T A B B
A + ) = +
(
If AT = A A is symmetric
Trang 31Determinant: A must be square
32 31
22 21
13 33
31
23 21
12 33
32
23 22
11 33
32 31
23 22
21
13 12
11
det
a a
a
a a a
a
a
a a a
a
a
a a a
a a
a a
a
a a
11 22
21
12 11
22 21
12 11
a a
a
a a
Trang 32I A
A A
12 22
12 21 22
11
1
22 21
12
a a
a
a a
a a
a a
a
a a
Trang 33MATLAB works with
essentially only one
Trang 35An Example
•A = [1, 2, 3; 7, 8,
9]
Use ; to indicate ‘ ’ the end of each row
to separate elements of
a row
Trang 36• To make the * , ^ , \ ‘ ’ ‘ ’ ‘ ’
Trang 37A = [1, 2, 3; 4, 5, 6]
B = [0.5; 1;3]
C = A * B
v.s.
C = A * B
Trang 38Array Operations
•Scalar-Array Mathematics
For addition, subtraction,
multiplication, and division of an array
by a scalar simply apply the operations
to all elements of the array.
Trang 39Array Operations (con’t…)
• Element-by-Element Array-Array Mathematics.
Trang 40Algebraic operations in Matlab:
subtraction of the individual elements of the matrices Sometimes it is desired to simply multiply or divide each element of an matrix by the corresponding element of another matrix 'array operations”
Array or element-by-element operations are executed when the operator is preceded
by a '.' (period):
a * b multiplies each element of a by the respective element of b
a / b divides each element of a by the respective element of b
a \ b divides each element of b by the respective element of a
a ^ b raise each element of a by the respective b element
Trang 41
For example, if matrices G and H are G = [ 1 3 5; 2 4 6]; H = [-4 0 3; 1 9 8];
D=G * H = [ -4 0 15
2 36 48 ]
Algebraic operations in Matlab:
Trang 42•Subscripts: the element
in row i and column j
of A is denoted by A(i, j)
•Example: A = magic(3); A(1,1) + A(1,2) +
A(1,3)
Trang 43The Colon Operator ‘:’
The colon : is one of MATLAB s ‘ ’ ’ most important operators It
has many formats:
• 3 : -2 : -11 is a row vector containing integers from 3 to –
11 with a increment of 2 –
• Subscript expressions involving colons refer to portions of a matrix:
A(1:3 , 2) is the first to the third elements of the second
column of A.
What does A([1:3], [2:4]) mean?
Trang 44Working with Matrices:
MATLAB provides four functions that generate basic matrices:
• Zeros: all zeros A =
zeros(1,3)
• Ones: all ones A = ones(2,4)
• Rand: uniformly distributed
Trang 45•Concatenation: join small (compatible) matrices to make
Trang 46returns the larger of the number of rows or columns in A.
Trang 47Matrices (con’t…)
Transpose B = A’
Identity Matrix eye(n) returns an n x n identity matrix
eye(m,n) returns an m x n matrix with ones on the main diagonal and zeros elsewhere.
Addition and subtraction C = A + B
C = A – B Scalar Multiplication B = α A, where α is a scalar.
Matrix Multiplication C = A*B
Matrix Inverse B = inv(A), A must be a square matrix in this case.
rank (A) returns the rank of the matrix A.
Matrix Powers B = A.^2 squares each element in the matrix
C = A * A computes A*A, and A must be a square matrix Determinant det (A), and A must be a square matrix.
more commands
A, B, C are matrices, and m, n, α are scalars.
Trang 48Solutions to Systems of Linear Equations
• Example: a system of 3 linear equations with
2 3 1
1 2 3
x x
x x
10
b
Let :
Trang 49Solutions to Systems of Linear Equations
• Solution by Matrix Division:
The solution to the equation
Ax = b can be computed using left division.
Trang 50• The polynomials are represented by
their coefficients in MATLAB.
• Consider the following polynomial:
• For s is scalar: use scalar operations
– A = s^3 + 3*s^2 + 3*s + 1;
• For s is a vector or a matrix: use
array or element by element operation
Trang 51Polynomials (con’t…)
>> s = linspace (-5, 5, 100);
Trang 52Polynomials (con’t…)
Operation MATLAB command Description
same length.
Polynomial
Multiplication
c = conv(a,b) returns the coefficient vector for the polynomial resulting from
the product of polynomial A and B.
Polynomial
Division
[q,r] = deconv(a,b) returns the long division of A and B.
q is the quotient polynomial coefficient, and r is the remainder polynomial coefficient.
Derivatives polyder(a) returns the coefficients of the derivative of the polynomial A
polyder(a, b) returns the coefficients of the derivative of the product of
Trang 53Programming with MATLAB:
•Files that contain code
in the MATLAB language
are called M-files You create M-files using a
text editor, then use
them as you would any
other MATLAB functions or command There are two types of M-files: Scripts and Functions.
Trang 54• Scripts: a bunch of code
grouped together; doesn t accept ’ argument or return output.
• Example: create a file called magicrank.m that calculates
the rank of magic squares:
• Add the file into search path
and type the statement:
magicrank
Trang 55• The M-file is a text file that
consists a group of MATLAB
commands.
• MATLAB can open and execute the commands exactly as if they were entered at the MATLAB command
window.
• To run the M-files, just type
the file name in the command
window (make sure the current
working directory is set
correctly)
All MATLAB commands are M-files.
So far, we have executed the commands in the command window But a more practical way is to create a M-file
Trang 56M-files Functions
• M-files are macros of MATLAB commands that are stored as ordinary text files with the extension m, that is
• Get input by prompting on m-file:
T = input('Input the value of T: ')
Trang 57•Functions are M-files that
can accept input arguments
and return output
arguments The name of the M-file and of the function should be the same
•For example, the M-file
rank.m is available in the
Trang 59if … elseif … else … end
Trang 60for … end
for i = 1:m for j = 1:n H(i,j) = 1/ (i+j)
end
end
Trang 61Suppressing Output:
If you simply type a statement and press Enter, MATLAB
automatically displays the
results on screen If you end the line with a semicolon ; , ‘ ’
MATLAB performs the computation but does not display any
result.
• Example: C = randn(5,1)
v.s
Trang 63subplot
Trang 64Plotting (con’t…)
plot the polynomial using linear/linear scale, log/linear scale, linear/log scale, & log/log scale:
subplot (2,2,1), plot (x,y);
title ('Polynomial, linear/linear scale');
ylabel ('y'), grid;
subplot (2,2,2), semilogx (x,y);
title ('Polynomial, log/linear scale');
ylabel ('y'), grid;
subplot (2,2,3), semilogy (x,y);
title ('Polynomial, linear/log scale');
xlabel('x'), ylabel ('y'), grid;
subplot (2,2,4), loglog (x,y);
title ('Polynomial, log/log scale');
xlabel('x'), ylabel ('y'), grid;
Trang 65Plotting (con’t…)
Trang 66Plotting (con’t…)
• Adding new curves to the existing graph:
• Use the hold command to add lines/points to an existing plot.
– hold on – retain existing axes, add new curves to current axes Axes are rescaled when necessary.
– hold off – release the current figure window for new plots
n Grids and
Labels:
Command Description
grid on Adds dashed grids lines at the tick marks
grid off removes grid lines (default)
grid toggles grid status (off to on, or on to off)
title (‘text’) labels top of plot with text in quotes
xlabel (‘text’) labels horizontal (x) axis with text is quotes
ylabel (‘text’) labels vertical (y) axis with text is quotes
text (x,y,’text’) Adds text in quotes to location (x,y) on the current axes, where (x,y) is in
units from the current plot.
Trang 67Additional commands for plotting
color of the point or curve Marker of the data points Plot line styles
Symbol Line Style
– solid line : dotted line – dash-dot line – – dashed line
Trang 683D - Plotting example
• x=[0:10]; y=[0:10]; z=x *y; ’
• mesh(x,y,z); title( 3-D ‘
Graph ); ’
Trang 69– Type ‘hold on’ to add new plot to current graph
– Type ‘hold off’ to resume stomping
•Make your graph beautiful:
– title(‘apples over oranges’)
– xtitle(‘apples’)
– ytitle(‘oranges’)
Trang 71Useful Constants
•Inf infinity
•NaN Not and number (div
by zero)
•eps machine epsilon
•ans most recent unassigned answer
•pi 3.14159 …
•i and j Matlab supports
imaginary numbers!
Trang 73Ανθρώπινη όραση, αντίλήψη ιατρικής εικόνας
Trang 74Retina - the “focal plane array” on the
back surface of the eye the detects and
measures light.
Photoreceptors - the nerves in the
retina that detect light.
Fovea - a small region in the retina
with high spatial resolution.
Blind spot - a small region in the retina
where the optic nerve is located that
has no photoreceptors.
Long, medium, and short cones - the three specific types of codes used to produce color vision These cones are sensitive to long (L or red) wavelengths, medium (M or green) wavelengths, and short (S or blue) wavelengths.
Αντίληψη εικόνας: Το ανθρώπινο σύστημα
Trang 75Goals in the field of perception:
– Understand contrast and how humans detect changes in images – Understand photometric properties of the physical world.
– Understand the percept of “color”.
– Learn how to use this understanding to design imaging systems.
Αντίληψη εικόνας: Βασικές Κατευθύνσεις
Trang 76A Simple Visual Stimulus
A single uniform dot of luminance L in a large uniform background of
luminance LB.
How much difference is necessary for a “standard observer” to notice the
difference between L and LB?
– The just noticeable difference (JND) is the difference that allows an observer
to detect the stimulus 50% of the time.
– ΔJND is the difference in L and LB required to achieve a just noticable
difference.
L
LB
Αντίληψη εικόνας: Βασικά μεγέθη
Trang 77“Image perception is intimately connected to the psychophysical properties of the visual system of the observer, i.e the ability of the observer to respond to low-contrast and fine-detail stimuli.”
In medical imaging, information is transferred to the observer in two steps:
1 Data acquisition and image formation in the imaging system
2 Processing and display of image data
Visual performance in medical imaging can be divided into three categories:
1 Detection of an abnormality (presence)
2 Recognition of an abnormality (shape and size)
3 Identification (relation to likely disease) of the abnormality
Αντίληψη εικόνας στη Ιατρική
Trang 78πληροφορίας αλλά και της εμπειρίας του.
Trang 79Medical Image Analysis
με βάση της οπτικής πληροφορίας αλλά και της εμπειρίας του
Ο παρατηρητής αποφασίζει και παρέχει πληροφορίες σχετικά με
το απεικονιζόμενο αντικείμενο
Trang 80•The human brain instinctively searches for geometrical
patterns of objects in an image, such as border lines —
preferring well-known figures such as circles, rectangles and triangles — and tries to form those objects
•Τhe viewing distance must be long enough, so that the
pixels cannot be distinguished individually and thus be seen as squares Otherwise, the faculty of vision gives priority to
identification of the square-shaped objects rather than to combining them into a larger object within the image
•The resolution properties of the eye are dependent on
both the contrast level and the light intensity impinging
on the eye The resolution drops from ~7line pairs per mm for film-
lightbox combination (x-rays) to less than 3 for a common CRT monitor!!!
Αντίληψη εικόνας στην Ιατρική
Trang 81"There are times when an experienced
physician experienced physician sees a
visible lesion clearly and times when he
does not This is the baffling problem,
apparently partly visual and partly
psychologic They constitute the still
unexplained human equation in
diagnostic procedures.” Henry Garland,
M.D., 1959
“In the last ten years, our basic
knowledge of physics of
radiological images has
increased to such an extent that
it cries out to be linked with
observer performance studies.”
Kurt Rossmann, 1974
Αντίληψη εικόνας στην Ιατρική : Γνώμες…