DECLARATION I hereby declare that the results embodied in this dissertation entitled “CAR NUMBER PLATE RECOGNITION” is carried out by me during the year 2008-09 in partial fulfillment of the requirements of the award of degree, Bachelor of Engineering in Electronics and Communication Engineering from M.V.S.R Engineering College, affiliated to Osmania University, Hyderabad. I have not been submitted the same to any other university or organization for award of any other degree or diploma. D. Keerthi K. Aruna Kumari B. Spandana
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
DECLARATION
I hereby declare that the results embodied in this dissertation entitled “CAR
NUMBER PLATE RECOGNITION” is carried out by me during the year 2008-09 in
partial fulfillment of the requirements of the award of degree, Bachelor of Engineering in
Electronics and Communication Engineering from M.V.S.R Engineering College,
affiliated to Osmania University, Hyderabad.
I have not been submitted the same to any other university or organization for
award of any other degree or diploma.
D. Keerthi K. Aruna Kumari B. Spandana
ACKNOWLEDGEMENTS
The satisfaction and euphoria that accompany the successful completion of any
task would be, but incomplete without the mention of the people who made it possible,
whose constant guidance and encouragement have crowned our efforts with success.
We express our sincere thanks and gratitude to our external guide
Mr. K. Rambabu Director of Laser systems (RESEARCH CENTRE IMARAT).
We are extremely indebted to our internal guide, Mr. Sudhir Dakey for his
valuable help, and would like to express our profound gratitude towards his for providing
all facilities to implement this project in the college and for his sagacious guidance
through out the project in the college and also through out our college period.
We would like express our deep felt gratitude to Dr. P.A. Sastry, Principal of
M.V.S.R Engineering College for his kind co-operation and valuable suggestions.
We would like to take this opportunity to express our heart-felt gratitude to our
H.O.D. Dr. B. Hari Kumar for providing the necessary infrastructure to complete this
project.
We also thank the staff of the ECE department who helped us morally for the
successful completion of this project.
RCI PROFILE
The Research Centre Imarat (RCI) was established by A.P.J. Abdul Kalam in
1988 on a campus 8 km from Defence Research and Development Laboratory [DRDL] at
Kanchanbagh, Hyderabad. The center's state-of-the-art facilities are dedicated to work in
advanced missile technologies.
The Research Center Imarat complex is primarily associated with research and
development of technologies for missiles, aircraft and other advanced weapons,
Development activities at RCI include the Light Combat Aircraft as well as the missile
programs. The research conducted at RCI in areas such as materials, electronics and
software provided the base on which an ambitious missile program could be successfully
constructed.
Work conducted at RCI also includes specialties such as automated test systems,
data acquisition, analysis, control electronics, digital signal processing, quality control of
high reliability electronic packages, gyro systems, environmental testing, and integration
of multistage aerospace vehicles. Activities range from software operations, navigational
checks, sensor interface and calibration, to environmental and integration check-outs.
Typical projects include development of a data acquisition system for surface to air
missile ground segment.
The RCI is one of the nodal laboratories that are involved in developing light-
weight composite material for the missiles developed by the Defence Research and
Development Organization. RCI's Composite Product and Development Centre (CPDC)
is also working on uses of high-tech material for social applications, such as light-weight
artificial limbs.
ABSTRACT
Car Number Plate Recognition System means to extract the number plate
characters in ASCII format from the image. The aim of the project is to provide traffic
management, control and other related applications
This system takes a vehicle image of any size breaks it into smaller image pieces.
These pieces are then analyzed to locate the exact location of number plate in the image.
Once the area of the number plate (its x and y coordinates) is found the plate is parsed to
extract the character from it. These characters are then given to the Optical Character
Recognition (OCR) module. OCR program recognizes those characters and converts
them to ASCII format.
The technique used in finding the exact location of number plate in the vehicle
image is signature technique. The plate thus obtained is given to the OCR module. The
goal of Optical Character Recognition is to classify optical patterns (often contained in a
digital image) corresponding to alphanumeric or other characters. The process of OCR
involves several steps including segmentation, feature extraction, and classification.
Templates are 2D correlated to extract the characters.
CAR NUMBER PLATE RECOGNITION
CONTENTS
LIST OF FIGURES iv
LIST OF TABLES vi
I. INTRODUCTION 1
1.1 Introduction 1
1.2 Aim Of The Project 2
1.3 History 3
1.4 Working 3
1.5 Algorithm 4
1.6 Conclusion 4
II. IMPLEMENTATION TOOL – MATLAB 5
2.1 Introduction 5
2.2 MATLAB 5
2.3 MATLAB Systems 6
2.4 Graphics and Visualization 9
2.5 Features 9
2.6 M files 11
2.7 Images in MATLAB 11
2.8 Working with Images in MATLAB 12
2.9 Graphical User Interface 12
2.10 GUI Working 13
i
2.11 Defining User Interface Controls 14
2.12 Guide: An Overview 23
2.13 Guide Tools Summary 24
2.14 Conclusion 24
III. PROJECT DESCRIPTION 25
3.1 Introduction 25
3.2 Digital Image 25
3.3 Digital Image Processing 25
3.4 Key Steps Involved in the Project 26
3.5 Techniques Used In the Project 27
3.6 Signature Technique 27
3.7 Optical Character Recognition (OCR) 28
3.8 Template Matching 29
3.9 Conclusion 31
IV. WORKING DESCRIPTION 32
4.1 Introduction 32
4.2 Algorithm 32
4.3 Flowchart Depicting the Operations of the System 33
4.4 Flow of Function Calls in the program 34
4.5 MATLAB Code 35
4.6 GUI Code 46
ii
4.7 Conclusion 51
V. ADVANTAGES, DISADVATAGES AND APPLICATIONS 52
5.1 Advantages 52
5.2 Disadvantages 52
5.3 Applications 53
VI. RESULTS & CONCLUSION 57
6.1 Results 57
6.2 Conclusion 63
6.3 Future Advancements 63
APPENDIX A 64
BIBLIOGRAPHY 76
LIST OF FIGURES
2.1 MATLAB Development Environment 7
2.2 Simple GUI 13
2.3 Property Inspector 14
iii
2.4 Push Button 15
2.3 Push Button with Image 16
2.6 Slider 16
2.7 Radio Button 17
2.8 Check Box 18
2.9 Edit Text Box 19
2.10 Static Text 20
2.11 Pop-up Menu 20
2.12 Toggle Button 21
2.13 Axes 22
2.14 Layout Editor 24
3.1 Segmented Character Of The Number Plate 30
3.2 Template Image 30
3.3 Result Of Correlation 31
4.1 Flowchart Depicting The Operations Of The System 33
4.2 Flow Of Function calls In The Program 34
6.1 Input Image To Tmain 57
6.2 Binarised Image Of Input Image 58
6.3 Row wise Segmentation Of The Binarised Image 59
6.4 High Frequency Areas Of The Image 60
6.5 Number Plate From The Input Image 61
iv
6.6 Segmented Characters Of The Number Plate 62
A.1 Pixel Coordinate System 66
A.2 Spatial Coordinate System 67
A.3 Binary Image 69
A.4 Intensity Image 70
A.5 Indexed Image 71
A.6 RGB Image 72
LIST OF TABLES
8.1 Data Classes Supported By IPT Functions 68
8.2 Image Types And Data classes 73
8.3 Image Type conversion Functions 74
v
vi
CHAPTER I
INTRODUCTION
1.1 INTRODUCTION
“Car Number Plate Recognition” system uses Optical Character Recognition
(OCR) software to convert images of vehicle registration numbers into information for
real time or retrospective matching with law enforcement and other databases. This
system is an integrated hardware-software device that reads the vehicles number plate
and outputs the number plate number in ASCII - to some data processing system. This
system is also known as License Plate Recognition (LPR) and Automatic License Plate
Recognition (ALPR) systems.
It is believed that there are currently more than half a billion cars on the roads
worldwide. All those vehicles have their Vehicle Identification Number as their primary
identifier. The vehicle identification number is actually a license number which states a
legal license to participate in the public traffic. All vehicle world-wide should have its
license number - written on a license plate - mounted onto its body (at least at the back
side) and no vehicle without properly mounted, well visible and well readable license
plate should run on the roads.
The license number is the most important identification data a computer system
should treat when dealing with vehicles. If the data is already in the computer most of
these tasks are rather easy to be carried out.
Suppose a company's security manager would require a system that precisely tells
at every moment where the cars of the company are: in the garage or out on roads. By
registering every single drive-out from and drive-in to the garage, the system could
always tell which car is out and which is in. The key issue of this task is that the
registration of the movement of the vehicles should be done automatically by the system,
otherwise it would require manpower.
1
Concisely, Car Number Plate Recognition is automation of data input, where data
equals the registration number of the vehicle. This system replaces, redeems the task of
manually typing the plate number of the bypassing vehicle into the computer system.
1.2 AIM OF THE PROJECT
The aim of the project is to develop an efficient Car Number Plate Recognition
System for necessary applications.
The scope of the project is broadly categorized into modules as follows:
Number Plate Recognition
Templates
Templates Management
1.3 HISTORY
The Car Number Plate Recognition System was invented in 1976 at the Police
Scientific Development Branch in the UK. Prototype systems were working by 1979 and
contracts were let to produce industrial systems, first at EMI Electronics then at
Computer Recognition Systems (CRS) in Wokingham, UK. Early trial systems were first
used in Britain in 1979 with trial units placed on the A1 road and the Dartford tunnel. To
minimize errors, license plate's character font, positioning and sizes were optimized for
the character recognition systems used. The first arrest due to a detected stolen car was
made in 1981.
Early CNPR systems were unable to read white or silver lettering on black
background, as permitted on UK vehicles built prior to 1973.
There are a number of other possible difficulties that the software must be able to
cope with. These include:
Poor image resolution, usually because the plate is too far away but sometimes
resulting from the use of a low-quality camera.
Blurry images, particularly motion blur
2
Poor lighting and low contrast due to overexposure, reflection or shadows
An object obscuring (part of) the plate, quite often a tow bar, or dirt on the plate
A different font, popular for vanity plates (some countries do not allow such plates,
eliminating the problem)
1.4 WORKING
As the vehicle approaches the secured area, and starts the cycle by stepping over a
magnetic loop detector (which is the most popular vehicle sensor). The loop
detector senses the presence of the car.
FIGURE 1.1
Now the illumination is activated and the camera (shown in the left side of the
gate) takes pictures of the front or rear plates. The images of the vehicle include
the plate.
FIGURE 1.2
Our project (CNPR System) reads the pixel information of this vehicle image and
breaks it into smaller image pieces. These pieces are then analyzed to locate the 3
exact location of number plate in the image. Once the area of the number plate (its
x and y coordinates) is found the plate is parsed to extract the character from it.
These characters are then given to the OCR module. OCR program recognizes
those characters and coverts them to text format.
FIGURE 1.3
Once
the car number was obtained it can be used according to the application.
1.5 ALGORITHM
This system takes a vehicle image of any size.
Breaks it into smaller image pieces.
These pieces are then analyzed to locate the exact location of number plate in the
image.
Once the area of the number plate (its x and y coordinates) is found the plate is
parsed to extract the character from it.
These characters are then recognized and converted to ASCII text format.
1.6 CONCLUSION
There are frequent situations in which a system able to recognize registration
numbers. Our project deals with the identification of the characters from the image of the
car (containing number plate). The basic ideas of the project are discussed in brief.
4
CHAPTER II
IMPLEMENTATION TOOL - MATLAB
2.1 INTRODUCTION
This chapter discusses the implementation software, MATLAB used in the
project. This project is also implemented in GUI (Graphical User Interface). This chapter
also discusses main features of GUI..
2.2 MATLAB
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming in an easy-to-use environment where
problems and solutions are expressed in familiar mathematical notation. Typical uses
include:
•Math and computation
•Algorithm development
•Modeling, simulation, and prototyping
•Data analysis, exploration, and visualization
•Scientific and engineering graphics
•Application development, including graphical user interface building
MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would
take to write a program in a scalar noninteractive language such as C or FORTRAN. The
name MATLAB stands for Matrix Laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK
projects. Today, MATLAB uses software developed by the LAPACK and ARPACK
projects, which together represent the state-of-the-art in software for matrix computation.
5
MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses
in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for
high-productivity research, development, and analysis.
MATLAB features a family of add-on application-specific solutions called
toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and
apply specialized technology. Toolboxes are comprehensive collections of MATLAB
functions (M-files) that extend the MATLAB environment to solve particular classes of
problems. Areas in which toolboxes are available include image processing, signal
processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and
many others.
2.3 MATLAB SYSTEM
The MATLAB system consists of five main parts:
Development Environment
MATLAB Mathematical Function Library
MATLAB Language
Handle Graphics
MATLAB Application Program Interface (API).
Development Environment
This is the set of tools and facilities that help you use MATLAB functions and
files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop
and Command Window, a command history, and browsers for viewing help, the
workspace, files, and the search path.
6
FIGURE 2.1 MATLAB Development Environment
MATLAB Mathematical Function Library
This is a vast collection of computational algorithms ranging from elementary
functions like sum, sine, cosine and complex arithmetic, to more sophisticated functions
like matrix inverse, matrix eigen values, Bessel functions and Fourier transforms.
7
MATLAB language
This is a high-level matrix/array language with control flow statements,
functions, data structures, input/output, and object-oriented programming features. It
allows both “programming in the small” to rapidly create quick and dirty throw-away
programs, and “programming in the large” to create complete large and complex
application programs.
Handle Graphics
This is the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level commands that allow you to fully
customize the appearance of graphics as well as to build complete graphical user
interfaces on your MATLAB applications.
MATLAB Application Program Interface (API)
This is a library that allows you to write C and FORTRAN programs that interact
with MATLAB. It include facilities for calling routines from MATLAB (dynamic
linking), calling MATLAB as a computational engine, and for reading and writing MAT-
files.
Our Image processing laboratory based on MATLAB has the capability to perform the
following tasks:
1. Perform algebraic operations such as addition, subtraction, multiplication, and
division. These operations can be used to perform operations on images such as noise
reduction by using averages, movement detection, and algebraic masking.
2. Geometric transformations such as translation, rotation, and scaling
3. Space domain operations such as histogram modification (scaling, offset, amplitude
change) non linear point operations (absolute value, squaring, square root, log scale
function pushbutton1_Callback(hObject, eventdata, handles)
global file;
Tmain(file,1);
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global file;
Tmain(file,2);
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
50
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global file;
Tmain(file,3);
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
global file;
Tmain(file,4);
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
global file;
Tmain(file,5);
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
global file;
Tmain(file,6);
51
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
global file;
Tmain(file,7);
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data
4.7 CONCLUSION
This chapter discussed flow of function calls in the MATLAB code. MATLAB
Code and GUI code with comments is also given. Tmain is the main function. ImBin
converts the image to binary. NoBlack gives the coordinates of the number plate in the
image. Plate gives the final output of characters of the number plate in ASCII format.
52
CHAPTER V
ADVANTAGES, DISADVANTAGES & APPLICATIONS
5.1 ADVANTAGES
Simple and easy to implement
Good performance
Translation-invariant
The CNPR system significant advantage is that the system can keep an image
record of the vehicle which is useful in order to fight crime and fraud ("an image is worth
a thousand words"). An additional camera can focus on the driver face and save the
image for security reasons. Additionally, this technology does not need any installation
per car (such as in all the other technologies that require a transmitter added on each car
or carried by the driver).
5.2 DISADVANTAGES
Requires considerable tweaking to find the right templates
Not scale or rotation invariant.
Performance deteriorates rapidly for incomplete or noisy data
53
5.3 APPLICATIONS
Traffic Congestion Management (differential pricing for use of roads in a
precinct)
Traffic Speed Restrictions
Access Control.
Tolling
Border Control
Offender Identification (unregistered, uninsured, stolen vehicles, fake number
plates)
Criminal Intelligence (location of terrorism suspects and 'persons of interest to the
police')
Generation of blacklists of vehicles seeking fuel or other products from petrol
stations
5.3.1 Traffic Congestion
Traffic congestion schemes, of increasing significance in urban centres where
there are concerns about pollution or the capacity of streets to accommodate a large
number of vehicles during peak hours, seek to exclude classes of motor vehicles (for
example cars owned by non-residents) or to allow entry of vehicles on a selective basis
(e.g. at a particular time or subject to a financial penalty). In essence most schemes
involve charging for use of public streets and have thus proved to be controversial,
although sometimes supported by residents of the particular precinct.
This system has been used in such schemes to identify what vehicles are
traversing a location, on the basis that the technology is less "invasive" than electronic
tagging systems that require users to gain a RFID tag for the particular driver or vehicle.
The registration database is typically linked to a billing system, with this system being
used to identify 'authorized' vehicles (which have usually paid for the privilege of using
54
the local road network) and non-authorized vehicles, which are automatically issued with
a fine.
Given the speed of processing and sufficient cameras it is possible to develop highly
granular, time-specific and dynamic charging, e.g. different charges at various times of
the day, higher charges when pollution reaches particular levels.
5.3.2 Speed Restrictions
This system can also be used for automated enforcement of speed restrictions and
associated traffic codes, such as prohibitions on particular classes of vehicles (such as
those carrying explosives or chemical) using specific routes.
Speed restriction is mechanistic, with the this system 'logging' the vehicle at two
or more locations and determining whether transit between those points and times
breached speed limits. A billing database can then automatically issue a fine and/or alert
traffic police that a breach is underway.
5.3.3 Access Control
A gate automatically opens for authorized members in a secured area, thus
replacing or assisting the security guard. The events are logged on a database and could
be used to search the history of events.
5.3.4 Tolling
The car number is used to calculate the travel fee in a toll-road, or used to double-
check the ticket. In this installation, the plate is read when the vehicle enters the toll lane
and presents a pass card. The information of the vehicle is retrieved from the database
and compared against the pass information. In case of fraud the operator is notified.
5.3.5 Network Management
This is academic and official interest, although apparently few implementations,
in use of this system to identify how road networks are being used and thereby better
55
model future traffic flows or underpin intelligent transport systems (e.g. dynamic signage
and traffic signals that reflect loads on parts of the network).
5.3.6 Offender Identification
Law enforcement officials appear to have been more enthusiastic about the scope
for using this system in ‘offender identification’.
That encompasses such things as identification of
unregistered vehicles, i.e. vehicles with an expired number plate (significant
because most regimes prohibit driving of an unregistered vehicle but do not
require that 'unused' vehicles have a current plate)
uninsured vehicles (primarily in regimes where it is mandatory to insure a vehicle
through a government-controlled insurer)
stolen vehicles (i.e. where the thief takes the vehicle but does not change the
number plates)
vehicles with cloned plates (e.g. the same plates are identified on separate
vehicles in different locations at much the same time) or with bogus numbers (e.g.
there is no match with the vehicle register)
Vehicles engaged in activity such as unauthorized use of bus-only lanes.
Such identification can be tied to automated issue of a fine or summons to appear
before a magistrate. It can also be used in real time to alert law enforcement personnel to
intercept the suspect vehicle, for example to find and pull over a car that has been
reported as stolen.
5.3.7 Criminal Intelligence
Police, customs and other law enforcement officials are reluctant to tightly
circumscribe use of this system. As the following pages note there appears to be
56
considerable sharing of information by agencies and real time checking of plates against
multiple hotlists.
Such lists include vehicles –
Reported to have been involved in hit and run incidents, petrol thefts, drive by
shootings, burglaries and abductions
Reported as having been at the scene of a crime
Registered to suspected terrorists, family and associates
Rented using 'flagged' credit cards
Registered to suspected drug traffickers
Registered to suspected stalkers
In practice a wide range of people may be 'of interest to the police' (and their
peers); the major limit on real-time large scale ad hoc sorting based on this system is the
difficulty of linking different databases.
Blacklists and Whitelists
The preceding applications have primarily involved official ANPR (Automatic
Number Plate Recognition) systems, particularly those tied to one or more government
databases. It is important, however, to recognize that private ANPR schemes have been
established in many countries.
One Australian promoter for example has marketed a commercial ANPR network
to petrol stations, with individual stations capturing an image of the plate on each vehicle
entering those premises. The expectation is that if there is a 'drive off' (i.e. the driver
leaves the station without paying) the site manager will manually apply a 'flag' to the
corresponding license number on the station's database. If the vehicle returns to the site
57
an alarm will be sounded by the system and the cashier will disable the pump. That
blacklist can be shared with other stations via periodic exchange of information over the
promoter's server, a "feature that prevents an offending vehicle stealing fuel from a
different site every time".
Other vendors are promoting use of ANPR as an access control mechanism for
entry to a building or campus, with the vehicle's number plate replacing a proximity card
or other identifier.
CHAPTER VI
RESULTS & CONCLUSIONS
This chapter deals with the results obtained at the various stages of the project.
And the final output of the project in ASCII format.
6.1 RESULTS
STEP 1
Photograph of the car which contains number plate portion taken by CCTV
camera.
58
Size: 254x333
Bytes: Class: uint8 array
STEP 2
Binarised form of the above image, output of Imbin function. (If the image is binarised then most of the detail is lost from the image, leaving our area of interest more prominent.)
FIGURE 6.2 Binarised image of input image
59
FIGURE 6.1 Input image to Tmain
STEP 3
High frequency areas of the image to find the probable location of the number plate (Using row wise histogram)
60
FIGURE 6.3 Row wise segmentation of the Binarised Iimage
STEP 4
After column wise histogram (for the above obtained result)
61
FIGURE 6.4 High frequency areas of the image (after column wise segmentation)
STEP 5
Number plate
62
FIGURE 6.5 Number Plate from the Input Image ( Binarised Image)
STEP 6
Segmented characters from the above obtained number plate.
63
FIGURE 6.6 Segmented characters of the number plate
OUTPUT
Output of the system in ASCII format
GHW356K
6.2 CONCLUSION
64
As described in the project, this system provides characters of the car number
plate in ASCII format that can be used for various applications. This is a comprehensive
step providing traffic management, security, control and offender identification. This
technology is simple and does not need any installations on cars.
6.3 FUTURE ADVANCEMENTS
The software can be used along with camera to serve many applications and we can even make the system automatic
An additional camera can focus on the driver face and save the image for security reasons.
In order to reduce the execution time of the code this can be implemented using c/c++.
APPENDIX A
65
IMAGE PROCESSING TOOLBOX
INTRODUCTION
The Image Processing Toolbox is a collection of functions that extend the
capability of the MATLAB numeric computing environment. The toolbox supports a
wide range of image processing operations, including
Spatial image transformations
Morphological operations
Neighborhood and block operations
Linear filtering and filter design
Transforms Image analysis and enhancement
Image registration
Deblurring
Region of interest operations
Many of the toolbox functions are MATLAB M-files, a series of MATLAB
statements that implement specialized image processing algorithms.
The capabilities of the Image Processing Toolbox can be extended by writing user
defined M-files, or by using the toolbox in combination with other toolboxes, such as the
Signal Processing Toolbox and the Wavelet Toolbox
IMAGES IN MATLAB
The basic data structure in MATLAB is the array, an ordered set of real or
complex elements. This object is naturally suited to the representation of images, real-
valued ordered sets of color or intensity data. MATLAB stores most images as two-
dimensional arrays (i.e., matrices), in which each element of the matrix corresponds to a
single pixel in the displayed image. (Pixel is derived from picture element and usually
66
denotes a single dot on a computer display.) For example, an image composed of 200
rows and 300 columns of different colored dots would be stored in MATLAB as a 200-
by-300 matrix. Some images, such as RGB, require a three-dimensional array, where the
first plane in the third dimension represents the red pixel intensities, the second plane
represents the green pixel intensities, and the third plane represents the blue pixel
intensities. This convention makes working with images in MATLAB similar to working
with any other type of matrix data, and makes the full power of MATLAB available for
image processing applications.
For example, we can select a single pixel from an image matrix using normal
matrix subscripting. I (2, 15)
This command returns the value of the pixel at row 2, column 15 of the image I.
COORDINATE SYSTEMS
Locations in an image can be expressed in various coordinate systems, depending
on context. This section discusses the two main coordinate systems used in the Image
Processing Toolbox and the relationship between them. These two coordinate systems are
described in
Pixel Coordinates
Spatial Coordinates
Pixel Coordinates
Generally, the most convenient method for expressing locations in an image is to
use pixel coordinates. In this coordinate
system, the image is treated as a grid
of discrete elements, ordered from top
to bottom and left to right, as
illustrated by the following figure.
67
FIGURE. A.1 Pixel Coordinate System
For pixel coordinates, the first component r (the row) increases downward,
while the second component c (the column) increases to the right. Pixel coordinates are
integer values and range between 1 and the length of the row or column. There is a one-
to-one correspondence between pixel coordinates and the coordinates MATLAB uses for
matrix subscripting. This correspondence makes the relationship between an image's data
matrix and the way the image is displayed easy to understand. For example, the data for
the pixel in the fifth row, second column is stored in the matrix element (5, 2).
Spatial Coordinates
In the pixel coordinate system, a pixel is treated as a discrete unit, uniquely
identified by a single coordinate pair, such as (5, 2). From this perspective, a location
such as (5.3,2.2) is not meaningful. At times, however, it is useful to think of a pixel as a
square patch. From this perspective, a location such as (5.3, 2.2) is meaningful, and is
distinct from (5, 2). In this spatial coordinate system, locations in an image are positions
on a plane, and they are described in terms of x and y (not r and c as in the pixel
coordinate system). The following figure illustrates the spatial coordinate system used for
images. Notice that y increases
68
FIGURE A.2 Spatial Coordinate System
Differences between Pixels Coordinate System and Spatial Coordinate System
There are some important differences, however. In pixel coordinates, the upper
left corner of an image is (1, 1), while in spatial coordinates, this location by default is
(0.5, 0.5). This difference is due to the pixel coordinate system's being discrete, while the
spatial coordinate system is continuous. Also, the upper left corner is always (1, 1) in
pixel coordinates, but you can specify a nondefault origin for the spatial coordinate
system. See Using a Nondefault Spatial Coordinate System for more information.
STORAGE CLASSES SUPPORTED BY MATLAB AND IPT
Images are most commonly stored in MATLAB using the logical, uint8, uint16
and double data types. By default, MATLAB stores most data in arrays of class double.
The data in these arrays is stored as double-precision (64-bit) floating-point numbers. All
MATLAB functions work with these arrays.
For image processing, however, this data representation is not always ideal. The
number of pixels in an image can be very large. To reduce memory requirements,
69
MATLAB supports storing image data in arrays as 8-bit or 16-bit unsigned integers, class
uint8 and uint16. These arrays require one eighth as much memory as double arrays and
can perform many standard MATLAB array manipulations.
The data classes listed in the below table are supported by most IPT functions.
Data Class Description
Double Double-precision, floating point numbers in the approximate range
-10^308 to 10 ^308 (8 bytes per element).
Unit8 Unsigned 8-bit integers in the range [0,255] (1 byte per element).
Unit16 Unsigned 16-bit integers in the range [0, 65535] (2 bytes per
element).
Unit32 Unsigned 32-bit integers in the range [0, 4294967295] (4 bytes per
element).
Int8 Signed 8-bit integers in the range [-128, 127] (1 byte per element).
Int16 Signed 16-bit integers in the range [-32768, 32767] (2 bytes per
element).
Int32 Signed 32-bit integers in the range [-2147483648, 2147483647] (4
bytes per element).
Single Single-precision, floating point numbers in the approximate range -
10^38 to 10 ^38 (4 bytes per element).
Char Characters (2 bytes per element)
Logical Values are 0 or 1 (1 byte per element)
TABLE A.1 Data Classes supported by IPT functions
70
Certain MATLAB functions, including the find, all, any, conv2, convn, fft2, fftn,
and sum functions, accept uint8 or uint16 data but return data in double-precision format.
TYPES OF DIGITAL IMAGES
The Image Processing Toolbox supports four basic types of images:
Binary Images
Intensity Images
Indexed Images
RGB (True Colour) Images
Binary Images
In a binary image, each pixel assumes one of only two discrete values.
Essentially, these two values correspond to on and off. A binary image is stored as a
logical array of 0's (off pixels) and 1's (on pixels).
FIGURE A.3 Binary Image
71
Intensity Images
An intensity image is a data matrix, I, whose values represent intensities within
some range. MATLAB stores an intensity image as a single matrix, with each element of
the matrix corresponding to one image pixel. The matrix can be of class double, uint8, or
uint16.While intensity images are rarely saved with a colormap, MATLAB uses a
colormap to display them. The elements in the intensity matrix represent various
intensities, or gray levels, where the intensity 0 usually represents black and the intensity
1, 255, or 65535 usually represents full intensity, or white.
FIGURE A.4 Intensity Image
Indexed Image
An indexed image consists of a data matrix, X, and a colormap matrix, map. The
data matrix can be of class uint8, uint16, or double. The colormap matrix is an m-by-3
array of class double containing floating-point values in the range [0,1]. Each row of map
specifies the red, green, and blue components of a single color. An indexed image uses
direct mapping of pixel values to colormap values. The color of each image pixel is
determined by using the corresponding value of X as an index into map. The value 1
points to the first row in map, the value 2 points to the second row, and so on.
72
FIGURE A.5 Indexed Image
RGB (True Colour) images
An RGB image, sometimes referred to as a true-color image, is stored in
MATLAB as an m-by-n-by-3 data array that defines red, green, and blue color
components for each individual pixel. RGB images do not use a palette. The color of
each pixel is determined by the combination of the red, green, and blue intensities stored
in each color plane at the pixel's location. Graphics file formats store RGB images as 24-
bit images, where the red, green, and blue components are 8 bits each. This yields a
potential of 16 million colors. The precision with which a real-life image can be
replicated has led to the commonly used term true-color image. An RGB array can be of
class double, uint8, or uint16. In an RGB array of class double, each color component is a
value between 0 and 1. A pixel whose color components are (0, 0, 0) is displayed as
black, and a pixel whose color components are (1, 1, 1) is displayed as white. The three
color components for each pixel are stored along the third dimension of the data array.
73
For example, the red, green, and blue color components of the pixel (10,5) are stored in
RGB(10,5,1), RGB(10,5,2), and RGB(10,5,3), respectively.
FIGURE A.6 RGB (True Colour) Image
Multiframe image arrays
For some applications, you might need to work with collections of images related
by time or view, such as magnetic resonance imaging (MRI) slices or movie frames. The
Image Processing Toolbox provides support for storing multiple images in the same
array. Each separate image is called a frame. If an array holds multiple frames, they are
concatenated along the fourth dimension. For example, an array with five 400-by-300
RGB images would be 400-by-300-by-3-by-5. A similar multiframe intensity or indexed
image would be 400-by-300-by-1-by-5. Use the cat command to store separate images in
one multiframe array. For example, if you have a group of images A1, A2, A3, A4, and
A5, you can store them in a single array using A = cat(4,A1,A2,A3,A4,A5)
74
We can also extract frames from a multiframe image. For example, if you have a
multiframe image MULTI, this command extracts the third frame. FRM3 = MULTI (:,:,:,
3)
Note that, in a multiframe image array, each image must be the same size and
have the same number of planes. In a multiframe indexed image, each image must be the
same size and have the same number of planes. In a multiframe indexed image, each
image must also use the same colormap.
SUMMARY OF IMAGE TYPES AND DATA CLASSES
Image Type Data Class Interpretation
Binary logical Array of zeros (0) and ones (1)
Indexed double Array of integers in the range [1, p]. The associated colormap is a p-by-3 array of floating-point values in the range [0, 1]
uint8 or uint16 Array of integers in the range [0, p-1]. The associated colormap is a p-by-3 array of floating-point values in the range [0, 1].
Intensity double Array of floating-point values. The typical range of values is [0, 1]. The associated colormap, typically grayscale, is a p-by-3 array of floating-point values in the range [0, 1].
uint8 or uint16 Array of integers. The typical range of values is [0, 255] or [0, 65535]. The associated colormap, typically grayscale, is a p-by-3 array of floating-point values in the range [0, 1].
RGB (true-color)
double m-by-n-by-3 array of floating-point values in the range [0, 1]
uint8 or uint16 m-by-n-by-3 array of integers in the range [0, 255] or [0, 65535]75
TABLE A.2 Image Types and Numeric Classes
IMAGE TYPE CONVERSION FUNCTIONS
For certain operations, it is helpful to convert an image to a different image type
Function Description
dither Create a binary image from a grayscale intensity image by dithering; create an indexed image from an RGB image by dithering
gray2ind Create an indexed image from a grayscale intensity image
grayslice Create an indexed image from a grayscale intensity image by thresholding
im2bw Create a binary image from an intensity image, indexed image, or RGB image, based on a luminance threshold
ind2gray Create a grayscale intensity image from an indexed image
ind2rgb Create an RGB image from an indexed image
mat2gray Create a grayscale intensity image from data in a matrix, by scaling the data
76
TABLE A.3 Image Type conversion Functions
IMAGE ARITHMETIC
Image arithmetic is the implementation of standard arithmetic operations, such as
addition, subtraction, multiplication, and division, on images. Image arithmetic has many
uses in image processing both as a preliminary step in more complex operations and by
itself. For example, image subtraction can be used to detect differences between two or
more images of the same scene or object. we can do image arithmetic using the
MATLAB arithmetic operators. The Image Processing Toolbox also includes a set of
functions that implement arithmetic operations for all numeric, nonsparse data types. The
toolbox arithmetic functions accept any numeric data type, including uint8, uint16, and
double, and return the result image in the same format. The functions perform the 77
operations in double precision, on an element-by-element basis, but do not convert
images to double-precision values in the MATLAB workspace. Overflow is handled
automatically. The functions truncate return values to fit the data type.
Image Arithmetic Truncation Rules
The results of integer arithmetic can easily overflow the data type allotted for
storage. For example, the maximum value you can store in uint8 data is 255. Arithmetic
operations can also result in fractional values, which cannot be represented using integer
arrays. The image arithmetic functions use these rules for integer arithmetic: Values that
exceed the range of the integer type are truncated to that range. Fractional values are
rounded. For example, if the data type is uint8, results greater than 255 (including Inf) are
set to 255.
BIBLIOGRAPHY
1. Automatic Number Plate Recognition – Universty of Trás-os-Montes e Alto Douro - Vila Real – Portugal.
2. CARINA - Software Product for Automatic Number Plate Recognition – Budapest – Hungary.
3. Real-time number plate reading, J. Bulas-Cruz , J. Barroso, A Rafaele E. L. dagless
4. http://www.mathworks.com/
5. Digital Image Processing Using MATLAB 2nd Edition By Rafael C. Gonzalez, Richard E. Woods and Steven L. Eddins