Chapter 12

A Selection of MATLAB® Commands

As already stated in the foreword, this book is not an introduction to MATLAB programming; rather than that, we used MATLAB or Octave as some sort of vehicle for executing scripts that illustrate the basic concepts of image processing algorithms. The drawback of this approach is the poor performance of some of the scripts. The advantage, on the other hand, lies in the fact that virtually no knowledge of MATLAB or a more sophisticated programming environment is necessary.

Here, we have collected all commands, control structures and mathematical functions used in the scripts from the LessonData folder. While this selection is by no means representative of the capabilities of MATLAB, it may serve as some resource if a command in the scripts is unclear. You may, of course, also use the help command in the MATLAB shell.

12.1 Control Structures and Operators

for: A loop structure that executes a sequence of commands for a given number of times. The command sequence is delimited by the end keyword.

while: A loop structure that repeats a sequence of commands until a logical condition is met. The command sequence is delimited by the end keyword.

if: A decision structure that executes a sequence of commands if a logical condition is met. The command sequence is delimited by the end keyword.

*: Matrix multiplication; if the operands are scalar, this is the standard multiplication operator.

.*: Component-wise multiplication of matrix elements; the matrices have to have the same dimension.

ˆ: The power-operator. We only use it for computing powers of scalar values.

>: greater than operator.

<: less than operator.

>=: greater or equal operator.

<=: less or equal operator.

~=: not equal operator.

&: logical AND operator. This operator can also be used as a short circuit operator &&.

|: logical OR operator. This operator can also be used as a short circuit operator ||.

(:): The colon operator can be used to assign rows and columns in total. While this is a very powerful tool in MATLAB for fast matrix operations, it also tends to obfuscate the code. We therefore only used it to maintain the shape of a matrix when assigning a stream of data.

@: This operator de-references a call to a function; it is, for instance, used for calling a merit function to be optimized.

12.2 I/O and Data Structures

;: Suppresses output in the MATLAB console.

cd: Changes the working directory of MATLAB.

image: Shows a graphical representation of an arbitrary matrix. The numerical entries in the matrix are shown as colored dots. The assignment of colors can be defined by the colormap command.

colormap: Choose a lookup table for the image command. Since medical images do usually not feature color, we mainly use the gray scale lookup table of MATLAB which features 64 shades of gray.

imshow: A more sophisticated command from the image processing toolbox for directly displaying images; a similar command is also available in Octave. Usually, we do not use this functionality; rather than that, the image command is used.

plot: A command to display a functional relationship from data stored as vectors or matrices.

ylim: This command sets the range of the y-axis in a plot.

bar: Plots a bar chart from a vector or matrix data.

surf: Generates a surface plot from a matrix.

fopen: Opens a file for read or write access, which is defined by the additional 'r' or 'w' attribute. If the file exists, a structure - the file pointer - for reading from or writing to the file is assigned. If the operation fails, fopen returns a value -1.

fseek: A function that moves the file pointer in a file by a given number of bytes. The starting position for this incremental procedure can be defined. Here, we only used ’bof’, which stands for beginning of file.

fread: A function that reads a given number of bytes from a file using the file pointer.

fclose: This functions stops the access to a file and forces data to be written to disk.

imread: A function that reads the content of more complex image file formats and saves the content in matrix. A similar command exists for Octave.

imwrite: Another function that allows for saving matrices as images in common file formats such as JPG. A similar command with a slightly different syntax exists for Octave.

save: A command for writing a matrix to a file from MATLAB.

load: A command for reading matrix data from a file.

sprintf: This function returns a string, or a vector of characters from other characters or numbers.

fprintf: This function writes binary data for a file using the file pointer.

: A non-printable character - the line break.

input: This function is used for reading input from the console. We only use it to stop program execution until a key is pressed.

char: The 8 bit integer datatype of MATLAB.

short: The 16 bit integer datatype of MATLAB.

uint8 (...): ’uint8’ stands for an unsigned 8 bit integer datatype. Calls of this type force a typecast on a number - it is therefore possible to change the datatype of a variable. A similar call would be double (...).

zeros: This function generates a matrix of arbitrary dimension, filled with zeros.

eye: This function returns an identity matrix; only one argument is required since the number of columns and rows in an identity matrix is identical.

12.3 Mathematical Functions

function:This keyword allows for definition of custom functions in MATLAB. In order to keep the sample code simple and compact, we did not use this possibility to a large extent.

transpose: The transposition operation switches rows and columns in a matrix. We use this operation frequently, especially since MATLAB may show a flipped version of images sometimes. Applied to a vector, it changes a row vector to a column vector and vice versa.

max: This function returns the maximum element of a vector. If it is applied to a matrix, it returns a vector of the maximal element in each column.

min: This function returns the minimum value; otherwise, its behavior is identical to max.

size: Returns the dimension of a matrix or a vector.

mean: Returns the average value of all entries in a vector; if applied to a matrix, it returns a vector of the averages from each column.

median: Returns the median value of all entries in a vector.

std: Returns the standard deviation of all entries in a vector.

sort: Returns a vector with sorted vector entries.

round: Returns a rounded integer value if applied to floating point number.

floor: Returns the next smallest integer value if applied to floating point number.

log: The logarithm.

exp: The exponential function.

sin: The sine.

cos: The cosine.

fft: Returns a complex-valued vector which represents the Fourier transform stored in a vector.

ifft: The inverse Fourier transform, which maps from k-space to the spatial domain.

fft2: The two-dimensional fast Fourier transform.

ifft2: The inverse two-dimensional fast Fourier transform.

fftshift: A phase shift for aligning images in a symmetrical manner when applying the DFT.

ifftshift: The inverse phase shift, necessary before transforming an image back to the spatial domain.

abs: The absolute values of a scalar or of matrix components. The length of a vector is computed by calling the norm function.

real: Returns the real part of a complex number.

mod: Returns the modulus of a division.

inv: The inverse of a matrix.

det: The determinant of a matrix.

lsqlin: Solves a system of equations using the method of linear least squares. It is part of the Optimization toolbox of MATLAB.

eig: Returns the eigenvalues and eigenvectors of a matrix.

fminsearch: The MATLAB version of the Nelder-Mead algorithm. It is part of the Optimization Toolbox. The same function does not perform very well in Octave.

cross: The outer product of two vectors.

dot: The scalar product of two vectors.

pi:... approximately 3.14159.

12.4 Further References

S. Attaway: MATLAB: A Practical Introduction to Programming and Problem Solving, Butterworth-Heinemann, (2009)

R. C. Gonzalez, R. E. Woods, and S. L. Eddins: Digital Image Processing Using MATLAB, Gatesmark Publishing, (2009)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.6.75