Professional Documents
Culture Documents
Image Processing of A Male Leg X
Image Processing of A Male Leg X
Measurement and recording techniques which are not primarily designed to produce
images, such as electroencephalography (EEG), magneto encephalography (MEG),
electrocardiography (ECG), and others represent other technologies which produce
data susceptible to representation as a parameter graph vs. time or maps which contain
information about the measurement locations. In a limited comparison these
technologies can be considered as forms of medical imaging in another discipline.
Up until 2010, 5 billion medical imaging studies had been conducted worldwide.
Radiation exposure from medical imaging in 2006 made up about 50% of total
ionizing radiation exposure in the United States.
1
Medical Image Processing Using MATLAB 2016
the techniques developed for medical imaging also have scientific and industrial
applications.
2
Medical Image Processing Using MATLAB 2016
Medical field
Remote sensing
Machine/Robot vision
Colour processing
Pattern recognition
Video processing
Microscopic Imaging
Others
3
Medical Image Processing Using MATLAB 2016
Clear,close all
To read an image, use the imread command. The example reads one of the sample
images included with the toolbox, pout.tif, and stores it in an array named I.
I = imread('pout.tif');
imread infers from the file that the graphics file format is Tagged Image File Format
(TIFF). For the list of supported graphics file formats, see the imread function
reference documentation.
Now display the image. The toolbox includes two image display functions: imshow
and imtool.imshow is the toolbox's fundamental image display function.
imshow(I)
4
Medical Image Processing Using MATLAB 2016
You can also get information about variables in the workspace by calling the whos
command.
whos
figure, imhist(I)
5
Medical Image Processing Using MATLAB 2016
Notice how the intensity range is rather narrow. It does not cover the potential range
of [0, 255], and is missing the high and low values that would result in good contrast.
The toolbox provides several ways to improve the contrast in an image. One way is to
call the histeq function to spread the intensity values over the full range of the
image, a process called histogram equalization.
I2 = histeq(I);
figure, imshow(I2)
We call imhist again to create a histogram of the equalized image I2. If you
compare the two histograms, the histogram of I2 is more spread out than the
histogram of I1.
figure, imhist(I2)
6
Medical Image Processing Using MATLAB 2016
imfinfo('pout2.png')
The imfinfo function returns information about the image in the file, such as its
format, size, width, and height. See Getting Information about a Graphics File for
more information about using imfinfo.
ans =
Filename: 'pout2.png'
FileSize: 36938
Format: 'png'
FormatVersion: []
Width: 240
Height: 291
BitDepth: 8
ColorType: 'grayscale'
The above example is a preliminary image processing task that can be handled by the
MATLAB. We can do a lot more things like image analysis, element counting,
sharpening of the image, modifying blurred images, adding or subtracting images etc
by MATLAB. Some image examples are processed through MATLAB in the section.
7
Medical Image Processing Using MATLAB 2016
Introduction to MATLAB
What is MATLAB?
MATLAB is widely used in all areas of applied mathematics, in education and
research at universities, and in the industry. MATLAB stands for MATrixLABoratory
and the software is built up around vectors and matrices. This makes the software
particularly useful for linear algebra but MATLAB is also a great tool for solving
algebraic and differential equations and for numerical integration. MATLAB has
powerful graphic tools and can produce nice pictures in both 2D and 3D. It is also a
programming language, and is one of the easiest programming languages for writing
mathematical programs. MATLAB also has some tool boxes useful for signal
processing, image processing, optimization, etc.
PC: Choose the submenu "Programs" from the "Start" menu. From the "Programs"
menu, open the "MATLAB" submenu. From the "MATLAB" submenu, choose
"MATLAB".
In the command window you will see a prompt that looks like >>. You type your
commands immediately after this prompt. Once you have typed the command you
wish MATLAB to perform, press <enter>. If you want to interrupt a
command that MATLAB is running, type <ctrl> + <c>.
The commands you type in the command window are stored by MATLAB and can be
viewed in the Command History window. To repeat a command you have already
used, you can simply double-click on the command in the history window, or use the
8
Medical Image Processing Using MATLAB 2016
<up arrow> at the command prompt to iterate through the commands you have used
until you reach the command you desire to repeat.
>> 5*sin(2.5^(3-pi))+1/75
ans =
3.8617
Note that MATLAB is case sensitive. This means that MATLAB knows a difference
between letters written as lower and upper case letters. For example, MATLAB will
understand sin(2) but will not understand Sin(2).
MATLAB
Operation, function or constant
command
+ (addition) +
- (subtraction) -
× (multiplication) *
/ (division) /
|x| (absolute value of x) abs(x)
square root of x sqrt(x)
ex exp(x)
ln x (natural log) log(x)
log10 x (base 10 log) log10(x)
sin x sin(x)
cos x cos(x)
tan x tan(x)
cot x cot(x)
arcsin x asin(x)
arccos x acos(x)
9
Medical Image Processing Using MATLAB 2016
arctan x atan(x)
arccot x acot(x)
n! (n factorial) gamma(n+1)
e (2.71828...) exp(1)
(3.14159265...) Pi
i (imaginary unit, sqrt(-1)) I
For example, to obtain help on the gamma function, we type at the command prompt:
Try this now. You may also get help about commands using the "Help Desk", which
can be accessed by selecting the MATLAB Help option under the Help menu.
Note that the description MATLAB returns about the command you requested help on
contains the command name in ALL CAPS. This does not mean that you use this
command by typing it in ALL CAPS. In MATLAB, you almost always use all lower
case letters when using a command.
Variables in MATLAB
We can easily define our own variables in MATLAB. Let's say we need to use the
value of 3.5 sin (2.9) repeatedly. Instead of typing 3.5*sin (2.9)over and
over again, we can denote this variable as x by typing the following:
x =
0.8374
Now type:
>> x+1
ans =
1.8374
10
Medical Image Processing Using MATLAB 2016
Note that we did not need to declare x as a variable that is supposed to hold a
floating point number as we would need to do in most programming languages.
Often, we may not want to have the result of a calculation printed-out to the command
window. To supress this output, we put a semi-colon at the end of the command;
MATLAB still performs the command in "the background". If you defined x as
above, now type
>> y=2*x;
>> y
y =
1.6747.
In many cases we want to know what variables we have declared. We can do this by
typing whos. Alternatively, we can view the values by opening the "Workspace"
window. This is done by selecting the Workspace option from the View menu. If you
want to erase all variables from the MATLAB memory, type clear. For erase a
specific variable, say x, type clear x. To clear two specific variables, say x and y,
type clear x y, that is separate the different variables with a space. Variables can also
be cleared by selecting them in the Workspace window and selecting the delete
option.
Example: x= [1 2 3 4 5 6 7 8 9 10]
Or by typing
>> x=1:0.1:1.5
>> A = [1 2 3; 4 5 6; 7 8 9];
A =
11
Medical Image Processing Using MATLAB 2016
1 2 3
4 5 6
7 8 9
i.e., rows are separated with semi-colons. If we want to use a specific element in a
vector or a matrix, study the following example:
Example:
>> x (2)
ans =
20
>> A (3, 1)
ans =
Here we extracted the second element of the vector by typing the variable and the
position within parentheses. The same principle holds for matrices; the first number
specifies the row of the matrix, and the second number specifies the column of the
matrix.
Note that in MATLAB the first index of a vector or matrix starts at 1, not 0 as is
common with other programming languages.
If the matrices (or vectors which are special cases of a matrices) are of the same
dimensions then matrix addition, matrix subtraction and scalar multiplication works
just like we are used to.
Example: Type
>> X = [1 2 3]
>> y = [4 5 6]
>> a=2
>> x+y
ans =
>> x-y
12
Medical Image Processing Using MATLAB 2016
ans =
>> a*x
ans =
1.6747
>> x=1:10
x =
1 2 3 4 5 6 7 8 9
10
>> x.^2
ans =
1 4 9 16 25 36 49 64 81
100
>> A = [1 2 3; 4 5 6; 7 8 9]
A =
1 2 3
4 5 6
7 8 9
>> A.^2
ans =
1 4 9
16 25 36
49 64 81
>> A^2
13
Medical Image Processing Using MATLAB 2016
ans =
30 36 42
66 81 96
The dot allows us to do operations element wise. All built-in functions such as sin,
cos, exp and so on automatically act elementwise on a matrix.
Type
y=
>> y = pi*y
y=
ans =
Example 1: Plot sin(x2) on the interval [-5, 5]. To do this, type the following:
>> x=-5:0.01:5;
>> y=sin(x.^2);
>> plot(x,y)
>> x=logspace(-5,5,101);
14
Medical Image Processing Using MATLAB 2016
>> y=x.^(5/2);
>> plot(x,y)
15
Medical Image Processing Using MATLAB 2016
16
Medical Image Processing Using MATLAB 2016
Step 2:- Using the command ‘clear, close all’, we make the work space
bar empty for fresh processing of images.
Step 3:- Leg X-Ray of male is stored in jpg format. The important task is to import
this X-Ray image from the memory of the compute r to the MATLAB environment.
We write in the command window
Imread is a MATLAB’s function to read images from the computer into its
environment. But there is a word of caution. If we don’t change the current directory’s
name, the MATLAB will not be able to read the image. But there is another way of
overcoming to this problem. We can make the MATLAB to read the desired image by
giving the exact location and file name details. For instance if an image is on the
desktop, we can use
Step 4:- After reading the image, to know the dimension of the image use size (
) command. This results as shown below:
>> size(I)
ans =
1275 1650
The result shows that the image named ‘nits.jpg’ which is being processed is an
array of 1275 and1650, where there are 1275 rows and 1650 columns. Each element
of this array is an image point or pixels. So the total numbers of the pixels in this
image is 2103750 i.e. it is approximately 2.00 Mega pixel image.
17
Medical Image Processing Using MATLAB 2016
Step 5:- To get additional information about the image use whos as
>> whos
18
Medical Image Processing Using MATLAB 2016
Step 7:- To add the title and other labels we use title command. In this case, X-ray
image is named as ‘A Male Leg X-Ray’ as follows:
19
Medical Image Processing Using MATLAB 2016
Now we want that the intensity level of pixels should spread or take on all possible
values on the scale. So, to solve the problem of low dynamic range of pictures we
equalize the intensity histogram. MATLAB provides an important function histeq
( ) for this purpose.
And the histogram equalised image is shown below along with its histogram.
20
Medical Image Processing Using MATLAB 2016
21
Medical Image Processing Using MATLAB 2016
Spatial resolution is the density of pixels over the image: the greater the spatial
resolution, the more pixels are used to display the image. We can experiment with
spatial resolution with MATLAB's imresize function. By changing the parameters of
imresize, we can change the effective resolution of the image to smaller amounts:
The command imresize(I,1/2);
>> b1=imadd(I,128);
Subtraction is similar; we can transform out matrix in and out of double, or use the
imsubtract function:
>> b2=imsubtract (I,128);
22
Medical Image Processing Using MATLAB 2016
>> b3=immultiply(I,5);
>> b4=imdivide(I,2)
>> bc=imcomplement(I);
>> imshow(bc)
23
Medical Image Processing Using MATLAB 2016
24
Medical Image Processing Using MATLAB 2016
25
Medical Image Processing Using MATLAB 2016
Gaussian noise
Gaussian noise is an idealized form of white noise, which is caused by random
fluctuations in the signal. We can observe white noise by watching a television which
is slightly mistuned to a particular channel. Gaussian noise is white noise which is
normally distributed. If the image is represented as I and the Gaussian noise by N,
then we can model a noisy image by simply adding the two: I+N
The effect can again be demonstrated by the imnoise function:
>> t_ga=inoise(t,'gaussian');
The noisy figure by Guassian noise is shown below:
26
Medical Image Processing Using MATLAB 2016
27
Medical Image Processing Using MATLAB 2016
>>bw= im2bw(I);
28
Medical Image Processing Using MATLAB 2016
A bad choice of colourmap can ruin an image, then we apply the vga colourmap.
This is done with the grayslice function:
>> b16=grayslice(I,16);
>> figure,imshow(b16,colormap(vga))
We can easily create our own colourmap: it must by a matrix with 3 columns, and
each row
consists of RGB values between 0.0 and 1.0. Suppose we wish to create a blue,
magenta, green, red colourmap as shown in table using the RGB values:
29
Medical Image Processing Using MATLAB 2016
30
Medical Image Processing Using MATLAB 2016
31