[go: up one dir, main page]

0% found this document useful (0 votes)
25 views63 pages

Imageprocessing

The document provides an introduction to image processing, defining an image as a two-dimensional representation that can be captured by various optical devices. It discusses image file sizes, formats, and the fundamental steps in digital image processing, including acquisition, enhancement, restoration, and segmentation. Additionally, it highlights the importance of color processing, compression techniques, and the role of knowledge bases in image processing systems.

Uploaded by

avprasanna1991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views63 pages

Imageprocessing

The document provides an introduction to image processing, defining an image as a two-dimensional representation that can be captured by various optical devices. It discusses image file sizes, formats, and the fundamental steps in digital image processing, including acquisition, enhancement, restoration, and segmentation. Additionally, it highlights the importance of color processing, compression techniques, and the role of knowledge bases in image processing systems.

Uploaded by

avprasanna1991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

INTRODUCTION TO IMAGE PROCESSING

INTRODUCTION

3.1 IMAGE:

An image is a two-dimensional picture, which has a similar appearance to some subject


usually a physical object or a person.

Image is a two-dimensional, such as a photograph, screen display, and as well as a three-


dimensional, such as a statue. They may be captured by optical devices—such as cameras,
mirrors, lenses, telescopes, microscopes, etc. and natural objects and phenomena, such as the
human eye or water surfaces.

The word image is also used in the broader sense of any two-dimensional figure such as a
map, a graph, a pie chart, or an abstract painting. In this wider sense, images can also be
rendered manually, such as by drawing, painting, carving, rendered automatically by printing or
computer graphics technology, or developed by a combination of methods, especially in a
pseudo-photograph.
Fig

An image is a rectangular grid of pixels. It has a definite height and a definite width
counted in pixels. Each pixel is square and has a fixed size on a given display. However different
computer monitors may use different sized pixels.The pixels that constitute an image are ordered
as a grid (columns and rows); each pixel consists of numbers representing magnitudes of
brightness and color.

Fig 3.1

Each pixel has a color. The color is a 32-bit integer. The first eight bits determine the
redness of the pixel, the next eight bits the greenness, the next eight bits the blueness, and the
remaining eight bits the transparency of the pixel.
Fig

3.2 IMAGE FILE SIZES:

Image file size is expressed as the number of bytes that increases with the number of
pixels composing an image, and the color depth of the pixels. The greater the number of rows
and columns, the greater the image resolution, and the larger the file. Also, each pixel of an
image increases in size when its color depth increases, an 8-bit pixel (1 byte) stores 256 colors, a
24-bit pixel (3 bytes) stores 16 million colors, the latter known as true color.

Image compression uses algorithms to decrease the size of a file. High resolution cameras
produce large image files, ranging from hundreds of kilobytes to megabytes, per the camera's
resolution and the image-storage format capacity. High resolution digital cameras record 12
megapixel (1MP = 1,000,000 pixels / 1 million) images, or more, in true color. For example, an
image recorded by a 12 MP camera; since each pixel uses 3 bytes to record true color, the
uncompressed image would occupy 36,000,000 bytes of memory, a great amount of digital
storage for one image, given that cameras must record and store many images to be practical.
Faced with large file sizes, both within the camera and a storage disc, image file formats were
developed to store such large images.

3.3 IMAGE FILE FORMATS:


Image file formats are standardized means of organizing and storing images. This entry is
about digital image formats used to store photographic and other images. Image files are
composed of either pixel or vector (geometric) data that are rasterized to pixels when displayed
(with few exceptions) in a vector graphic display.Including proprietary types, there are hundreds
of image file types. The PNG, JPEG, and GIF formats are most often used to display images on
the Internet.

Fig

In addition to straight image formats, Metafile formats are portable formats which can
include both raster and vector information.The metafile format is an intermediate format. Most
Windows applications open metafiles and then save them in their own native format.

3.3.1 RASTER FORMATS:

These formats store images as bitmaps (also known as pixmaps).

 JPEG/JFIF:

JPEG (Joint Photographic Experts Group) is a compression method. JPEG compressed


images are usually stored in the JFIF (JPEG File Interchange Format) file format. JPEG
compression is lossy compression. Nearly every digital camera can save images in the
JPEG/JFIF format, which supports 8 bits per color (red, green, blue) for a 24-bit total, producing
relatively small files. Photographic images may be better stored in a lossless non-JPEG format if
they will be re-edited, or if small "artifacts" are unacceptable. The JPEG/JFIF format also is used
as the image compression algorithm in many Adobe PDF files.

 EXIF:

The EXIF (Exchangeable image file format) format is a file standard similar to the JFIF
format with TIFF extensions. It is incorporated in the JPEG writing software used in most
cameras. Its purpose is to record and to standardize the exchange of images with image
metadata between digital cameras and editing and viewing software. The metadata are recorded
for individual images and include such things as camera settings, time and date, shutter speed,
exposure, image size, compression, name of camera, color information, etc. When images are
viewed or edited by image editing software, all of this image information can be displayed.

 TIFF:

The TIFF (Tagged Image File Format) format is a flexible format that normally saves 8
bits or 16 bits per color (red, green, blue) for 24-bit and 48-bit totals, respectively, usually using
either the TIFF or TIF filename extension. TIFFs are lossy and lossless. Some offer relatively
good lossless compression for bi-level (black & white) images. Some digital cameras can save in
TIFF format, using the LZW compression algorithm for lossless storage. TIFF image format is
not widely supported by web browsers. TIFF remains widely accepted as a photograph file
standard in the printing business. TIFF can handle device-specific color spaces, such as the
CMYK defined by a particular set of printing press inks.

 PNG:

The PNG (Portable Network Graphics) file format was created as the free, open-source
successor to the GIF. The PNG file format supports true color (16 million colors) while the GIF
supports only 256 colors. The PNG file excels when the image has large, uniformly colored
areas. The lossless PNG format is best suited for editing pictures, and the lossy formats, like
JPG, are best for the final distribution of photographic images, because JPG files are smaller than
PNG files. PNG, an extensible file format for the lossless, portable, well-compressed storage of
raster images. PNG provides a patent-free replacement for GIF and can also replace many
common uses of TIFF. Indexed-color, grayscale, and true color images are supported, plus an
optional alpha channel. PNG is designed to work well in online viewing applications, such as the
World Wide Web. PNG is robust, providing both full file integrity checking and simple detection
of common transmission errors.

 GIF:

GIF (Graphics Interchange Format) is limited to an 8-bit palette, or 256 colors. This
makes the GIF format suitable for storing graphics with relatively few colors such as simple
diagrams, shapes, logos and cartoon style images. The GIF format supports animation and is still
widely used to provide image animation effects. It also uses a lossless compression that is more
effective when large areas have a single color, and ineffective for detailed images or dithered
images.

 BMP:
The BMP file format (Windows bitmap) handles graphics files within the Microsoft
Windows OS. Typically, BMP files are uncompressed, hence they are large. The advantage is
their simplicity and wide acceptance in Windows programs.

3.3.2 VECTOR FORMATS:

As opposed to the raster image formats above (where the data describes the
characteristics of each individual pixel), vector image formats contain a geometric description
which can be rendered smoothly at any desired display size.

At some point, all vector graphics must be rasterized in order to be displayed on digital
monitors. However, vector images can be displayed with analog CRT technology such as that
used in some electronic test equipment, medical monitors, radar displays, laser shows and early
video games. Plotters are printers that use vector data rather than pixel data to draw graphics.

 CGM:

CGM (Computer Graphics Metafile) is a file format for 2D vector graphics, raster
graphics, and text. All graphical elements can be specified in a textual source file that can be
compiled into a binary file or one of two text representations. CGM provides a means of graphics
data interchange for computer representation of 2D graphical information independent from any
particular application, system, platform, or device.

 SVG:
SVG (Scalable Vector Graphics) is an open standard created and developed by the World
Wide Web Consortium to address the need for a versatile, scriptable and all purpose vector
format for the web and otherwise. The SVG format does not have a compression scheme of its
own, but due to the textual nature of XML, an SVG graphic can be compressed using a program
such as gzip.

3.4 IMAGE PROCESSING:

Digital image processing, the manipulation of images by computer, is relatively recent


development in terms of man’s ancient fascination with visual stimuli. In its short history, it has
been applied to practically every type of images with varying degree of success. The inherent
subjective appeal of pictorial displays attracts perhaps a disproportionate amount of attention
from the scientists and also from the layman. Digital image processing like other glamour fields,
suffers from myths, mis-connect ions, mis-understandings and mis-information. It is vast
umbrella under which fall diverse aspect of optics, electronics, mathematics, photography
graphics and computer technology. It is truly multidisciplinary endeavor ploughed with
imprecise jargon.

Several factor combine to indicate a lively future for digital image processing. A major
factor is the declining cost of computer equipment. Several new technological trends promise to
further promote digital image processing. These include parallel processing mode practical by
low cost microprocessors, and the use of charge coupled devices (CCDs) for digitizing, storage
during processing and display and large low cost of image storage arrays.

3.5 FUNDAMENTAL STEPS IN DIGITAL IMAGE PROCESSING:


Fi
g

3.5.1 Image Acquisition:

Image Acquisition is to acquire a digital image. To do so requires an image sensor and


the capability to digitize the signal produced by the sensor. The sensor could be monochrome or
color TV camera that produces an entire image of the problem domain every 1/30 sec. the image
sensor could also be line scan camera that produces a single image line at a time. In this case, the
objects motion past the line.
Fig

Scanner produces a two-dimensional image. If the output of the camera or other imaging
sensor is not in digital form, an analog to digital converter digitizes it. The nature of the sensor
and the image it produces are determined by the application.

Fig

3.5.2 Image Enhancement:

Image enhancementis among the simplest and most appealing areas of digital image
processing. Basically, the idea behind enhancement techniques is to bring out detail that is
obscured, or simply to highlight certain features of interesting an image. A familiar example of
enhancement is when we increase the contrast of an image because “it looks better.” It is
important to keep in mind that enhancement is a very subjective area of image processing.

Fig

3.5.3 Image restoration:


Image restorationis an area that also deals with improving the appearance of an image.
However, unlike enhancement, which is subjective, image restoration is objective, in the sense
that restoration techniques tend to be based on mathematical or probabilistic models of image
degradation.

Fig

Enhancement, on the other hand, is based on human subjective preferences regarding


what constitutes a “good” enhancement result. For example, contrast stretching is considered an
enhancement technique because it is based primarily on the pleasing aspects it might present to
the viewer, where as removal of image blur by applying a deblurring function is considered a
restoration technique.

3.5.4 Color image processing:

The use of color in image processing is motivated by two principal factors. First, color is
a powerful descriptor that often simplifies object identification and extraction from a scene.
Second, humans can discern thousands of color shades and intensities, compared to about only
two dozen shades of gray. This second factor is particularly important in manual image analysis.
Fig

3.5.5 Wavelets and multiresolution processing:

Wavelets are the formation for representing images in various degrees of resolution.
Although the Fourier transform has been the mainstay of transform based image processing since
the late1950’s, a more recent transformation, called the wavelet transform, and is now making it
even easier to compress, transmit, and analyze many images. Unlike the Fourier transform,
whose basis functions are sinusoids, wavelet transforms are based on small values, called
Wavelets, of varying frequency and limited duration.

Fig

Wavelets were first shown to be the foundation of a powerful new approach to signal
processing and analysis called Multiresolutiontheory. Multiresolution theory incorporates and
unifies techniques from a variety of disciplines, including sub band coding from signal
processing, quadrature mirror filtering from digital speech recognition, and pyramidal image
processing.

3.5.6 Compression:

Compression, as the name implies, deals with techniques for reducing the storage
required saving an image, or the bandwidth required for transmitting it. Although storage
technology has improved significantly over the past decade, the same cannot be said for
transmission capacity. This is true particularly in uses of the Internet, which are characterized by
significant pictorial content. Image compression is familiar to most users of computers in the
form of image file extensions, such as the jpg file extension used in the JPEG (Joint
Photographic Experts Group) image compression standard.

3.5.7 Morphological processing:

Morphological processingdeals with tools for extracting image components that are
useful in the representation and description of shape. The language of mathematical morphology
is set theory. As such, morphology offers a unified and powerful approach to numerous image
processing problems. Sets in mathematical morphology represent objects in an image. For
example, the set of all black pixels in a binary image is a complete morphological description of
the image.

Fig
In binary images, the sets in question are members of the 2-D integer space Z2, where
each element of a set is a 2-D vector whose coordinates are the (x,y) coordinates of a black(or
white) pixel in the image. Gray-scale digital images can be represented as sets whose
components are in Z3. In this case, two components of each element of the set refer to the
coordinates of a pixel, and the third corresponds to its discrete gray-level value.

3.5.8 Segmentation:

Segmentationprocedures partition an image into its constituent parts or objects. In


general, autonomous segmentation is one of the most difficult tasks in digital image processing.
A rugged segmentation procedure brings the process a long way toward successful solution of
imaging problems that require objects to be identified individually.

Fig

On the other hand, weak or erratic segmentation algorithms almost always guarantee
eventual failure. In general, the more accurate the segmentation, the more likely recognition is to
succeed.

3.5.9 Representation and description:

Representation and description almost always follow the output of a segmentation stage,
which usually is raw pixel data, constituting either the boundary of a region (i.e., the set of pixels
separating one image region from another) or all the points in the region itself. In either case,
converting the data to a form suitable for computer processing is necessary. The first decision
that must be made is whether the data should be represented as a boundary or as a complete
region. Boundary representation is appropriate when the focus is on external shape
characteristics, such as corners and inflections.

Regional representation is appropriate when the focus is on internal properties, such as


texture or skeletal shape. In some applications, these representations complement each other.
Choosing a representation is only part of the solution for transforming raw data into a form
suitable for subsequent computer processing. A method must also be specified for describing the
data so that features of interest are highlighted. Description, also called feature selection, deals
with extracting attributes that result in some quantitative information of interest or are basic for
differentiating one class of objects from another.

3.5.10 Object recognition:

The last stage involves recognition and interpretation. Recognition is the process that
assigns a label to an object based on the information provided by its descriptors. Interpretation
involves assigning meaning to an ensemble of recognized objects.

3.5.11 Knowledgebase:

Knowledge about a problem domain is coded into image processing system in the form of
a knowledge database. This knowledge may be as simple as detailing regions of an image when
the information of interests is known to be located, thus limiting the search that has to be
conducted in seeking that information. The knowledge base also can be quite complex, such as
an inter related to list of all major possible defects in a materials inspection problem or an image
data base containing high resolution satellite images of a region in connection with change
deletion application. In addition to guiding the operation of each processing module, the
knowledge base also controls the interaction between modules. The system must be endowed
with the knowledge to recognize the significance of the location of the string with respect to
other components of an address field. This knowledge glides not only the operation of each
module, but it also aids in feedback operations between modules through the knowledge base.
We implemented preprocessing techniques using MATLAB.

3.6 COMPONENTS OF AN IMAGE PROCESSING SYSTEM:

As recently as the mid-1980s, numerous models of image processing systems being sold
throughout the world were rather substantial peripheral devices that attached to equally
substantial host computers. Late in the 1980s and early in the 1990s, the market shifted to image
processing hardware in the form of single boards designed to be compatible with industry
standard buses and to fit into engineering workstation cabinets and personal computers. In
addition to lowering costs, this market shift also served as a catalyst for a significant number of
new companies whose specialty is the development of software written specifically for image
processing.
Network

Image displays computer Mass storage

Specialized
Image processing
Hard copy image processing
software
hardware

Image sensor

Problem domain

Fig

Although large-scale image processing systems still are being sold for massive imaging
applications, such as processing of satellite images, the trend continues toward miniaturizing and
blending of general-purpose small computers with specialized image processing hardware.
Figure 1.24 shows the basic components comprising a typical general-purpose system used for
digital image processing. The function of each component is discussed in the following
paragraphs, starting with image sensing.
 Image sensors:

With reference to sensing, two elements are required to acquire digital images. The first
is a physical device that is sensitive to the energy radiated by the object we wish to image. The
second, called a digitizer, is a device for converting the output of the physical sensing device into
digital form. For instance, in a digital video camera, the sensors produce an electrical output
proportional to light intensity. The digitizer converts these outputs to digital data.

 Specialized image processing hardware:

Specialized image processing hardware usually consists of the digitizer just mentioned,
plus hardware that performs other primitive operations, such as an arithmetic logic unit (ALU),
which performs arithmetic and logical operations in parallel on entire images. One example of
how an ALU is used is in averaging images as quickly as they are digitized, for the purpose of
noise reduction. This type of hardware sometimes is called a front-end subsystem, and its most
distinguishing characteristic is speed. In other words, this unit performs functions that require
fast data throughputs (e.g., digitizing and averaging video images at 30 frames) that the typical
main computer cannot handle.

 Computer:

The computer in an image processing system is a general-purpose computer and can


range from a PC to a supercomputer. In dedicated applications, sometimes specially designed
computers are used to achieve a required level of performance, but our interest here is on
general-purpose image processing systems. In these systems, almost any well-equipped PC-type
machine is suitable for offline image processing tasks.
 Image processing software:

Software for image processing consists of specialized modules that perform specific
tasks. A well-designed package also includes the capability for the user to write code that, as a
minimum, utilizes the specialized modules. More sophisticated software packages allow the
integration of those modules and general-purpose software commands from at least one
computer language.

 Mass storage:

Mass storage capability is a must in image processing applications. An image of size


1024*1024 pixels, in which the intensity of each pixel is an 8-bit quantity, requires one
megabyte of storage space if the image is not compressed. When dealing with thousands, or even
millions, of images, providing adequate storage in an image processing system can be a
challenge. Digital storage forimage processing applications fall into three principal categories:
(1) short-term storage for use during processing, (2) on-line storage for relatively fast recall, and
(3) archival storage, characterized by infrequent access. Storage is measured in bytes (eight bits),
Kbytes (one thousand bytes), Mbytes (one million bytes), Gbytes (meaning giga, or one billion,
bytes), and Tbytes (meaning tera, or one trillion, bytes).

One method of providing short-term storage is computer memory. Another is by


specialized boards, called frame buffers that store one or more images and can be accessed
rapidly, usually at video rates. The latter method allows virtually instantaneous image zoom, as
well as scroll (vertical shifts) and pan (horizontal shifts). Frame buffers usually are housed in the
specialized image processing hardware unit shown in Fig. 1.24. Online storage generally takes
the form of magnetic disks or optical-media storage. The key factor characterizing on-line
storage is frequent access to the stored data. Finally, archival storage is characterized by massive
storage requirements but infrequent need for access. Magnetic tapes and optical disks housed in
“jukeboxes” are the usual media for archival applications.
 Image displays:

Image displays in use today are mainly color (preferably flat screen) TV monitors.
Monitors are driven by the outputs of image and graphics display cards that are an integral part
of the computer system. Seldom are there requirements for image display applications that
cannot be met by display cards available commercially as part of the computer system. In some
cases, it is necessary to have stereo displays, and these are implemented in the form of headgear
containing two small displays embedded in goggles worn by the user.

 Hardcopy:

Hardcopy devices for recording images include laser printers, film cameras, heat-
sensitive devices, inkjet units, and digital units, such as optical and CD-ROM disks. Film
provides the highest possible resolution, but paper is the obvious medium of choice for written
material. For presentations, images are displayed on film transparencies or in a digital medium if
image projection equipment is used. The latter approach is gaining acceptance as the standard for
image presentations.

 Network:

Networking is almost a default function in any computer system in use today. Because of
the large amount of data inherent in image processing applications, the key consideration in
image transmission is bandwidth. In dedicated networks, this typically is not a problem, but
communications with remote sites via the Internet are not always as efficient. Fortunately, this
situation is improving quickly as a result of optical fiber and other broadband technologies.
Software introduction:

4. Introduction to 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
 Data acquisition
 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 non interactive 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 engines incorporate the LAPACK and BLAS libraries, embedding the state of
the art in software for matrix computation.

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 uses 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 signal processing, control systems, neural networks, fuzzy logic,
wavelets, simulation, and many others.

1.1 The MATLAB system:

The MATLAB system consists of five main parts

 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, an editor and debugger, and browsers for viewing help,
the workspace, files, and the search path.

 The 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 fast Fourier transforms.

 The 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 large and complex application programs.

 Graphics:

MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well
as annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics. It
also includes low-level functions that allow you to fully customize the appearance of graphics as
well as to build complete graphical user interfaces on your MATLAB applications.

 The MATLAB Application Program Interface (API):

This is a library that allows you to write C and FORTRAN programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling
MATLAB as a computational engine, and for reading and writing MAT-files.

Various toolboxes are there in MATLAB for computing recognition techniques, but we are
using IMAGE PROCESSING toolbox.

1.2 GRAPHICAL USER INTERFACE (GUI):

MATLAB’s Graphical User Interface Development Environment (GUIDE) provides a


rich set of tools for incorporating graphical user interfaces (GUIs) in M-functions. Using
GUIDE, the processes of laying out a GUI (i.e., its buttons, pop-up menus, etc.)and
programming the operation of the GUI are divided conveniently into two easily managed and
relatively independent tasks. The resulting graphical M-function is composed of two identically
named (ignoring extensions) files:

 A file with extension .fig, called a FIG-file that contains a complete graphical description of
all the function’s GUI objects or elements and their spatial arrangement. A FIG-file contains
binary data that does not need to be parsed when he associated GUI-based M-function is
executed.

 A file with extension .m, called a GUI M-file, which contains the code that controls the GUI
operation. This file includes functions that are called when the GUI is launched and exited,
and callback functions that are executed when a user interacts with GUI objects for example,
when a button is pushed.

To launch GUIDE from the MATLAB command window, type

guide filename

Where filename is the name of an existing FIG-file on the current path. If filename is omitted,

GUIDE opens a new (i.e., blank) window.


A graphical user interface (GUI) is a graphical display in one or more windows containing
controls, called components that enable a user to perform interactive tasks. The user of the GUI
does not have to create a script or type commands at the command line to accomplish the tasks.
Unlike coding programs to accomplish tasks, the user of a GUI need not understand the details of
how the tasks are performed.

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.

software description

Getting Started

If you are new to MATLAB, you should start by reading Manipulating Matrices.
The most important things to learn are how to enter matrices, how to use the: (colon) operator,
and how to invoke functions. After you master the basics, you should read the rest of the sections
below and run the demos.

At the heart of MATLAB is a new language you must learn before you can fully
exploit its power. You can learn the basics of MATLAB quickly, and mastery comes shortly
after. You will be rewarded with high productivity, high-creativity computing power that will
change the way you work.

Introduction - describes the components of the MATLAB system.

Development Environment - introduces the MATLAB development


environment, including information about tools and the MATLAB desktop.

Manipulating Matrices - introduces how to use MATLAB to generate matrices


and perform mathematical operations on matrices.
Graphics - introduces MATLAB graphic capabilities, including information about
plotting data, annotating graphs, and working with images.

Programming with MATLAB - describes how to use the MATLAB language to


create scripts and functions, and manipulate data structures, such as cell arrays and
multidimensional arrays.

INTRODUCTION

What Is 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.
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 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 signal processing, control systems, neural networks, fuzzy logic,
wavelets, simulation, and many others.

The MATLAB System

The MATLAB system consists of five main parts:

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.

The 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 eigenvalues, Bessel
functions, and fast Fourier transforms.

The 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.

The 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.

DEVELOPMENT ENVIRONMENT

Introduction

This chapter provides a brief introduction to starting and quitting MATLAB, and
the tools and functions that help you to work with MATLAB variables and files. For more
information about the topics covered here, see the corresponding topics under Development
Environment in the MATLAB documentation, which is available online as well as in print.

Starting and Quitting MATLAB

Starting MATLAB

On a Microsoft Windows platform, to start MATLAB, double-click the MATLAB shortcut icon
on your Windows desktop.

On a UNIX platform, to start MATLAB, type matlab at the operating system


prompt.

After starting MATLAB, the MATLAB desktop opens - see MATLAB Desktop.

You can change the directory in which MATLAB starts, define startup options including running
a script upon startup, and reduce startup time in some situations.
Quitting MATLAB

To end your MATLAB session, select Exit MATLAB from the File menu in the
desktop, or type quit in the Command Window. To execute specified functions each time
MATLAB quits, such as saving the workspace, you can create and run a finish.m script.

MATLAB Desktop

When you start MATLAB, the MATLAB desktop appears, containing tools
(graphical user interfaces) for managing files, variables, and applications associated with
MATLAB.

The first time MATLAB starts, the desktop appears as shown in the following
illustration, although your Launch Pad may contain different entries.

You can change the way your desktop looks by opening, closing, moving, and
resizing the tools in it. You can also move tools outside of the desktop or return them back inside
the desktop (docking). All the desktop tools provide common features such as context menus and
keyboard shortcuts.

You can specify certain characteristics for the desktop tools by selecting
Preferences from the File menu. For example, you can specify the font characteristics for
Command Window text. For more information, click the Help button in the Preferences dialog
box.

Desktop Tools

This section provides an introduction to MATLAB's desktop tools. You can also
use MATLAB functions to perform most of the features found in the desktop tools. The tools
are:
 Current Directory Browser
 Workspace Browser
 Array Editor
 Editor/Debugger
 Command Window
 Command History
 Launch Pad
 Help Browser
Command Window

Use the Command Window to enter variables and run functions and M-files.

Command History

Lines you enter in the Command Window are logged in the Command History
window. In the Command History, you can view previously used functions, and copy and
execute selected lines. To save the input and output from a MATLAB session to a file, use the
diary function.

Running External Programs

You can run external programs from the MATLAB Command Window. The exclamation point
character! is a shell escape and indicates that the rest of the input line is a command to the
operating system. This is useful for invoking utilities or running other programs without quitting
MATLAB. On Linux, for example,!emacsmagik.m invokes an editor called emacs for a file
named magik.m. When you quit the external program, the operating system returns control to
MATLAB.

Launch Pad

MATLAB's Launch Pad provides easy access to tools, demos, and documentation.

Help Browser
Use the Help browser to search and view documentation for all your Math Works
products. The Help browser is a Web browser integrated into the MATLAB desktop that
displays HTML documents.

To open the Help browser, click the help button in the toolbar, or type
helpbrowser in the Command Window. The Help browser consists of two panes, the Help
Navigator, which you use to find information, and the display pane, where you view the
information.

Help Navigator

Use to Help Navigator to find information. It includes:

Product filter - Set the filter to show documentation only for the products you specify.

Contents tab -View the titles and tables of contents of documentation for your products.

Index tab - Find specific index entries (selected keywords) in the MathWorks
documentation for your products.

Search tab - Look for a specific phrase in the documentation. To get help for a specific
function, set the Search type to Function Name.

Favorites tab -View a list of documents you previously designated as favorites.

Display Pane

After finding documentation using the Help Navigator, view it in the display pane. While
viewing the documentation, you can:

Browse to other pages- Use the arrows at the tops and bottoms of the pages, or use the back
and forward buttons in the toolbar.

Bookmark pages - Click the Add to Favorites button in the toolbar.


Print pages - Click the print button in the toolbar.

Find a term in the page - Type a term in the Find in page field in the toolbar and click Go.

Other features available in the display pane are: copying information, evaluating a
selection, and viewing Web pages.

Current Directory Browser

MATLAB file operations use the current directory and the search path as
reference points. Any file you want to run must either be in the current directory or on the search
path.

Search Path

To determine how to execute functions you call, MATLAB uses a search path to
find M-files and other MATLAB-related files, which are organized in directories on your file
system. Any file you want to run in MATLAB must reside in the current directory or in a
directory that is on the search path. By default, the files supplied with MATLAB and
MathWorks toolboxes are included in the search path.

Workspace Browser

The MATLAB workspace consists of the set of variables (named arrays) built up during a
MATLAB session and stored in memory. You add variables to the workspace by using
functions, running M-files, and loading saved workspaces.

To view the workspace and information about each variable, use the Workspace browser, or use
the functions who and whos.

To delete variables from the workspace, select the variable and select Delete from
the Edit menu. Alternatively, use the clear function.

The workspace is not maintained after you end the MATLAB session. To save the
workspace to a file that can be read during a later MATLAB session, select Save Workspace As
from the File menu, or use the save function. This saves the workspace to a binary file called a
MAT-file, which has a .mat extension. There are options for saving to different formats. To read
in a MAT-file, select Import Data from the File menu, or use the load function.

Array Editor

Double-click on a variable in the Workspace browser to see it in the Array Editor.


Use the Array Editor to view and edit a visual representation of one- or two-dimensional numeric
arrays, strings, and cell arrays of strings that are in the workspace.

Editor/Debugger

Use the Editor/Debugger to create and debug M-files, which are programs you write to
runMATLAB functions. The Editor/Debugger provides a graphical user interface for basic
textediting, as well as for M-file debugging.

You can use any text editor to create M-files, such as Emacs, and can use
preferences (accessible from the desktop File menu) to specify that editor as the default. If you
use another editor, you can still use the MATLAB Editor/Debugger for debugging, or you can
use debugging functions, such as dbstop, which sets a breakpoint.

If you just need to view the contents of an M-file, you can display it in the
Command Window by using the type function.

MANIPULATING MATRICES

Entering Matrices

The best way for you to get started with MATLAB is to learn how to handle matrices. Start
MATLAB and follow along with each example.

You can enter matrices into MATLAB in several different ways:

 Enter an explicit list of elements.


 Load matrices from external data files.
 Generate matrices using built-in functions.
 Create matrices with your own functions in M-files.
Start by entering Dürer's matrix as a list of its elements. You have only to follow a few basic
conventions:

 Separate the elements of a row with blanks or commas.


 Use a semicolon, ; , to indicate the end of each row.
 Surround the entire list of elements with square brackets, [ ].

To enter Dürer's matrix, simply type in the Command Window

A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

MATLAB displays the matrix you just entered.

A=

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

This exactly matches the numbers in the engraving. Once you have entered the matrix, it is
automatically remembered in the MATLAB workspace. You can refer to it simply as A.

Expressions

Like most other programming languages, MATLAB provides mathematical


expressions, but unlike most programming languages, these expressions involve entire matrices.
The building blocks of expressions are:

 Variables
 Numbers
 Operators
 Functions
Variables

MATLAB does not require any type declarations or dimension statements. When
MATLAB encounters a new variable name, it automatically creates the variable and allocates the
appropriate amount of storage. If the variable already exists, MATLAB changes its contents and,
if necessary, allocates new storage. For example,

num_students = 25

Creates a 1-by-1 matrix named num_students and stores the value 25 in its single element.

Variable names consist of a letter, followed by any number of letters, digits, or


underscores. MATLAB uses only the first 31 characters of a variable name. MATLAB is case
sensitive; it distinguishes between uppercase and lowercase letters. A and a are not the same
variable. To view the matrix assigned to any variable, simply enter the variable name.

Numbers

MATLAB uses conventional decimal notation, with an optional decimal point and leading plus
or minus sign, for numbers. Scientific notation uses the letter e to specify a power-of-ten scale
factor. Imaginary numbers use either i or j as a suffix. Some examples of legal numbers are

3 -99 0.0001

9.6397238 1.60210e-20 6.02252e23

1i -3.14159j 3e5i
All numbers are stored internally using the long format specified by the IEEE
floating-point standard. Floating-point numbers have a finite precision of roughly 16 significant
decimal digits and a finite range of roughly 10-308 to 10+308.

Operators

Expressions use familiar arithmetic operators and precedence rules.

+ Addition

- Subtraction

* Multiplication

/ Division

\ Left division (described in "Matrices and Linear


Algebra" in Using MATLAB)

^ Power

' Complex conjugate transpose

() Specify evaluation order

Functions

MATLAB provides a large number of standard elementary mathematical


functions, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a negative
number is not an error; the appropriate complex result is produced automatically. MATLAB also
provides many more advanced mathematical functions, including Bessel and gamma functions.
Most of these functions accept complex arguments. For a list of the elementary mathematical
functions, type

helpelfun

For a list of more advanced mathematical and matrix functions, type

helpspecfun

helpelmat

Some of the functions, like sqrt and sin, are built-in. They are part of the
MATLAB core so they are very efficient, but the computational details are not readily
accessible. Other functions, like gamma and sinh, are implemented in M-files. You can see the
code and even modify it if you want. Several special functions provide values of useful
constants.

Pi 3.14159265...

i Imaginary unit, √-1

I Same as i

Eps Floating-point relative precision, 2-52

Realmin Smallest floating-point number, 2-1022

Realmax Largest floating-point number, (2-ε)21023

Inf Infinity

NaN Not-a-number

GUI
A graphical user interface (GUI) is a user interface built with graphical objects,
such as buttons, text fields, sliders, and menus. In general, these objects already have meanings
to most computer users. For example, when you move a slider, a value changes; when you press
an OK button, your settings are applied and the dialog box is dismissed. Of course, to leverage
this built-in familiarity, you must be consistent in how you use the various GUI-building
components.

Applications that provide GUIs are generally easier to learn and use since the
person using the application does not need to know what commands are available or how they
work. The action that results from a particular user action can be made clear by the design of the
interface.

The sections that follow describe how to create GUIs with MATLAB. This
includes laying out the components, programming them to do specific things in response to user
actions, and saving and launching the GUI; in other words, the mechanics of creating GUIs. This
documentation does not attempt to cover the "art" of good user interface design, which is an
entire field unto itself. Topics covered in this section include:

Creating GUIs with GUIDE

MATLAB implements GUIs as figure windows containing various styles of uicontrol objects.
You must program each object to perform the intended action when activated by the user of the
GUI. In addition, you must be able to save and launch your GUI. All of these tasks are simplified
by GUIDE, MATLAB's graphical user interface development environment.

GUI Development Environment

The process of implementing a GUI involves two basic tasks:

 Laying out the GUI components


 Programming the GUI components
GUIDE primarily is a set of layout tools. However, GUIDE also generates an M-
file that contains code to handle the initialization and launching of the GUI. This M-file provides
a framework for the implementation of the callbacks - the functions that execute when users
activate components in the GUI.

The Implementation of a GUI

While it is possible to write an M-file that contains all the commands to lay out a
GUI, it is easier to use GUIDE to lay out the components interactively and to generate two files
that save and launch the GUI:

A FIG-file - contains a complete description of the GUI figure and all of its

children (uicontrols and axes), as well as the values of all object properties.

An M-file- contains the functions that launch and control the GUI and the

callbacks, which are defined as subfunctions. This M-file is referred to as the

application M-file in this documentation.

Note that the application M-file does not contain the code that lays out the
uicontrols; this information is saved in the FIG-file.

The following diagram illustrates the parts of a GUI implementation.


Features of the GUIDE-Generated Application M-File

GUIDE simplifies the creation of GUI applications by automatically generating


an M-file framework directly from your layout. You can then use this framework to code your
application M-file. This approach provides a number of advantages:

The M-file contains code to implement a number of useful features (see Configuring Application
Options for information on these features). The M-file adopts an effective approach to managing
object handles and executing callback routines (see Creating and Storing the Object Handle
Structure for more information). The M-files provides a way to manage global data (see
Managing GUI Data for more information).

The automatically inserted subfunction prototypes for callbacks ensure compatibility with future
releases. For more information, see Generating Callback Function Prototypes for information on
syntax and arguments.
You can elect to have GUIDE generate only the FIG-file and write the application M-file
yourself. Keep in mind that there are no uicontrol creation commands in the application M-file;
the layout information is contained in the FIG-file generated by the Layout Editor.

Beginning the Implementation Process

To begin implementing your GUI, proceed to the following sections:

Getting Started with GUIDE - the basics of using GUIDE.

Selecting GUIDE Application Options - set both FIG-file and M-file options.

Using the Layout Editor - begin laying out the GUI.

Understanding the Application M-File - discussion of programming techniques

used in the application M-file.

Application Examples - a collection of examples that illustrate techniques

which are useful for implementing GUIs.

Command-Line Accessibility

When MATLAB creates a graph, the figure and axes are included in the list of
children of their respective parents and their handles are available through commands such as
findobj, set, and get. If you issue another plotting command, the output is directed to the current
figure and axes.

GUIs are also created in figure windows. Generally, you do not want GUI figures
to be available as targets for graphics output, since issuing a plotting command could direct the
output to the GUI figure, resulting in the graph appearing in the middle of the GUI.

In contrast, if you create a GUI that contains an axes and you want commands
entered in the command window to display in this axes, you should enable command-line access.
User Interface Controls
The Layout Editor component palette contains the user interface controls that you
can use in your GUI. These components are MATLAB uicontrol objects and are programmable
via their Callback properties. This section provides information on these components.

 Push Buttons
 Sliders
 Toggle Buttons
 Frames
 Radio Buttons
 Listboxes
 Checkboxes
 Popup Menus
 Edit Text
 Axes
 Static Text
 Figures
Push Buttons

Push buttons generate an action when pressed (e.g., an OK button may close a
dialog box and apply settings). When you click down on a push button, it appears depressed;
when you release the mouse, the button's appearance returns to its nondepressed state; and its
callback executes on the button up event.

Properties to Set

String - set this property to the character string you want displayed on the push button.

Tag - GUIDE uses the Tag property to name the callback subfunction in the application M-
file. Set Tag to a descriptive name (e.g., close_button) before activating the GUI.

Programming the Callback


When the user clicks on the push button, its callback executes. Push buttons do not return a value
or maintain a state.

Toggle Buttons

Toggle buttons generate an action and indicate a binary state (e.g., on or off).
When you click on a toggle button, it appears depressed and remains depressed when you release
the mouse button, at which point the callback executes. A subsequent mouse click returns the
toggle button to the nondepressed state and again executes its callback.

Programming the Callback

The callback routine needs to query the toggle button to determine what state it is
in. MATLAB sets the Value property equal to the Max property when the toggle button is
depressed (Max is 1 by default) and equal to the Min property when the toggle button is not
depressed (Min is 0 by default).

From the GUIDE Application M-File

The following code illustrates how to program the callback in the GUIDE
application M-file.

functionvarargout = togglebutton1_Callback(h,eventdata,handles,varargin)

button_state = get(h,'Value');

ifbutton_state == get(h,'Max')

% toggle button is pressed

elseifbutton_state == get(h,'Min')

% toggle button is not pressed


end

Adding an Image to a Push Button or Toggle Button

Assign the CData property an m-by-n-by-3 array of RGB values that define a
truecolor image. For example, the array a defines 16-by-128 truecolor image using random
values between 0 and 1 (generated by rand).

a(:,:,1) = rand(16,128);

a(:,:,2) = rand(16,128);

a(:,:,3) = rand(16,128);

set(h,'CData',a)

Radio Buttons

Radio buttons are similar to checkboxes, but are intended to be mutually exclusive within a
group of related radio buttons (i.e., only one button is in a selected state at any given time). To
activate a radio button, click the mouse button on the object. The display indicates the state of
the button.

Implementing Mutually Exclusive Behavior

Radio buttons have two states - selected and not selected. You can query and set
the state of a radio button through its Value property:

Value = Max, button is selected.

Value = Min, button is not selected.


To make radio buttons mutually exclusive within a group, the callback for each
radio button must set the Value property to 0 on all other radio buttons in the group. MATLAB
sets the Value property to 1 on the radio button clicked by the user.

The following subfunction, when added to the application M-file, can be called by
each radio button callback. The argument is an array containing the handles of all other radio
buttons in the group that must be deselected.

functionmutual_exclude(off)

set(off,'Value',0)

Obtaining the Radio Button Handles.

The handles of the radio buttons are available from the handles structure, which
contains the handles of all components in the GUI. This structure is an input argument to all
radio button callbacks.

The following code shows the call to mutual_exclude being made from the first
radio button's callback in a group of four radio buttons.

functionvarargout = radiobutton1_Callback(h,eventdata,handles,varargin)

off = [handles.radiobutton2,handles.radiobutton3,handles.radiobutton4];

mutual_exclude(off)

% Continue with callback

.
After setting the radio buttons to the appropriate state, the callback can continue
with its implementation-specific tasks.

Checkboxes

Check boxes generate an action when clicked and indicate their state as checked
or not checked. Check boxes are useful when providing the user with a number of independent
choices that set a mode (e.g., display a toolbar or generate callback function prototypes).

The Value property indicates the state of the check box by taking on the value of
the Max or Min property (1 and 0 respectively by default):

Value = Max, box is checked.

Value = Min, box is not checked.

You can determine the current state of a check box from within its callback by
querying the state of its Value property, as illustrated in the following example:

function checkbox1_Callback(h,eventdata,handles,varargin)

if (get(h,'Value') == get(h,'Max'))

% then checkbox is checked-take approriate action

else

% checkbox is not checked-take approriate action

end
Edit Text

Edit text controls are fields that enable users to enter or modify text strings. Use
edit text when you want text as input. The String property contains the text entered by the user.

To obtain the string typed by the user, get the String property in the callback.

function edittext1_Callback(h,eventdata, handles,varargin)

user_string = get(h,'string');

% proceed with callback...

Obtaining Numeric Data from an Edit Test Component

MATLAB returns the value of the edit text String property as a character string. If
you want users to enter numeric values, you must convert the characters to numbers. You can do
this using the str2double command, which converts strings to doubles. If the user enters non-
numeric characters, str2double returns NaN.

You can use the following code in the edit text callback. It gets the value of the
String property and converts it to a double. It then checks if the converted value is NaN,
indicating the user entered a non-numeric character (isnan) and displays an error dialog
(errordlg).

function edittext1_Callback(h,eventdata,handles,varargin)

user_entry = str2double(get(h,'string'));

ifisnan(user_entry)

errordlg('You must enter a numeric value','BadInput','modal')

end

% proceed with callback...


Triggering Callback Execution

On UNIX systems, clicking on the menubar of the figure window causes the edit text callback to
execute. However, on Microsoft Windows systems, if an editable text box has focus, clicking on
the menubar does not cause the editable text callback routine to execute. This behavior is
consistent with the respective platform conventions. Clicking on other components in the GUI
execute the callback.

Static Text

Static text controls displays lines of text. Static text is typically used to label other
controls, provide directions to the user, or indicate values associated with a slider. Users cannot
change static text interactively and there is no way to invoke the callback routine associated with
it.

Frames

Frames are boxes that enclose regions of a figure window. Frames can make a
user interface easier to understand by visually grouping related controls. Frames have no
callback routines associated with them and only uicontrols can appear within frames (axes
cannot).

Placing Components on Top of Frames

Frames are opaque. If you add a frame after adding components that you want to
be positioned within the frame, you need to bring forward those components. Use the Bring
to Front and Send to Back operations in the Layout menu for this purpose.
List Boxes

List boxes display a list of items and enable users to select one or more items.

The String property contains the list of strings displayed in the list box. The first
item in the list has an index of 1.

The Value property contains the index into the list of strings that correspond to
the selected item. If the user selects multiple items, then Value is a vector of indices.

By default, the first item in the list is highlighted when the list box is first
displayed. If you do not want any item highlighted, then set the Value property to empty, [].

The ListboxTop property defines which string in the list displays as the top most
item when the list box is not large enough to display all list entries. ListboxTop is an index into
the array of strings defined by the String property and must have a value between 1 and the
number of strings. Noninteger values are fixed to the next lowest integer.

Single or Multiple Selection


The values of the Min and Max properties determine whether users can make
single or multiple selections:

If Max - Min > 1, then list boxes allow multiple item selection.

If Max - Min <= 1, then list boxes do not allow multiple item selection.

Selection Type

Listboxes differentiate between single and double clicks on an item and set the figure
SelectionType property to normal or open accordingly. See Triggering Callback Execution for
information on how to program multiple selection.

Triggering Callback Execution

MATLAB evaluates the list box's callback after the mouse button is released or a
keypress event (including arrow keys) that changes the Value property (i.e., any time the user
clicks on an item, but not when clicking on the list box scrollbar). This means the callback is
executed after the first click of a double-click on a single item or when the user is making
multiple selections.

In these situations, you need to add another component, such as a Done button
(push button) and program its callback routine to query the list box Value property (and possibly
the figure SelectionType property) instead of creating a callback for the list box. If you are using
the automatically generated application M-file option, you need to either:
Set the list box Callback property to the empty string ('') and remove the callback
subfunction from the application M-file. Leave the callback subfunction stub in the application
M-file so that no code executes when users click on list box items.

The first choice is best if you are sure you will not use the list box callback and
you want to minimize the size and efficiency of the application M-file. However, if you think
you may want to define a callback for the list box at some time, it is simpler to leave the callback
stub in the M-file.

Popup Menus

Popup menus open to display a list of choices when users press the arrow.

The String property contains the list of string displayed in the popup menu. The
Value property contains the index into the list of strings that correspond to the selected item.

When not open, a popup menu displays the current choice, which is determined
by the index contained in the Value property. The first item in the list has an index of 1.

Popup menus are useful when you want to provide users with a number of
mutually exclusive choices, but do not want to take up the amount of space that a series of radio
buttons requires.

Programming the Popup Menu


You can program the popup menu callback to work by checking only the index of the item
selected (contained in the Value property) or you can obtain the actual string contained in the
selected item.

This callback checks the index of the selected item and uses a switch statement to
take action based on the value. If the contents of the popup menu is fixed, then you can use this
approach.

functionvarargout = popupmenu1_Callback(h,eventdata,handles,varargin)

val = get(h,'Value');

switchval

case 1

% The user selected the first item

case 2

% The user selected the second item

% etc.

This callback obtains the actual string selected in the popup menu. It uses the
value to index into the list of strings. This approach may be useful if your program dynamically
loads the contents of the popup menu based on user action and you need to obtain the selected
string. Note that it is necessary to convert the value returned by the String property from a cell
array to a string.

functionvarargout = popupmenu1_Callback(h,eventdata,handles,varargin)
val = get(h,'Value');

string_list = get(h,'String');

selected_string = string_list{val}; % convert from cell array to string

% etc.

Enabling or Disabling Controls

You can control whether a control responds to mouse button clicks by setting the
Enable property. Controls have three states:

on - The control is operational

off - The control is disabled and its label (set by the string property) is

grayed out.

inactive - The control is disabled, but its label is not grayed out.

When a control is disabled, clicking on it with the left mouse button does not
execute its callback routine. However, the left-click causes two other callback routines to
execute:

First the figure WindowButtonDownFcn callback executes. Then the control's


ButtonDownFcn callback executes.
A right mouse button click on a disabled control posts a context menu, if one is
defined for that control. See the Enable property description for more details.

Axes

Axes enable your GUI to display graphics (e.g., graphs and images). Like all graphics objects,
axes have properties that you can set to control many aspects of its behavior and appearance. See
Axes Properties for general information on axes objects.

Axes Callbacks

Axes are not uicontrol objects, but can be programmed to execute a callback when users click a
mouse button in the axes. Use the axes ButtonDownFcn property to define the callback.

Plotting to Axes in GUIs

GUIs that contain axes should ensure the Command-line accessibility option in
the Application Options dialog is set to Callback (the default). This enables you to issue plotting
commands from callbacks without explicitly specifying the target axes.

GUIs with Multiple Axes

If a GUI has multiple axes, you should explicitly specify which axes you want to target when
you issue plotting commands. You can do this using the axes command and the handles
structure. For example,

axes(handles.axes1)
makes the axes whose Tag property is axes1 the current axes, and therefore the target for plotting
commands. You can switch the current axes whenever you want to target a different axes. See
GUI with Multiple Axes for and example that uses two axes.

Figure

Figures are the windows that contain the GUI you design with the Layout Editor.
See the description of figure properties for information on what figure characteristics you can
control.

Main code:
clc
clearall
tempImage=dicomread('tumour.dcm');
imshow(tempImage,[]);
GLCM2 = graycomatrix(tempImage,'Offset',[2 0;0 2]);
stats = glcm(GLCM2,0);
test_feat=[stats.autoc,stats.energ,stats.entro,stats.homom];

features_Testset=test_feat(:)'
loadtrain_data
% Prepare numeric matrix
features_Trainset=[];
for i=1:length(train_feat)
features_train_tmp= train_feat{1,i}(:)' ;
features_Trainset=[features_Trainset;features_train_tmp];
end

train_label = zeros(size(8,1),1);
train_label(1:3,1) = 1;
train_label(4:6,1) = 2;

clc;
SVMStruct = svmtrain(features_Trainset,train_label,'kernel_function','rbf');

Group= svmclassify(SVMStruct,features_Testset );

if Group==1
'GIven is tumour one'
elseif Group==2
'GIven is tumourless'
end

clc
clearall
tempImage=dicomread('tumour.dcm');
imshow(tempImage,[]);
GLCM2 = graycomatrix(tempImage,'Offset',[2 0;0 2]);
stats = glcm(GLCM2,0);
test_feat=[stats.autoc,stats.energ,stats.entro,stats.homom];

features_Testset=test_feat(:)'
loadtrain_data
% Prepare numeric matrix
features_Trainset=[];
for i=1:length(train_feat)
features_train_tmp= train_feat{1,i}(:)' ;
features_Trainset=[features_Trainset;features_train_tmp];
end

train_label = zeros(size(8,1),1);
train_label(1:3,1) = 1;
train_label(4:6,1) = 2;
clc;
SVMStruct = svmtrain(features_Trainset,train_label,'kernel_function','rbf');

Group= svmclassify(SVMStruct,features_Testset );

if Group==1
'GIven is tumour one'
elseif Group==2
'GIven is tumourless'
end

clc;closeall;clearall;
[file path]=uigetfile('Input\*.*');
filename=strcat(path,file);
img1=double(dicomread(filename));

figure(1);imshow(img1,[])

% Introduce AWGN into test images.


% Note: This will show the benefit of bilateral filtering.
img1 = img1+0.03*randn(size(img1));
img1(img1<0) = 0; img1(img1>1) = 1;
% Set bilateral filter parameters.
w = 5; % bilateral filter half-width
sigma = [3 0.1]; % bilateral filter standard deviations

% Apply bilateral filter to each image.


bflt_img1 = bfilter2(img1,w,sigma);

V. CONCLUSION
We are studied various types of method for the detectionand classification of brain tumor from
MRI image. The above mention method is having various limitations such as, it does not
generate perfect results in case of high invariability of brain MRI, particularly in terms of
contrast between brain tissues and intensity ranges, removing intensity in homogeneity from MR
images is also a difficult task as it invariably changes if different MRI acquisition parameters are
used, and it varies from slice to slice and from a patient to a patient as well etc. We are trying to
resolve these limitations by using RoughSet Theory. Feature extraction and reduction will be
carried out by using RST and classification will be performing by using neuro fuzzy classifier to
generate better results.

REFERENCES
[1] Y. Zhang, M. Brady and S. Smith, “Segmentation ofBrain MR Images through a Hidden
Markow Random Field Model and the Expectation-Maximization Algorithm”, Proceeding of the
IEEE transaction on medical images, January 2001
[2] M.N. Ahmed, S.M. Yamany, N. Mohamed and T. Moriarty, “A modified fuzzy c-means
algorithm for bias field estimation and segmentation of MRI data”, Proceedings of the IEEE
Transaction on Medical Images, KY, USA, vol. 21, issue 3, pp. 193-199, March 2002.
[3] M.Tolba, M. Mostafa, T. Gharib and M. Salem, “MRBrainImage Segmentation Using
Gaussian Multi resolution Analysis and the EM Algorithm”, International Conference on
Engineering and Science, 2003.
[4] S. Li, J.T. Kwok, I.W Tsang and Y. Wang “ Fusing Images with Different Focuses using
Support Vector Machines,” Proceedings of the IEEE transaction on Neural Networks, China,
November 2007.
[5] J.K Sing, D.K. Basu, M. Nasipuri and M. Kundu, “Segmentation of MR Images of the
Human brain using Fuzzy Adaptive Radial Basis function Neural Network, Pattern Recognition
and Machine Intelligence,” LNCS, Berlin, Heidelberg, 2005.
[6] H. Yu and J.L. Fan, “Three-level Image Segmentation Based on Maximum Fuzzy Partition
Entropy of 2-D Histogram and Quantum Genetic Algorithm,” Advanced Intelligent Computing
Theories and Applications. With aspects of Artificial Intelligence, Lecture Notes in Computer
Science, Berlin and Heidelberg 2008.
[7] J. Luts, T. Laudadio, A.J. Idema, A.W. Simonetti, A. Heerschap, D. Vandermeulen and S.
Huffel, “ Nosologic imaging of the brain segmentation and classification using MRI and MRSI”,
Journal of NMR in Biomedicine, vol. 22, issue 4, pp. 374-390, May 2009.
[8] Z. Shi, L. He, T.N.K Suzuki, and H. Ito, “Survey on Neural Networks used for Medical
Image Processing,” International Journal of Computational Science, 2009.
[9] S. Roy and S. K. Bandyopadhyay, “Detection and Quantification of Brain Tumor from MRI
of Brain and its Symmetric Analysis”, International Journal of Information and Communication
Technology of Research, vol. 2, issue 6, pp. 477-483, June 2012.
[10] V.B Padole and D.S. Chaudhari, “”Detection of Brain Tumor in MRI Images Using Mean
Shift Algorithm and Normalized Cut Method,” International Journal of Engineering and
Advanced Technology, June 2012.
[11] M. Kumar and K. K. Mehta, “”A Texture based Tumor detection and automatic
Segmentation using SeededRegion Growing Method,” International Journal of Computer
Technology and Applications, August 2011.
[12] R. Meenakshi and P. Anandhakumar, ‘’Brain Tumor Identification in MRI with BPN
Classifier and Orthonormal Operators,” European Journal of Scientific Research, September
2012.
[13] T.U Paul and S.K. Bandyopadhyay,“ Segmentation of Brain Tumor from Brain MRI Images
Reintroducing K–Means with advanced Dual Localization Method”, International Journal of
Engineering Research and Applications, June 2012.
[14] J. J. Corso, E. Sharon, S. Dube, S. El-Saden, U. Sinha and A. Yuille, "Efficient Multilevel
Brain Tumor Segmentation With Integrated Bayesian Model Classification", IEEE Transactions
on Medical Imaging, vol. 27, Issue 5, pp. 629-640,May 2008.
[15] T. U. Paul and S. K. Bandhyopadhyay, "Segmentation of Brain Tumor from Brain MRI
Images Reintroducing K–Means with advanced Dual Localization Method", International
Journal of Engineering Research and Applications (IJERA), Vol. 2, Issue 3, pp. 226-231, May-
Jun 2012.[16] S. Pal, “Fuzzy image processing and recognition: Uncertainties handling and
applications,” International journal Image Graph, vol. 1, no. 2, pp. 169–195, 2001. [17] S. Pal, B.
U. Shankar, and P. Mitra, “Granular computing, rough entropy and object extraction,” Pattern
Recognition Letter, vol. 26, no. 16, pp. 2509– 2517, December 2005.
[18] S. Hirano and S. Tsumoto, “Rough representation of aregion of interest in medical images,”
International Journal of Approximation Reasoning vol. 40,issue 1-2, pp. 23–34, July 2005.
[19] R. Swiniarski and L. Hargis, “Rough sets as a front end of neural- networks texture
classifiers,” Neurocomputing, vol. 36, no. 1–4, pp. 85–102, 2001.

You might also like