Professional Documents
Culture Documents
LO SHING LOONG
Certified by :
Signature :
Name of Supervisor : DR. YUSRI YUNUS
Date : APRIL 2010
IMAGE PROCESSING USING MATLAB – LEARNING TOOL
LO SHING LOONG
A thesis submitted in fulfillment of the requirements for the award of the degree of
Bachelor of Engineering (Telecommunication)
APRIL 2010
ii
DECLARATION
“I declare that this work as the product of my own effort with the exception of
excerpts cited form other works of which the sources were duly noted”
Signature :
DECLARATION
ACKNOWLEDGEMENT
My appreciation also goes to my family who has been so tolerant and supports
me all these years. Thanks for their encouragement, love and emotional supports that
they had given to me.
.
v
ABSTRACT
The purpose for this study is to investigate a software application that can show
how the image is process in computer platform. The process will be done in converting
the picture to matrix model by using MATLAB program. Picture will be shown when
program is running successfully. Real image or picture will be resulted from the matrix
using the function in the MATHLAB. User can use varies of functions such as filter or
rotate depending on the user itself. In this study, the picture or real image used is from
Internet, scanner and etc. Basic mathematical calculation does not apply in this project
as it only used MATHLAB program. The significant of this project is to educated user to
learn how the image can be changes after the function indicated by the program.
vi
ABSTRAK
Tujuan kajian ini adalah untuk mencari suatu aplikasi perisian yang dapat
menunjukkan bagaimana imej di proses dalam platform komputer. Proses ini akan
dilakukan dalam menukar imej-imej untuk model matriks dengan menggunakan
program MATLAB. Imej akan dipaparkan ketika program ini beroperasi dengan
jayanya. Imej tulen atau gambar akan dihasilkan dari matriks menggunakan fungsi di
MATHLAB. Pengguna boleh menggunakan fungsi bervariasi seperti penapis atau lain-
lain, bergantung pada pengguna itu sendiri. Dalam kajian ini, imej atau bayangan nyata
yang digunakan adalah dari Internet, scanner, dan lain-lain Dasar perhitungan matematik
tidak berlaku dalam projek ini kerana hanya menggunakan program MATHLAB.
Pengguna dididik untuk mempelajari bagaimana imej boleh berubah setelah melalui
berbagai fungsi yang ditunjukkan oleh program.
vii
TABLE OF CONTENTS
TITLE OF RESEARCH i
DECLARATION ii
ACKNOWLEDGEMENT iv
ABSTRACT v
LIST OF TABLE x
LIST OF FIGURES xi
1 INTRODUCTION
1.1 Introduction 1
1.2 Objective of The Project 3
1.3 Scope of Project 3
1.4 Outline of Thesis 3
1.5 Summary of Work 4
viii
3 METODOLOGY
3.1 Introduction 17
3.2 Blur/Deblurring Image Using Blind Deconvolution 19
Algorithm 20
3.3 Enhancing Multispectral Color Composite Images
Threshold / Edge Detection
3.4 Threshold / Edge Detection 20
3.5 Identify the Round Object 21
3.6 Rotate 22
3.7 Open Image 23
3.8 Reset 24
3.9 Save Image 24
3.10 Show Original Picture 25
ix
4.1 Introduction 26
4.2 GUI (Graphical User Interface) 27
4.3 Image Processing Result 29
5.1 Conclsion 35
5.2 Problems 36
5.3 Recommendation 37
REFERENCES 38
APPENDICES A 39
APPENDICES B 43
x
LIST OF TABLES
LIST OF FIGURES
INTRODUCTION
1.1 Introduction
Image processing is any form of signal processing for which the input is an
image, such as photographs; the output of image processing can be either an image or a
set of characteristics or parameters related to the image. Most image-processing
techniques involve treating the image as a two-dimensional signal and applying standard
signal-processing techniques to it. Image processing – converting the image to another
form by using direction in MATLAB/Toolboxes/Image Processing tables for example is
image input/output, color operation, image enhancement/ analysis and another method.
Image processing is the manipulation of the image by using a computer, with the
objective to enhance or evaluate some aspect of an image which is not readily apparent
in its original form. This is done through the development and implementation of
processing means necessary to operate on the image. Processing image using a digital
computer provides the greatest flexibility and power for general image processing
2
application, since the programming of a computer can be changed easily which allows
operation to be modified quickly.
Interest in image processing technique dates back to early 1920’s when digitized
pictures of world news events were first transmitted by submarine cable between
Newyork and London. However, application of digital image processing concepts did
not become widespread until the middle 1960’s, when third-generation digital computers
began to offer the speed and storage capabilities required for practical implementation of
image processing algorithms. Since then, this area has experienced vigorous growth and
has been subjected of study and research in such fields as engineering, computer science,
statistics, information science, physics, chemistry and medicine.
The result of these efforts have established the value of image processing
technique in of problem with application in diverse fields, including automated factory
controlled, astronomy, meteorology, agriculture, medicine, art and military application.
With the increasing availability of reasonably inexpensive hardware and some very
importance application on the horizon, image technology is expected to continue its
growth and to play an important role in the future.
From the MATLAB software we have the Toolbox for image processing and
Professional MATLAB. MATLAB is the interactive environment, scientists and
engineers are able to analyze and develop algorithms with exceptional improvements n
productivity and creativity. As a result of new algorithms with application-specific uses.
The MathWorks offers a series of application toolboxes that contain set of MATLAB ofr
the Linear algebra, high-speed computational kernel, extensive mathematical
functionality, data analysis, 2-D and 3-D graphic rapid algorithm development, matrix
based programming environment. In MATLAB Toolboxes professional version but
priced at a lower rate for academic use.
3
This thesis consists four chapters. In first chapter, it discuss about the objective
and scope of this project as long as summary of works. While Chapter 2 will discuss
4
more on theory and literature reviews that have been done. It well discuss about types of
motor, various kind of speed measurement and controllers (thyristor, phase-lock loop
and PWM technique) that can be used to control the speed of the motor.
Image
MATLAB
Process
Block
Processed
Image
sensor system specially designed to view a scene and provide a digital representation of
the scene.
Process block. When the images are installed in MATLAB, flowers picture for
example, the color of that image is first analyzed. In the process include several
functions of image processing technique.
Processed Image is the image display after the process. Gantt charts as shown in
Figure 1.2 and Figure 1.3 show the detail of the works of the project that had been
implemented in the first and second semester.
6
2.1 Introduction
2.2 Histogram
predetermined threshold and a dark portion average value denoting an average of the
light intensity values which are less than the predetermined threshold are calculated. A
new threshold is obtained by applying the bright portion average value and the dark
portion average value to a predetermined dividing ratio. The object within the image
area is distinguished using the new threshold. The method is also applicable to the use
of multi value thresholds.
Estimate each object's area and perimeter. Use these results to form a simple
metric indicating the roundness of an object:
11
Metric = 4*pi*area/perimeter^2.
This metric is equal to one only for a circle and it is less than one for any other
shape. The discrimination process can be controlled by setting an appropriate threshold.
In this example use a threshold of 0.94 so that only the pills will be classified as round.
The digital filter can be categorized as a low pass or high pass filter depending
on which part of the frequency spectrum it affects. The effect on a composite electrical
analog signal containing all frequency components. The output signal of the high pass
filter will contain the high frequency components. The output signal of the low pass
filter will contain the DC bias and low frequency components. The specific cutoff
frequency cab be varied the selection of the value used in the filter, but that is beyond
the scope of this course.
The low pass filter will not affect low frequency components in the image data
and will attenuate the high frequency components as illustrated in figure 2.1. Random
speckles in an image can be considered as noise and are high frequency components
since the pixel values of adjacent pixels change very rapidly. The effect of the speckles
can be reduced by using a simple averaging filter. The coefficient matrix for an
12
averaging filter for a 3x3 local area convolution would contain nine elements as shown
below.
High Pass
Filter
(b)
Low Pass
Filter
(a)
(c)
Figure 2.1 Filter
Result of low pass (b) and high pass (c) digital filter on a composite signal (a)
containing both low and high frequency as well as a DC bias.
The value for the pixel in the output matrix is calculated by convoluting the
image data, p1,j with the coefficient matrix f1,j and placing the resultant value at the
center pixel of the area in the new image matrix. The clearly for low pass filter, the
coefficient values of a low pass filter can declared with matrix form as show below
figure 2.2;
13
1 1 1
, , , ⎡ 9 9 9⎤
, , , = ⎢1 1 1 ⎥
⎢ 9 9 9⎥
, , , 1 1 1
⎣ 9 9 9⎦
Figure 2.2 coefficient values of low pass filter
q2 , 2 = , x , + , x , +…+ , x ,
If the sum of the coefficient must be equal 1, amplification will result. If the sum
is less than 1, attenuation will result, and the magnitude of the pixel value over the entire
image will be reduced. Hence, the image would appear darker.
The application of the 3x3 coefficient matrix to a data field where all the pixel
have the same value will have no effect except where there is a gradient between
adjacent pixels. The effect of the low pass digital filter in reducing noise can be
illustrated by considering the case where there is one pixel in the matrix which is zero
due to bad element in the sensor array used to acquire the data; all the adjacent pixels
have a high value show is figure 2.3.
14
7 7 7 7 7 7
7 0 7 7 7 7
7 7 7 7 7 7
(a) (b)
Figure 2.3 effect of low pass filter (a) matrix with bad element (b) matrix after low pass
filter
If the bad pixel value had been high instead of low as the result of a white speck,
the application of the low filter would have had the effect of reducing the magnitude of
the value of bad pixel.
The high pass digital filter has the inverse characteristic of low pass filter. The
filter will not change the high frequency component of a signal and will attenuate the
low frequency component as well as eliminate any bias in the signal. The effect of
background light would result in a DC bias in the vision system data since the minimum
value of all pixel would be above some given some given value. The effect of applying a
15
high pass filter to the data for a 6 x 6 image is shown in the histogram of figure 2.4
below. The high pixel values may or may not change depending on the degree of
saturation of the image.
The high pass filter coefficient set for set for a 3 x 3 matrix convolution mask is
−1 −1 −1
−1 −8 −1
−1 −1 −1
Figure 2.4 high pass filter coefficient set for 3x3 matrix convolution mask
Since the sum of all the coefficients is equal to zero, the dc component will be
completely suppressed. If the sum were equal to +1, the DC value would have been
retained at the same value as the original signal. The filter is applied by overlaying the
3x3 coefficient matrix filter mask on the image data, multiplying the coefficient and data
in each of the nine elements, and adding the nine resultant products to obtain the value
of the new element located at the center of 3 x 3 matrixes. The mask is then shifted by
one unit and the process repeated to obtain the value of the next new element.
16
+1 +1 +1 4 8 8 − − −
+1 −8 +1 4 8 8 − [] −
+1 +1 +1 4 8 8 − − −
mask data element
Figure 2.5 mask, data and element
(2,2) = +(1x4)+(1x8)+(1x8)+(1x4)-(8x8)-(8x8)+(1x8)+(1x4)+(1x8)+(1x8)
= +4+8+8+4-64+8+4+8+8
=` +52-62
= -12
CHAPTER III
METHODOLOGY
3.1 Introduction
Image
MATLAB
Process
Block
Processed
Image
Image and MATLAB involves the conversion of scene into a digital representation that
can be processed by a digital computer. This can be performed by a sensor system
specially designed to view a scene and provide a digital representation of the scene.
When the images are installed in MATLAB, flowers picture for example, the
color of that image is first analyzed. In the process include several functions of image
processing technique. Processed Image is the image display after the process.
19
d) blurred = imfilter(IMG, PSF, 'conv', 'circular'), simulate the blur, convolve the
filter with the image using imfilter.
h) delta_sq=diff(boundary).^2;perimeter=sum(sqrt(sum(delta_sq,2))), compute a
simple estimate of the object's perimeter
k) if
metric>threshold; centroid = stats(k); Centroid; plot(centroid(1),centroid(2),'ko');
end
mark objects above the threshold with a black circle
3.6 Rotate
b) i = 1:s(1)
23
j=1:s(2);
k=s(2)-j+1;
result(k,i,:)=image(i,j,:),Computing the new matrix
c) res=uint8(result);
IMG=res;
imshow(IMG), Displaying the rotated image
3.8 Reset
a) (get(handles.checkbox3,'Value') == 0),
25
4.1 Introduction
Before processing the image, we must know what process should be planning.
The planning as shown in figure 4.1 is step to process the image by applying MATLAB
toolbox program.
-Modified Image
1. JPG -Show Image
2. Any image
Get image
1. Enhance
2. Threshold
RESULT 3. Rotate
4. Blur
5. Deblur
6. Identify Round Object
Regarding to figure 4.1 we can know the step to identify which the images
are .JPG and any image file. To develop the program, we should know how to create
GUI (Graphical User Interface) function program.
GUI components can include menus, toolbars, push buttons, radio buttons, list
boxes, and sliders—just to name a few. GUIs created using MATLAB tools can also
perform any type of computation, read and write data files, communicate with other
GUIs, and display data as tables or as plots
Most GUIs wait for their user to manipulate a control, and then respond to each
action in turn. Each control, and the GUI itself, has one or more user-written routines
(executable MATLAB code) known as callbacks, named for the fact that they "call
back" to MATLAB to ask it to do things. The execution of each callback is triggered by
a particular user action such as pressing a screen button, clicking a mouse button,
selecting a menu item, typing a string or a numeric value, or passing the cursor over a
component. The GUI then responds to these events. You, as the creator of the GUI,
provide callbacks which define what the components do to handle events.
Although you can provide a callback with certain data and make it do anything
you want, you cannot control when callbacks will execute. That is, when your GUI is
being used, you have no control over the sequence of events that trigger particular
callbacks or what other callbacks might still be running at those times. This
distinguishes event-driven programming from other types of control flow, for example,
processing sequential data files.
29
The image will be modified after the process in the program system. The GUI
program I create will be show below and include all the results (modified images) for
each function.
5.1 Conclusion
Image can be solved with ant software programming such as C language, Matrix
– X (Mainframe or workstation, based on MATLAB), Visual Basic, Java program and
MATLAB program. Image applications frequently need to produce multiple degrees of
manipulation interactively. Image applications frequently need to interactively
manipulate an image by continuously changing a single parameter and multi-parameter.
The best software program is the MATLAB toolbox for image processing. Interpolation
and extrapolation of image can be a unifying approach, providing a simple function that
supports many common images processing operation.
By using the GUI (Graphical User Interface) program, the application of image
processing can successfully created. The function of the image processing program
36
include the enhance, threshold, rotate, blur (noise), deblur, identify round object and
show the original and modified image together.
5.3 Problems
Although the image processing program function as we aspect, but there are still
many way to improve this program. In the image processing program, the info for the
function are not state clearly enough and make people understand. In the GUI program,
the info should function as pop-up window after user press any function button.
As the project title is Image Processing using MATLAB – Learning Tool, the
information is not good enough and clear to understand by people. The main problem is
the effectiveness of people to understand it. MATLAB also can be used in industry are
in the areas of bar coding, deck-top publication, copy preparation for printing and
factory automation.
However, due to the information and studies this state of program of image
processing that I only can create. More advance and more functional program can be
creating by using MATLAB. Thereby, to write the program became problem and the this
project not perfectly complete.
37
5.3 Recommendations
The result of the program is slightly sluggish. For future works, some
recommendations have been listed based on the problems in order to improve the
performance.
a) Create a 3-D for the image processing and animation. Then the image can be
more sophisticated if the 3-D program instead. Can spin and move the image
with applying that command, so that we can create a great animation for the
image.
b) Add more functional button of more function to the program. It is less filter to
filter image, such as Robert Gradient, Sobel Edge Detector Operator, Gaussion
filter and other filters.
c) More information and detail about the function should be add in the program to
educate people well.
38
REFERENCES
APPENDIX A
Image input/output
bmpread -Read a BMP (Microsoft Windows Bitmap) file from disk.
bmpwrite -Write a BMP (Microsoft Windows Bitmap) file from disk.
gifread -Read a GIF (Graphical Interchange Format) file from disk.
gifread -Write a GIF (Graphical Interchange Format) file from disk.
hdfpeek -Read data from HDF file.
hdfwrite -Write data from HDF file.
pcxread -Read a PCX (ZSoft Paint Format) file form disk.
pcxwrite -Write a PCX (ZSoft Paint Format) file form disk.
tiffread -Read a TIFF (Tagged Image File Format) file from disk.
tiffwrite -Write a TIFF (Tagged Image File Format) file from disk.
xwdread -Read a XWD (X window dump) file from disk.
xwdwrite -Write a XWD (X window dump) file from disk.
Utility routines
getimage -Get image data form axes
isbw -True for black and white images.
isgray -True for intensity images.
isind -True for indexed images.
Color operations
brighten -Brighten or darken a colormap.
cmunique -Find unique colormap colors and corresponding image.
cmpermute -Permute colormap positions.
cmgamma -Gamma correct colormap.
cmgamdef -Default gamma correction table.
dither -Floyd-Steinberg image dithering.
hsv2rgb -Convert HSV values to RGB colorspace.
imadjust -adjust and stretch image by an image with fewer colors.
imapprox -Approximate indexed image by an image with fewer colors.
ntsc2rgb -Convert NTSC values to RGB colorspace.
rgb2gray -Convert RGB values to gray.
rgb2hsv -Convert RGB values to HSV colorspace.
rgb2ntsc -Convert RGB values to NTSC colorspace.
rgbplot -Plot RGB colormap components.
40
Geometric operations
imcrop -Crop image
imresize -Resize image
imrotate -Rotate image
truesize -Resize figure so that image is actual size
imzoom -Zoom in and out an image or 2-D plot
Image enhancement/analysis
brighten -Brigthen or darken a colormap.
grayslice -Density (intensity) slicing.
histeq -Histogram equalization.
imadjust -Adjust and stretch image intensity
imapprox -Approximate indexed image by an image with fewer colors.
imhist -Image histogram
impixel -color of a pixel
improfile -intensity profile.
interp2 -2-D data interpolation.
Image Statistics.
mean2 -Mean of a matrix
corr2 -2-D correlation coefficient.
std2 -2-D standard deviation.
Morphological operations.
bwarea -Area of object in binary image.
dilate -Dilate (thicken) a binary image.
erode -Erode (thin) a binary image.
edge -Euler number.
bwmorph -Morphological operators.
bwperim -Perimeter of objects in a binary image.
Frequency response.
freqspace -Frequency spacing for 2-D frequency responses.
freqz2 -Two dimensional frequency response.
41
Filtering.
colfilt -Local non-linear filtering as columns.
conv2 -Two-dimensional convolution.
filter2 -Two-dimensional filtering.
medfilt2 -Two-dimensional median filtering.
mfilter2 -Masked filter.
nlfilter -Local non-linear filtering.
wiener2 -Adaptive 2-D Wiener filtering
Block processing
bestblk -Best block size for block processing.
blkproc -Process an image in blocks.
col2im -Rearrange distinct or sliding column blocks to form image,
colfilt -Local non-linear filtering as columns.
im2col -Rearrange distinct or sliding blocks into columns.
Transforms.
dct2 -2-D discrete cosine transform.
fft2 -2-D Fast Fourier Transform.
fftshift -Move zeroth lag (DC component) to center.
idct2 -2-D inverse discrete cosine transform.
ifft2 -2-D inverse FFt
radon -Radon transform.
Conversions.
dither -Floyed-Steinberg image dithering.
gray2ind -Convert gray scale intensity image to indexed image.
hsv2rgb -Covert HSV values to RGB colorspace.
im2bw -convert image to black and white by thresholding.
imslice -Get image slices into an image deck
ind2rgb -Convert indexed image to an RGB image.
mat2gray - Convert matrix to (gray) intensity image.
ntsc2rgb - Convert NTSC values to an RGB image.
rgb2gray - Convert an RGB image r values to gray.
rgb2hsv - Convert RGB values to HSV colorspace..
rgb2ind - Convert RGB image to indexed image.
rgb2ntsc - Convert RGB values to NTSC colorspace.\
42
Image diplay
colorbar -Display color bar (color scale)
colormap -Set or get the color look-up table.
gray -Linear gray-scale color map
hsv,hot,jet -Colormaps. Types HELP COLOR for others
image -Display indexed image.
imagesc -Scale data and display as image
imcoutour -Image coutour.
immovie -Make a movie of an image deck.
imshow -Display all type of image data.
montage -Display an image deck as a rectangular montage.
warp -Warp an image on
43
APPENDIX B
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = LearningTool_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
threshold = 0.94;
text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
'FontSize',14,'FontWeight','bold');
end
51
var=strcat(pathname,filename,'.jpg');
imwrite(image,var);
set(hObject,'BackgroundColor','white');
end
end