You are on page 1of 54

Maze Solving Using Image Analysis

Image Processing
In electrical engineering and computer science, image processing is any form
of signal processing for which the input is an image, such as
a photograph or video frame; the output of image processing may be either an
image or, a set of characteristics or parameters related to the image. Most
image-processing techniques involve treating the image as a two-
dimensional signal and applying standard signal-processing techniques to it.
Image processing usually refers to digital image processing,
but optical and analog image processing also are possible. The acquisition of
images (producing the input image in the first place) is referred to as imaging.

Some of the operations and applications of image processing are mentioned


below:
Typical operations of image processing
 Euclidean geometry transformations such as enlargement, reduction,
and rotation
 Color corrections such as brightness and contrast adjustments, color
mapping, color balancing, quantization, or color translation to a
different color space
 Digital compositing or optical compositing (combination of two or more
images), which is used in film-making to make a "matte"
 Interpolation, demosaicing, and recovery of a full image from a raw
image format using a Bayer filter pattern
 Image registration, the alignment of two or more images
 Image differencing and morphing
 Image recognition, for example, may extract the text from the image
using optical character recognition or checkbox and bubble values
using optical mark recognition

1
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

 Image segmentation
 High dynamic range imaging by combining multiple images
 Geometric hashing for 2-D object recognition with affine invariance
Applications of image processing
Further information: Imaging
 Computer vision
 Optical sorting
 Augmented Reality
 Face detection
 Feature detection
 Lane departure warning system
 Non-photorealistic rendering
 Medical image processing
 Microscope image processing
 Morphological image processing
 Remote sensing

Digital Image Processing (DIP)


Digital image processing is the use of computer algorithms to perform image
processing on digital images. As a subcategory or field of digital signal
processing, digital image processing has many advantages over analog image
processing. It allows a much wider range of algorithms to be applied to the
input data and can avoid problems such as the build-up of noise and signal
distortion during processing. Since images are defined over two dimensions
(perhaps more) digital image processing may be modeled in the form
of Multidimensional Systems.

2
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Tasks of DIP
Digital image processing allows the use of much more complex algorithms for
image processing, and hence, can offer both more sophisticated performance at
simple tasks, and the implementation of methods which would be impossible by
analog means.
In particular, digital image processing is the only practical technology for:
 Classification
 Feature extraction
 Pattern recognition
 Projection
 Multi-scale signal analysis
Some techniques which are used in digital image processing include:
 Pixelization
 Linear filtering
 Principal components analysis
 Independent component analysis
 Hidden Markov models
 Partial differential equations
 Self-organizing maps
 Neural networks
 Wavelets

What is a Maze
A maze is a tour puzzle in the form of a complex branching passage through
which the solver must find a route. In everyday speech, both maze and labyrinth
denote a complex and confusing series of pathways, but technically the maze is
distinguished from the labyrinth, as the labyrinth has a single through-route with
twists and turns but without branches, and is not designed to be as difficult to

3
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

navigate. The pathways and walls in a maze or labyrinth are fixed (pre-


determined) – puzzles where the walls and paths can change during the game
are categorised as tour puzzles. The Cretan labyrinth is the oldest known maze.

Maze construction
Mazes have been built with walls and rooms, with hedges, turf, corn stalks, hay
bales, books, paving stones of contrasting colors or designs, bricks and turf,[3] or
in fields of crops such as corn or, indeed, maize. Maize mazes can be very large;
they are usually only kept for one growing season, so they can be different
every year, and are promoted as seasonal tourist attractions. Indoors, Mirror
Mazes are another form of maze, where many of the apparent pathways are
imaginary routes seen through multiple reflections in mirrors. Another type of
maze consists of a set of rooms linked by doors (so a passageway is just another
room in this definition). Players enter at one spot, and exit at another, or the idea
may be to reach a certain spot in the maze. Mazes can also be printed or drawn
on paper to be followed by a pencil or fingertip.

A small maze. Classical labyrinth. A computer-generated maze.

FIGURE-1

Generating mazes
Maze generation is the act of designing the layout of passages and walls within
a maze. There are many different approaches to generating mazes, where
various maze generation algorithms exist for building them, either by hand or
automatically by computer.

4
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

There are two main mechanisms used to generate mazes. "Carving passages" is
where one marks out the network of available routes. "Adding walls" is where
one lays out a set of obstructions within an open area. Most mazes drawn on
paper are where one draws the walls, where the spaces in between the markings
compose the passages.

Solving mazes
Maze solving is the act of finding a route through the maze from the start to
finish. Some maze solving methods are designed to be used inside the maze by
a traveler with no prior knowledge of the maze, whereas others are designed to
be used by a person or computer program that can see the whole maze at once.
The mathematician  Leonhard Euler was one of the first to analyze plane mazes
mathematically, and in doing so made the first significant contributions to the
branch of mathematics known as topology.
Mazes containing no loops are known as "standard", or "perfect" mazes, and are
equivalent to a tree in graph theory. Thus many maze solving algorithms are
closely related to graph theory. Intuitively, if one pulled and stretched out the
paths in the maze in the proper way, the result could be made to resemble a tree.

FIGURE-2; Example of a maze

5
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Origin of Mathematical Morphology


Mathematical morphology is an active and growing area of image processing
and analysis. It is based on set theory and topology (Matheron, 1975; Serra,
1982; Haralick et al., 1986; Giardina and Dougherty, 1988). Mathematical
morphology studies the geometric structure inherent within the image. For this
reason it uses a predetermined geometric shape known as the structuring
element. Erosion, which is the basic morphological operation, quantifies the
way in which the structuring element fits into the image. Mathematical
morphology has provided solutions to many tasks, where image processing can
be applied, such as in remote sensing, optical character recognition, radar image
sequence recognition, medical imaging, etc.
Soft mathematical morphology was introduced by Koskinen et al. (1991). In
this approach the definitions of the standard morphological operations were
slightly relaxed in such a way that a degree of robustness was achieved while
most of their desirable properties were maintained. Soft morphological filters
are less sensitive to additive noise and to small variations in object shape than
standard morphological filters. They have found applications mainly in noise
removal, in areas such as medical imaging and digital TV (Harvey, 1998).
The extension of concepts of mathematical morphology to color image
processing is not straightforward, because there is not an obvious and
unambiguous method of fully ordering vectors (Barnett, 1976). Componentwise
morphological techniques, which are based on marginal subordering, do not
take into consideration the correlation among color components; thus, they are
not vector preserving. Transformation techniques have been used to decorrelate
color components and then apply component wise gray-scale techniques
(Goutsias et al., 1995). Morphological techniques that are based on reduced or
partial sub ordering imply the existence of multiple suprema (infima); Thus,
they could introduce ambiguity in the resultant data (Comerand Delp, 1998).
The crucial point in developing a vector morphology theory for color image

6
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

processing is the definition of vector-preserving infimum and supremum


operators with unique outcome in a properly selected color space.

Standard Mathematical Morphology


The considerations for the structuring element used by Haralick et al. (1987)
have been adopted for the basic morphological operations. Also, the notations
of the extensions of the basic morphological operations (soft morphology,
fuzzy morphology and fuzzy soft morphology) are based on the same
consideration. Moreover, throughout the paper the discrete case is considered,
i.e., all sets belong to the Cartesian grid Z2.

Gray Image
In photography and computing, a grayscale or greyscale digital image is an
image in which the value of each pixel is a single sample, that is, it carries
only intensity information. Images of this sort, also known as black-and-white,
are composed exclusively of shades of gray, varying from black at the weakest
intensity to white at the strongest.[1]
Grayscale images are distinct from one-bit black-and-white images, which in
the context of computer imaging are images with only the two colors,black,
and white (also called bilevel or binary images). Grayscale images have many
shades of gray in between. Grayscale images are also called monochromatic,
denoting the absence of any chromatic variation.
Grayscale images are often the result of measuring the intensity of light at each
pixel in a single band of the electromagnetic spectrum (e.g. infrared,visible
light, ultraviolet, etc.), and in such cases they are monochromatic proper when
only a given frequency is captured. But also they can be synthesized from a full
color image.

7
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE-3;A typical grayscale image.

Numerical representations
The intensity of a pixel is expressed within a given range between a minimum
and a maximum, inclusive. This range is represented in an abstract way as a
range from 0 (total absence, black) and 1 (total presence, white), with any
fractional values in between. This notation is used in academic papers, but it
must be noted that this does not define what "black" or "white" is in terms
of colorimetry.
Another convention is to employ percentages, so the scale is then from 0% to
100%. This is used for a more intuitive approach, but if onlyinteger values are
used, the range encompasses a total of only 101 intensities, which are
insufficient to represent a broad gradient of grays. Also, the percentile notation
is used in printing to denote how much ink is employed in halftoning, but then
the scale is reversed, being 0% the paper white (no ink) and 100% a solid black
(full ink).
In computing, although the grayscale can be computed through rational
numbers, image pixels are stored in binary, quantized form. Some early
grayscale monitors can only show up to sixteen (4-bit) different shades, but
today grayscale images (as photographs) intended for visual display (both on
screen and printed) are commonly stored with 8 bits per sampled pixel, which
allows 256 different intensities (i.e., shades of gray) to be recorded, typically on
a non-linear scale. The precision provided by this format is barely sufficient to

8
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

avoid visible banding artifacts, but very convenient for programming due to the
fact that a single pixel then occupies a single byte.
Technical uses (e.g. in medical imaging or remote sensing applications) often
require more levels, to make full use of the sensor accuracy (typically 10 or 12
bits per sample) and to guard against roundoff errors in computations. Sixteen
bits per sample (65,536 levels) is a convenient choice for such uses, as
computers manage 16-bit words efficiently. The TIFF and the PNG (among
other) image file formats supports 16-bit grayscale natively, although browsers
and many imaging programs tend to ignore the low order 8 bits of each pixel.
No matter what pixel depth is used, the binary representations assume that 0 is
black and the maximum value (255 at 8 bpp, 65,535 at 16 bpp, etc.) is white, if
not otherwise noted.

Binary Image
A binary image is a digital image that has only two possible values for
each pixel. Typically the two colors used for a binary image are black and white
though any two colors can be used. The color used for the object(s) in the image
is the foreground color while the rest of the image is the background color.
Binary images are also called bi-level or two-level. This means that each pixel is
stored as a single bit (‘0’or‘1’). The names  black and
white,  B&W,monochrome or monochromatic are often used for this concept,
but may also designate any images that have only one sample per pixel, such
asgrayscale images. In Photoshop parlance, a binary image is the same as an
image in "Bitmap" mode.
Binary images often arise in digital image processing as masks or as the result
of certain operations such as segmentation, thresholding, and dithering. Some
input/output devices, such as laser printers, fax machines, and bilevel computer
displays, can only handle bilevel images. A binary image is usually stored in
memory as a bitmap, a packed array of bits. A 640×480 image requires

9
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

37.5 KiB of storage.They can be interpreted as subsets of the two-dimensional


integer lattice Z2; the field of morphological image processing was largely
inspired by this view.

Structuring element (s.e)


In mathematical morphology, a structuring element (s.e.) is a shape, used to
probe or interact with a given image, with the purpose of drawing conclusions
on how this shape fits or misses the shapes in the image. It is typically used in
morphological operations, such as dilation, erosion, opening, and closing, as
well as the hit-or-miss transform.According to Georges Matheron, knowledge
about an object (e.g., an image) depends on the manner in which we probe
(observe) it. In particular, the choice of a certain s.e. for a particular
morphological operation influences the information one can obtain. There are
two main characteristics that are directly related to s.e:
 Shape. For example, the s.e. can be a ``ball" or a line; convex or a ring,
etc. By choosing a particular s.e., one sets a way of differentiating some
objects (or parts of objects) from others, according to their shape or
spatial orientation.
 Size. For example, one s.e. can be a   square or a   square.
Setting the size of the structuring element is similar to setting the
observation scale, and setting the criterion to differentiate image objects
or features according to size.

A structuring element is a small image – used as a moving window whose


support delineates pixel neighborhoods in the image plane.It can be of any
shape, size, or connectivity (more than 1 piece, have holes). In the figure the
circles mark the location of the structuring element’s origin which can be placed
anywhere relative to its support.
Example SE:- Foreground is gray;Background is white;

10
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE4
Reflected Structuring Elements
Z (ρ ,χ ) = Z (−ρ ,−χ ) for all (ρ ,χ )∈ S
Let Z be a SE and let S be the square of pixel locations
that contains the set {(r,c), (−r,−c) | (r,c)∈supp(Z)}. Thenis the reflected
structuring element. Z is Z rotated by 180º around its origin.
Example for reflected S.E.

FIGURE-5

Mathematical particulars and examples of S.E


Structuring elements are particular cases of binary images, usually being small
and simple. In mathematical morphology, binary images are subsets of
an Euclidean space Rd or the integer grid Zd, for some dimension d. Here are
some examples of widely used structuring elements (denoted by B):
 Let E=R2; B is an open disk of radius r, centered at the origin.

11
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

 Let E=Z2; B is a 3x3 square, that is, B={(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),


(0,1),(1,-1),(1,0),(1,1)}.
 Let E=Z2; B is the "cross" given by: B={(-1,0),(0,-1),(0,0),(0,1),(1,0)}.
In the discrete case, a structuring element can also be represented as a set
of pixels on a grid, assuming the values 1 (if the pixel belongs to the structuring
element) or 0 (otherwise).
When used by a hit-or-miss transform, usually the structuring element is a
composite of two disjoint sets (two simple structuring elements), one associated
to the foreground, and one associated to the background of the image to be
probed. In this case, an alternative representation of the composite structuring
element is as a set of pixels which are either set (1, associated to the
foreground), not set (0, associated to the background) or "don't care".

Erosion
Erosion is one of two fundamental operations (the other being dilation)
in Morphological image processing from which all other morphological
operations are based. It was originally defined for binary images, later being
extended to grayscale images, and subsequently to complete lattices.

FIGURE-6;The erosion of the dark-blue square by a disk, resulting in the light-blue square.

Binary erosion
In binary morphology, an image is viewed as a subset of an Euclidean space   
or the integer grid  , for some dimension d.

12
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

The basic idea in binary morphology is to probe an image with a simple, pre-
defined shape, drawing conclusions on how this shape fits or misses the shapes
in the image. This simple "probe" is called structuring element, and is itself a
binary image (i.e., a subset of the space or grid).
Let E be an Euclidean space or an integer grid, and A a binary image in E.
The erosion of the binary image A by the structuring element B is defined by:

where  Bz is the translation of  B  by the vector z, i.e.,


  ,  .
When the structuring element B has a center (e.g., a disk or a square), and this
center is located on the origin of E, then the erosion of A by B can be
understood as the locus of points reached by the center of B when B moves
inside A. For example, the erosion of a square of side 10, centered at the origin,
by a disc of radius 2, also centered at the origin, is a square of side 6 centered at
the origin.
The erosion of A by B is also given by the expression: 

Example
Suppose A is a 13 * 13 matrix and B is a 5 * 1 matrix:
0000000000000
0000000000000
0000000000000
0000000000000
0001111111000 1
0001111111000 1
0001111111000 1
0001111111000 1
0001111111000 1
0000000000000
0000000000000
0000000000000
0000000000000

13
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Assuming that the origin B is at its center, for each pixel in A superimpose the
origin of B, if B is completely contained by A the pixel is retained, else deleted.
The Erosion of A by B is given by
0000000000000
0000000000000
0000000000000
0000000000000
0000000000000
0000000000000
0001111111000
0000000000000
0000000000000
0000000000000
0000000000000
0000000000000
0000000000000

This means that only when B is completely contained inside A that the pixels
values are retained, else it gets deleted or in other words it gets eroded.

Properties
 The erosion is translation invariant.
 It is increasing, that is, if  , then  .
 If the origin of E belongs to the structuring element B, then the erosion
is anti-extensive, i.e.,  .
 The erosion satisfies  , where   denotes
the morphological dilation.
 The erosion is distributive over set intersection

Grayscale erosion
In gray scale morphology, images are functions mapping an Euclidean
space or grid E into  , where   is the set of reals,   is an

14
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

element larger than any real number, and   is an element smaller than
any real number.
Denoting an image by f(x) and the gray scale structuring element by b(x),
the gray scale erosion of f by b is given by

where "inf" denotes the infimum.

Erosions on complete lattices


Complete lattices are partially ordered sets, where every subset has
an infimum and a supremum. In particular, it contains a least element and
a greatest element (also denoted "universe").
Let   be a complete lattice, with infimum and minimum symbolized
by   and  , respectively. Its universe and least element are symbolized
by U and  , respectively. Moreover, let {Xi} be a collection of elements
from L.
An erosion in   is any operator   that distributes over the
infimum, and preserves the universe. I.e.:

 ,
 .

Dilation
Dilation is one of the basic operations in mathematical morphology.
Originally developed for binary images, it has been expanded first
to grayscale images, and then to complete lattices. The dilation operation
usually uses a structuring element for probing and expanding the shapes
contained in the input image.

15
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE-7;The dilation of the dark-blue square by a disk, resulting in the light-blue


square with rounded corners.

Binary Dilation
In binary morphology, dilation is a shift-invariant (translation invariant)
operator, strongly related to the Minkowski addition.
A binary image is viewed in mathematical morphology as a subset of
an Euclidean space Rd or the integer grid Zd, for some dimension d.
LetE be a Euclidean space or an integer grid, A a binary image in E,
and B a structuring element.
The dilation of A by B is defined by:

.
The dilation is commutative, also given by

:  .
If B has a center on the origin, then the dilation of A by B can be
understood as the locus of the points covered by B when the center
of Bmoves inside A. The dilation of a square of side 10, centered at the
origin, by a disk of radius 2, also centered at the origin, is a square of side
12, with rounded corners, centered at the origin. The radius of the
rounded corners is 2.

16
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

The dilation can also be obtained by: 


,
where Bs denotes the symmetric of B, that is
  .

Properties of binary dilation


Here are some properties of the binary dilation operator:
 It is translation invariant.
 It is increasing, that is, if  , then  .
 It is commutative.
 If the origin of E belongs to the structuring element B, then it
is extensive, i.e.,  .
 It is associative, i.e.,  .
 It is distributive over set union.

Grayscale dilation
In grayscale morphology,images are  functions  mapping an Euclidean
space or grid E into  , where   is the set of reals,   is an
element larger than any real number, and   is an element smaller than
any real number.
Grayscale structuring elements are also functions of the same format,
called "structuring functions".
Denoting an image by f(x) and the structuring function by b(x), the
grayscale dilation of  f  by b is given by

,
where "sup" denotes the supremum.

17
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Flat structuring functions


It is common to use flat structuring elements in morphological
applications. Flat structuring functions are functions b(x) in the form

,
where  .
In this case, the dilation is greatly simplified, and given by

In the bounded, discrete case (E is a grid and B is bounded),


the supremum operator can be replaced by the maximum. Thus, dilation
is a particular case of order statistics filters, returning the maximum value
within a moving window (the symmetric of the structuring function
support B).

Dilation on complete lattices


Complete lattices are partially ordered sets, where every subset has
an infimum and a supremum. In particular, it contains a least element and
a greatest element (also denoted "universe").
Let   be a complete lattice, with infimum and minimum symbolized
by   and  , respectively. Its universe and least element are symbolized
by U and  , respectively. Moreover, let {Xi} be a collection of elements
from L.
A dilation is any operator   that distributes over the supremum,
and preserves the least element. I.e.:

 ,
 .

18
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Thresholding of an image
Thresholding is the simplest method of image segmentation. From
a grayscale image, thresholding can be used to create binary images.

FIGURE-8;Original Image FIGURE-9;Threshold effect


on the original Image

Methods
During the thresholding process, individual pixels in an image are marked as
“object” pixels if their value is greater than some threshold value (assuming an
object to be brighter than the background) and as “background” pixels
otherwise. This convention is known asthreshold above. Variants
include threshold below, which is opposite of threshold above; threshold inside,
where a pixel is labeled "object" if its value is between two thresholds;
and threshold outside, which is the opposite of threshold inside (Shapiro, et al.
2001:83). Typically, an object pixel is given a value of “1” while a background
pixel is given a value of “0.” Finally, a binary image is created by coloring each
pixel white or black, depending on a pixel's label's.

Threshold selection
The key parameter in the thresholding process is the choice of the threshold
value (or values, as mentioned earlier). Several different methods for choosing a
threshold exist; users can manually choose a threshold value, or a thresholding

19
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

algorithm can compute a value automatically, which is known as automatic


thresholding (Shapiro, et al. 2001:83). A simple method would be to choose
the mean or median value, the rationale being that if the object pixels are
brighter than the background, they should also be brighter than the average. In a
noiseless image with uniform background and object values, the mean or
median will work well as the threshold, however, this will generally not be the
case. A more sophisticated approach might be to create a histogram of the
image pixel intensities and use the valley point as the threshold. The histogram
approach assumes that there is some average value for the background and
object pixels, but that the actual pixel values have some variation around these
average values. However, this may be computationally expensive, and image
histograms may not have clearly defined valley points, often making the
selection of an accurate threshold difficult. One method that is relatively simple,
does not require much specific knowledge of the image, and is robust
against image noise, is the following iterative method:
1. An initial threshold (T) is chosen, this can be done randomly or according
to any other method desired.
2. The image is segmented into object and background pixels as described
above, creating two sets:
1. G1 = {f(m,n):f(m,n)>T} (object pixels)
2. G2 = {f(m,n):f(m,n) T} (background pixels) (note, f(m,n) is the
value of the pixel located in the mth column, nth row)
3. The average of each set is computed.
1. m1 = average value of G1
2. m2 = average value of G2
4. A new threshold is created that is the average of m1 and m2
1. T’ = (m1 + m2)/2

20
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

5. Go back to step two, now using the new threshold computed in step four,
keep repeating until the new threshold matches the one before it (i.e. until
convergence has been reached).
This iterative algorithm is a special one-dimensional case of the k-means
clustering algorithm, which has been proven to converge at a local minimum—
meaning that a different initial threshold may give a different final result.

Adaptive thresholding
Thresholding is called  adaptive thresholding when a different threshold is
used for different regions in the image. This may also be known
as local or dynamic thresholding (Shapiro, et al. 2001:89).

Categorizing thresholding Methods


Sezgin and Sankur (2004) categorize thresholding methods into the following
six groups based on the information the algorithm manipulates (Sezgin et al.,
2004):
 "histogram shape-based methods, where, for example, the peaks, valleys
and curvatures of the smoothed histogram are analyzed
 clustering-based methods, where the gray-level samples are clustered in
two parts as background and foreground (object), or alternately are
modeled as a mixture of two Gaussians
 entropy-based methods result in algorithms that use the entropy of the
foreground and background regions, the cross-entropy between the
original and binarized image, etc.
 object attribute-based methods search a measure of similarity between the
gray-level and the binarized images, such as fuzzy shape similarity, edge
coincidence, etc.
 [...] spatial methods [that] use higher-order probability distribution and/or
correlation between pixels

21
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

 local methods adapt the threshold value on each pixel to the local image
characteristics."

Multiband thresholding
Colour images can also be thresholded. One approach is to designate a separate
threshold for each of the RGB components of the image and then combine them
with an AND operation. This reflects the way the camera works and how the
data is stored in the computer, but it does not correspond to the way that people
recognize colour. Therefore, the HSL and HSVcolour models are more often
used. An interesting new method uses the CMYK colour model to threshold
colour images (Pham et al., 2007).
In histology images the colour is given by 2 or more dyes, for
example hematoxylin and DAB. The contributions of these two dyes to the
colour image can be established by using colour deconvolution. The incident
light is measured by looking at an unstained part of the slide. Then you measure
the relative absorption of each the 3 RGB components of the image by each
dye. Absorption is defined by Beer's Law. The absorption characteristics for
each dye can be obtained by measuring the RGB components of the colour in
areas of the slide that are only coloured by one dye. The computer software can
solve 3 linear equations for each pixel in the image, one for each colour
channel, in order to resolve the amounts of each of the dyes at each locus in the
image. This method can resolve up to 3 different dyes. The result is an image
for each dye, showing the amount of that dye throughout the image. This allows
the amount of dye to be quantified, which is important for image analysis
of immunohistochemical stains.

Image Histograms
An image histogram is a type of histogram which acts as a graphical
representation of the tonal distribution in a digital image.[1] It plots the number

22
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

of pixels for each tonal value. By looking at the histogram for a specific image a
viewer will be able to judge the entire tonal distribution at a glance.
Image histograms are present on many modern digital cameras. Photographers
can use them as an aid to show the distribution of tones captured, and whether
image detail has been lost to blown-out highlights or blacked-out shadows.[2]
The horizontal axis of the graph represents the tonal variations, while
the vertical axis represents the number of pixels in that particular tone.[1] The
left side of the horizontal axis represents the black and dark areas, the middle
represents medium grey and the right hand side represents light and pure white
areas. The vertical axis represents the size of the area that is captured in each
one of these zones. Thus, the histogram for a very bright image with few dark
areas and/or shadows will have most of its data points on the right side and
center of the graph. Conversely, the histogram for a very dark image will have
the majority of its data points on the left side and center of the graph.

FIGURE-10;Sunflower Image FIGURE-11; Histogram of


sunflower image

Image manipulation and histograms


Image editors typically have provisions to create a histogram of the image being
edited. The histogram plots the number of pixels in the image (vertical axis)
with a particular brightness value (horizontal axis). Algorithms in the digital

23
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

editor allow the user to visually adjust the brightness value of each pixel and to
dynamically display the results as adjustments are made.[3] Improvements in
picture brightness and contrast can thus be obtained.
In the field of Computer Vision, image histograms can be useful tools
for thresholding. Because the information contained in the graph is a
representation of pixel distribution as a function of tonal variation, image
histograms can be analyzed for peaks and/or valleys which can then be used to
determine a threshold value. This threshold value can then be used for edge
detection, image segmentation, and co-occurrence matrices.

Labeling in image processing


Labeling of a binary image is the operation of assigning a unique value to pixels
belonging to the same connected region. Depending on the definition of a
"connected region", different results can be obtained. 

Connected components labeling scans an image and groups its pixels into


components based on pixel connectivity, i.e. all pixels in a connected
component share similar pixel intensity values and are in some way connected
with each other. Once all groups have been determined, each pixel is labeled
with a graylevel or a color (color labeling) according to the component it was
assigned to.
Extracting and labeling of various disjoint and connected components in an
image is central to many automated image analysis applications.

24
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE-12 Connected components labeling

How it works
Connected component labeling works by scanning an image, pixel-by-pixel
(from top to bottom and left to right) in order to identify connected pixel
regions, i.e. regions of adjacent pixels which share the same set of intensity
values V. (For a binary image V={1}; however, in a graylevel image V will take
on a range of values, for example: V={51, 52, 53, ..., 77, 78, 79, 80}.)
Connected component labeling works on binary or graylevel images and
different measures of connectivity are possible. However, for the following we
assume binary input images and 8-connectivity. The connected components
labeling operator scans the image by moving along a row until it comes to a
point p (where p denotes the pixel to be labeled at any stage in the scanning
process) for which V={1}. When this is true, it examines the four neighbors
of p which have already been encountered in the scan (i.e. the neighbors (i) to
the left of p, (ii) above it, and (iii and iv) the two upper diagonal terms). Based
on this information, the labeling of p occurs as follows:
 If all four neighbors are 0, assign a new label to p, else
 if only one neighbor has V={1}, assign its label to p, else
 if more than one of the neighbors have V={1}, assign one of the labels
to p and make a note of the equivalences.

Two widely used square grid topologies are shown below.

FIGURE-13 ;Rectangular grids for connectivity study of pixel P

25
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Recommended use of these grids are:

 4 neighborhood for foreground pixels and 8 neighborhood for background


pixels
 8 neighborhood for foreground pixels and 4 neighborhood for background
pixels

After completing the scan, the equivalent label pairs are sorted into equivalence
classes and a unique label is assigned to each class. As a final step, a second
scan is made through the image, during which each label is replaced by the label
assigned to its equivalence classes. For display, the labels might be different
graylevels or colors.

To illustrate connected components labeling, we start with a simple binary


image containing some distinct artificial objects

After scanning this image and labeling the distinct pixels classes with a different
grayvalue, we obtain the labeled output image

Note that this image was scaled, since the initial grayvalues (1 - 8) would all
appear black on the screen. However, the pixels initially assigned to the lower
classes (1 and 2) are still indiscernible from the background. If we assign a
distinct color to each graylevel we obtain

26
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

The full utility of connected components labeling can be realized in an image


analysis scenario wherein images are pre-processed via some segmentation
(e.g. thresholding) or classification scheme. One application is to use connected
components labeling to count the objects in an image. For example, in the above
simple scene the 8 objects yield 8 different classes.

Labeling image from thresholding process


Example1:
If we want to count the objects in a real world scene like

we first have to threshold the image in order to produce a binary input image
(the implementation being used only takes binary images). Setting all values
above a value of 150 to zero yields

The white dots correspond to the black, dead cells in the original image. The
connected components of this binary image can be seen in

The corresponding colormap shows that the highest value is 163, i.e. the output


contains 163 connected components. In order to better see the result, we now
would like to assign a color to each component. The problem here is that we
cannot find 163 colors where each of them is different enough from all others to

27
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

be distinguished by the human eye. Two possible ways to assign the colors are
as follows:
 We only use a few colors (e.g. 8) which are clearly different from each
other and assign each graylevel of the connected component image to one
of these colors. The result can be seen in

We can now easily distinguish two different components, provided that they
were not assign the same color. However, we lose a lot of information because
the (in this case) 163 graylevels are reduced to 8 different colors.
 We can assign a different color to each grayvalue, many of them being
quite similar. A typical result for the above image would be

Although, we sometimes cannot tell the border between two components when
they are very close to each other, we do not lose any information.
More sophisticated techniques combine both methods. They make sure that two
nearby components always have distinct colors by taking into account the colors
of the neighbors of the component which is going to be assigned a color.
If we compare the above color-labeled images with the original, we can see that
the number of components is quite close to the number of dead cells in the
image. However, we obtain a small difference since some cells merge together
into one component or dead cells are suppressed by the threshold.
Example2:
We encounter greater problems when trying to count the number of turkeys in

28
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Labeling the thresholded image

yields

as a graylevel or

as a color labeled version. Although we managed to assign one connected


component to each turkey, the number of components (196) does not
correspond to the number of turkeys.
The two last examples showed that the connected component labeling is the
easy part of the automated analysis process, whereas the major task is to obtain
a good binary image which separates the objects from the background.

Labeling image from classification process


Finally, we consider the problem of labeling data output from
a classification processes. We can classify multi-spectral images (e.g. a two-
band image consisting of

(visible range) and

29
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

(infra-red range)) in order to find k groupings of the data based on the pixel


intensities clusters. This result is shown in the image

where the multi-spectral image was classified into two groups. If we now apply
connected components labeling, connected geographic regions which belong to
the same intensity classes can be labeled. The result contains 49 different
components, most of them being only a few pixels large. The color labeled
version can be seen in

One could now use this image to further investigate the regions, e.g. if some
components changed their size compared to a reference image or if other
regions merged together.

MATLAB Digital Image Processing Toolbox


Image Processing Toolbox™ provides a comprehensive set of reference-
standard algorithms and graphical tools for image processing, analysis,
visualization, and algorithm development. We can perform image enhancement,
image deblurring, feature detection, noise reduction, image segmentation,
spatial transformations, and image registration. Many functions in the toolbox
are multithreaded to take advantage of multicore and multiprocessor computers.
Image Processing Toolbox supports a diverse set of image types, including high
dynamic range, gigapixel resolution, ICC-compliant color, and tomographic
images. Graphical tools let you explore an image, examine a region of pixels,
adjust the contrast, create contours or histograms, and manipulate regions of
interest (ROIs). With the toolbox algorithms we can restore degraded images,

30
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

detect and measure features, analyze shapes and textures, and adjust the color
balance of images.
Key Features
 Image enhancement, filtering, and deblurring
 Image analysis, including segmentation, morphology, feature extraction,
and measurement
 Spatial transformations and image registration
 Image transforms, including FFT, DCT, Radon, and fan-beam projection
 Workflows for processing, displaying, and navigating arbitrarily large
images
 Modular interactive tools, including ROI selections, histograms, and
distance measurements
 ICC color management
 Multidimensional image processing
 Image-sequence and video display
 DICOM import and export

Analyzing Images using Toolbox


Image Processing Toolbox provides a comprehensive suite of reference-
standard algorithms and graphical tools for image analysis tasks such as
statistical analysis, feature extraction, and property measurement.
Statistical functions let you analyze the general characteristics of an image by:
 Computing the mean or standard deviation
 Determining the intensity values along a line segment
 Displaying an image histogram
 Plotting a profile of intensity values

31
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE-14;Image with histogram for the red channel.

Edge-detection algorithms  let us identify object boundaries in an image.


These algorithms include the Sobel, Prewitt, Roberts, Canny, and Laplacian of
Gaussian methods. The powerful Canny method can detect true weak edges
without being "fooled" by noise.
Image segmentation algorithms determine region boundaries in an image.
You can explore many different approaches to image segmentation, including
automatic thresholding, edge-based methods, and morphology-based methods
such as the watershed transform, often used to segment touching objects.

FIGURE-15;Detection and outlining of an aircraft using segmentation and morphology.

Morphological operators enables us to detect edges, enhance contrast, remove


noise, segment an image into regions, thin regions, or perform skeletonization
on regions. Morphological functions in Image Processing Toolbox include:
 Erosion and dilation
 Opening and closing
 Labeling of connected components
 Watershed segmentation

32
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

 Reconstruction
 Distance transform
Image Processing Toolbox also contains advanced image analysis functions that
lets us:
 Measure the properties of a specified image region, such as the area,
center of mass, and bounding box
 Detect lines and extract line segments from an image using the Hough
transform
 Measure properties, such as surface roughness or color variation, using
texture analysis functions

DIP functions of MATLAB used in the simulation code for solving the
maze
imread
Read image from graphics file
Syntax
A=imread(filename,fmt)
[X,map]=imread(...)…….reads the indexed image in filename into X and its
associated colormap into map. Colormap values in the image file are
automatically rescaled into the range [0,1].
[...]=imread(filename)….. attempts to infer the format of the file from its
content
[...]=imread(URL,...)…… reads the image from an Internet URL. The URL
must include the protocol type (e.g., http://).
[...] = imread(...,Param1,Val1,Param2,Val2...) ………..specifies parameters that
control various characteristics of the operations for specific formats.

33
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Description
A = imread(filename, fmt) reads a grayscale or color image from the file
specified by the string filename. If the file is not in the current folder, or in a
folder on the MATLAB path, specify the full pathname.
The text string fmt specifies the format of the file by its standard file extension.
For example, specify 'gif' for Graphics Interchange Format files. To see a list of
supported formats, with their file extensions, use the imformats function. If
imread cannot find a file named filename, it looks for a file named filename.fmt.

The return value A is an array containing the image data. If the file contains a
grayscale image, A is an M-by-N array. If the file contains a truecolor image, A
is an M-by-N-by-3 array. For TIFF files containing color images that use the
CMYK color space, A is an M-by-N-by-4 array. The class of A depends on the
bits-per-sample of the image data, rounded to the next byte boundary.

imshow
imshow is a function used to Display the image.
Syntax
imshow(I)
imshow(I,[low,high])
imshow(RGB)
imshow(BW)
imshow(X,map)
imshow(filename)
himage=imshow(...)
imshow(..., param1, val1, param2, val2,...)

Description
imshow(I) displays the grayscale image I.

34
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

imshow(I,[low high]) displays the grayscale image I, specifying the display


range for I in [low high]. The value low (and any value less than low) displays
as black; the value high (and any value greater than high) displays as white.
Values in between are displayed as intermediate shades of gray, using the
default number of gray levels. If you use an empty matrix ([]) for [low high],
imshow uses [min(I(:)) max(I(:))]; that is, the minimum value in I is displayed
as black, and the maximum value is displayed as white.
imshow(RGB) displays the truecolor image RGB.
imshow(BW) displays the binary image BW. imshow displays pixels with the
value 0 (zero) as black and pixels with the value 1 as white.
imshow(X,map) displays the indexed image X with the colormap map. A color
map matrix may have any number of rows, but it must have exactly 3 columns.
Each row is interpreted as a color, with the first element specifying the intensity
of red light, the second green, and the third blue. Color intensity can be
specified on the interval 0.0 to 1.0.
imshow(filename) displays the image stored in the graphics file filename. The
file must contain an image that can be read by imread or dicomread. imshow
calls imread or dicomread to read the image from the file, but does not store the
image data in the MATLAB workspace. If the file contains multiple images,
imshow displays the first image in the file. The file must be in the current
directory or on the MATLAB path.
himage = imshow(...) returns the handle to the image object created by imshow.
imshow(..., param1, val1, param2, val2,...) displays the image, specifying
parameters and corresponding values that control various aspects of the image
display. The following table lists all imshow parameters in alphabetical order.
Parameter names can be abbreviated, and case does not matter.

Set
Set Handle Graphics object properties

35
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Syntax
set(H,'PropertyName',PropertyValue,...)
set(H,a)
set(H,pn,pv,...)
set(H,pn,MxN_pv)
a=set(h)
pv = set(h,'PropertyName')

Description
set(H,'PropertyName',PropertyValue,...) sets the named properties to
the specified values on the object(s) identified by H. H can be a vector of
handles, in which case set sets the properties' values for all the objects.
set(H,a) sets the named properties to the specified values on the object(s)
identified by H. a is a structure array whose field names are the object
property names and whose field values are the values of the
corresponding properties.
set(H,pn,pv,...) sets the named properties specified in the cell array pn to
the corresponding value in the cell array pv for all objects identified in H.
set(H,pn,MxN_pv) sets n property values on each of m graphics objects,
where m = length(H) and n is equal to the number of property names
contained in the cell array pn. This allows you to set a given group of
properties to different values on each object.
a = set(h) returns the user-settable properties and possible values for the
object identified by h. a is a structure array whose field names are the
object's property names and whose field values are the possible values of
the corresponding properties. If you do not specify an output argument,
the MATLAB software displays the information on the screen. h must be
scalar.

36
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

pv = set(h,'PropertyName') returns the possible values for the named


property. If the possible values are strings, set returns each in a cell of the
cell array pv. For other properties, set returns a statement indicating that
PropertyName does not have a fixed set of property values. If you do not
specify an output argument, MATLAB displays the information on the
screen. h must be scalar.

uint8
Stored integer value of fi object as built-in uint8.uint8 converts data to
unsigned 8 bit integer.
Syntax
c = uint8(a);
Description
Fixed-point numbers can be represented as
Real-world value = (slope X stored integer)+bias;
The stored integer is the raw binary number, in which the binary point is
assumed to be at the far right of the word.
c = uint8(a) returns the stored integer value of fi object a as a built-in
uint8. If the stored integer word length is too big for a uint8, or if the
stored integer is signed, the returned value saturates to a uint8.

label2rgb
Convert label matrix into RGB image
Syntax
RGB = label2rgb(L)
RGB = label2rgb(L, map)
RGB = label2rgb(L, map, zerocolor)
RGB = label2rgb(L, map, zerocolor, order)

37
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Description
RGB = label2rgb(L) converts a label matrix, L, such as those returned
by labelmatrix, bwlabel, bwlabeln, or watershed, into an RGB color
image for the purpose of visualizing the labeled regions. The label2rgb
function determines the color to assign to each object based on the
number of objects in the label matrix and range of colors in the colormap.
The label2rgb function picks colors from the entire range.
RGB = label2rgb(L, map) defines the colormap map to be used in the
RGB image. map can have any of the following values:
 n-by-3 colormap matrix
 String containing the name of a MATLAB colormap function, such as
'jet' or 'gray' (See colormap for a list of supported colormaps.)
 Function handle of a colormap function, such as @jet or @gray
If you do not specify map, the default value is 'jet'.
RGB = label2rgb(L, map, zerocolor) defines the RGB color of the
elements labeled 0 (zero) in the input label matrix L. As the value of
zerocolor, specify an RGB triple.

bwlabel
Label connected components in 2-D binary image
Syntax
L = bwlabel(BW, n)
[L, num] = bwlabel(BW, n)

Description

38
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

L = bwlabel(BW, n) returns a matrix L, of the same size as BW,


containing labels for the connected objects in BW. The variable n can
have a value of either 4 or 8, where 4 specifies 4-connected objects and 8
specifies 8-connected objects. If the argument is omitted, it defaults to 8.
The elements of L are integer values greater than or equal to 0. The pixels
labeled 0 are the background. The pixels labeled 1 make up one object;
the pixels labeled 2 make up a second object; and so on.
[L, num] = bwlabel(BW, n) returns in num the number of connected
objects found in BW.

imdilate
imdilate is a function that is used to Dilate the image
Syntax
IM2 = imdilate(IM,SE)
IM2 = imdilate(IM,NHOOD)
IM2 = imdilate(IM,SE,PACKOPT)
IM2 = imdilate(...,SHAPE)

Description
IM2 = imdilate(IM,SE) dilates the grayscale, binary, or packed binary
image IM, returning the dilated image, IM2. The argument SE is a
structuring element object, or array of structuring element objects,
returned by the strel function.
If IM is logical and the structuring element is flat, imdilate performs
binary dilation; otherwise, it performs grayscale dilation. If SE is an array
of structuring element objects, imdilate performs multiple dilations of the
input image, using each structuring element in SE in succession.
IM2 = imdilate(IM,NHOOD) dilates the image IM, where NHOOD is a
matrix of 0's and 1's that specifies the structuring element neighborhood.

39
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

This is equivalent to the syntax imdilate(IM,strel(NHOOD)). The


imdilate function determines the center element of the neighborhood by
floor((size(NHOOD)+1)/2).
IM2 = imdilate(IM,SE,PACKOPT) or
imdilate(IM,NHOOD,PACKOPT) specifies whether IM is a packed
binary image. PACKOPT can have either of the following values. Default
value is enclosed in braces ({}).
IM2 = imdilate(...,SHAPE) specifies the size of the output image.
SHAPE can have either of the following values. Default value is enclosed in
braces ({}).

imfill
Fill image regions and holes
Syntax
BW2 = imfill(BW)
[BW2,locations] = imfill(BW)
BW2 = imfill(BW,locations)
BW2 = imfill(BW,'holes')
I2 = imfill(I)
BW2 = imfill(BW,locations,conn)

Description
BW2 = imfill(BW) displays the binary image BW on the screen and lets
you define the region to fill by selecting points interactively by using the
mouse. To use this interactive syntax, BW must be a 2-D image. Press
Backspace or Delete to remove the previously selected point. A shift-
click, right-click, or double-click selects a final point and starts the fill
operation. Pressing Return finishes the selection without adding a point.

40
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

[BW2,locations] = imfill(BW) returns the locations of points selected


interactively in locations. locations is a vector of linear indices into the
input image. To use this interactive syntax, BW must be a 2-D image.
BW2 = imfill(BW,locations) performs a flood-fill operation on
background pixels of the binary image BW, starting from the points
specified in locations. If locations is a P-by-1 vector, it contains the linear
indices of the starting locations. If locations is a P-by-ndims(BW) matrix,
each row contains the array indices of one of the starting locations.
BW2 = imfill(BW,'holes') fills holes in the binary image BW. A hole is a
set of background pixels that cannot be reached by filling in the
background from the edge of the image.
I2 = imfill(I) fills holes in the grayscale image I. In this syntax, a hole is
defined as an area of dark pixels surrounded by lighter pixels.
BW2 = imfill(BW,locations,conn) fills the area defined by locations,
where conn specifies the connectivity. conn can have any of the following
scalar values.

imerode
imerode is the function used to Erode the image
Syntax
IM2 = imerode(IM,SE)
IM2 = imerode(IM,NHOOD)
IM2 = imerode(...,PACKOPT,M)
IM2 = imerode(...,SHAPE)

Description
IM2 = imerode(IM,SE) erodes the grayscale, binary, or packed binary
image IM, returning the eroded image IM2. The argument SE is a

41
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

structuring element object or array of structuring element objects returned


by the strel function.
If IM is logical and the structuring element is flat, imerode performs
binary erosion; otherwise it performs grayscale erosion. If SE is an array
of structuring element objects, imerode performs multiple erosions of the
input image, using each structuring element in SE in succession.
IM2 = imerode(IM,NHOOD) erodes the image IM, where NHOOD is
an array of 0's and 1's that specifies the structuring element
neighborhood. This is equivalent to the syntax
imerode(IM,strel(NHOOD)). The imerode function determines the center
element of the neighborhood by floor((size(NHOOD)+1)/2).
IM2 = imerode(...,PACKOPT,M) specifies whether IM is a packed
binary image and, if it is, provides the row dimension M of the original
unpacked image. PACKOPT can have either of the following values.
Default value is enclosed in braces ({}).
If PACKOPT is 'ispacked', you must specify a value for M.
IM2 = imerode(...,SHAPE) specifies the size of the output image.
SHAPE can have either of the following values. Default value is enclosed
in braces ({}).

uigetfile
Open standard dialog box for retrieving files
Syntax
filename = uigetfile
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle)
[FileName,PathName,FilterIndex] =
uigetfile(FilterSpec,DialogTitle,DefaultName)
[FileName,PathName,FilterIndex] = uigetfile(...,'MultiSelect',selectmode)

42
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Description
filename = uigetfile displays a modal dialog box that lists files in the current
folder and enables you to select or enter the name of a file. If the filename is
valid and if the file exists, uigetfile returns the filename as a string when you
click Open. Otherwise uigetfile displays an appropriate error message, after
which control returns to the dialog box. You can then enter another filename or
click Cancel. If you click Cancel or close the dialog window, uigetfile returns
0. Successful execution of uigetfile does not open a file; it only returns the name
of an existing file that you identify.
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec) displays
only those files with extensions that match FilterSpec. On some platforms
uigetfile also displays the files that do not match FilterSpec in grey. The
uigetfile function appends 'All Files' to the list of file types. FilterSpec
can be a string or a cell array of strings, and can include the * wildcard.
 If FilterSpec is a filename, that filename displays, selected in the File
name field. The extension of the file is the default filter.
 FilterSpec can include a path. That path can contain '.','..', \, '/', or '~'. For
example, '../*.m' lists all code files in the folder above the current folder.
 If FilterSpec is a folder name, uigetfile displays the contents of that
folder, the File name field is empty, and no filter applies. To specify a
folder name, make the last character of FilterSpec either '\' or '/'.
 If FilterSpec is a cell array of strings, it can include two columns. The
first column contains a list of file extensions. The optional second column
contains a corresponding list of descriptions. These descriptions replace
standard descriptions in the Files of type field. A description cannot be
an empty string. The second and third examples illustrate use of a cell
array as FilterSpec.

43
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

If FilterSpec is missing or empty, uigetfile uses the default list of file


types (for example, all MATLAB files).
After you click Open and if the filename exists,uigetfile returns the name
of the file in FileName and its path in PathName. If you click Cancel or
close the dialog window, the function sets FileName and PathName to 0.
FilterIndex is the index of the filter selected in the dialog box. Indexing
starts at 1. If you click Cancel or close the dialog window, the function
sets FilterIndex to 0.
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle)
displays a dialog box that has the title DialogTitle. To use the default file
types and specify a dialog title, enter
uigetfile('',DialogTitle)
[FileName,PathName,FilterIndex]=uigetfile(FilterSpec,DialogTitle,DefaultName)
displays a dialog box in which the filename specified by DefaultName appears
in the File name field. DefaultName can also be a path or a path/filename. In
this case, uigetfile opens the dialog box in the folder specified by the path. You
can use '.','..', \, or '/' in the DefaultName argument. To specify a folder name,
make the last character of DefaultName either '\' or '/'. If the specified path does
not exist, uigetfile opens the dialog box in the current folder.
[FileName,PathName,FilterIndex] = uigetfile(...,'MultiSelect',selectmode)
opens the dialog in multiselect mode. Valid values for selectmode are 'on' and
'off' (the default, which allows single selection only). If 'MultiSelect' is 'on' and
you select more than one file in the dialog box, then FileName is a cell array of
strings. Each array element contains the name of a selected file. Filenames in
the cell array are sorted in the order your platform uses. Because multiple
selections are always in the same folder, PathName is always a string
identifying a single folder.
If you include either of the "wildcard" characters '*' or '?' in a file name,
uigetfile does not respond to clicking Open. The dialog box remains open until

44
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

you cancel it or remove the wildcard characters. This restriction applies to all
platforms, even to file systems that permit these characters in file names.

uiwait
Block program execution and wait for resume
Syntax
uiwait
uiwait(h)
uiwait(h,timeout)

Description
uiwait blocks execution until uiresume is called or the current figure is deleted.
This syntax is the same as uiwait(gcf).
uiwait(h) blocks execution until uiresume is called or the figure h is deleted.
uiwait(h,timeout) blocks execution until uiresume is called, the figure h is
deleted, or timeout seconds elapse. The minimum value of timeout is 1. If
uiwait receives a smaller value, it issues a warning and uses a 1 second timeout.

questdlg
used to Create and open question dialog box
Syntax
button = questdlg('qstring')
button = questdlg('qstring','title')
button = questdlg('qstring','title',default)
button = questdlg('qstring','title','str1','str2',default)
button = questdlg('qstring','title','str1','str2','str3',default)
button = questdlg('qstring','title', ..., options)

Description

45
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

button = questdlg('qstring') displays a modal dialog box presenting the


question 'qstring'. The dialog has three default buttons, Yes, No, and Cancel. If
the user presses one of these three buttons, button is set to the name of the
button pressed. If the user presses the close button on the dialog without making
a choice, button is set to the empty string. If the user presses the Return key,
button is set to 'Yes'. 'qstring' is a cell array or a string that automatically wraps
to fit within the dialog box.
button = questdlg('qstring','title') displays a question dialog with 'title'
displayed in the dialog's title bar.
button = questdlg('qstring','title',default) specifies which push button is the
default in the event that the Return key is pressed. 'default' must be 'Yes', 'No',
or 'Cancel'.
button =questdlg('qstring','title','str1','str2',default) creates a question dialog
box with two push buttons labeled 'str1' and 'str2'. default specifies the default
button selection and must be 'str1' or 'str2'.
button = questdlg('qstring','title','str1','str2','str3',default) creates a question
dialog box with three push buttons labeled 'str1', 'str2', and 'str3'. default
specifies the default button selection and must be 'str1', 'str2', or 'str3'.
When default is specified, but is not set to one of the button names, pressing the
Enter key displays a warning and the dialog remains open.
button = questdlg('qstring','title', ..., options) replaces the string default with
a structure, options. The structure specifies which button string is the default
answer, and whether to use TeX to interpret the question string, qstring. Button
strings and dialog titles cannot use TeX interpretation. The options structure
must include the fields Default and Interpreter, both strings. It can include other
fields, but questdlg does not use them. You can set Interpreter to 'none' or 'tex'.
If the Default field does not contain a valid button name, a command window
warning is issued and the dialog box does not respond to pressing the Enter
key.

46
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

std
Standard deviation
Syntax
s = std(X)
s = std(X,flag)
s = std(X,flag,dim)

Description
s = std(X), where X is a vector, returns the standard deviation using (1) above.
The result s is the square root of an unbiased estimator of the variance of the
population from which X is drawn, as long as X consists of independent,
identically distributed samples.
If X is a matrix, std(X) returns a row vector containing the standard deviation of
the elements of each column of X. If X is a multidimensional array, std(X) is
the standard deviation of the elements along the first nonsingleton dimension of
X.
s = std(X,flag) for flag = 0, is the same as std(X). For flag = 1, std(X,1) returns
the standard deviation using (2) above, producing the second moment of the set
of values about their mean.
s = std(X,flag,dim) computes the standard deviations along the dimension of X
specified by scalar dim. Set flag to 0 to normalize Y by n-1; set flag to 1 to
normalize by n.

47
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

RESULT

FIGURE-16;Maze to be solved

48
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Binary image and labeled image output

49
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

FIGURE-17

50
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Dilated and Eroded Images and The difference between them

FIGURE-18

51
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Final solution:Solved maze with path shown in red colour

FIGURE-19

52
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

Conclusion
By implementing the digital image processing and analysis tools of MATLAB,
we have been able to develop the code for solving the mazes, in
which,mathematical morphology and its basic operators ‘Dilation’ and
‘Erosion’ plays the main role.Also the study of different thersholding & labeling
techniques of image processing helped us in achieving the result.
Thus our termpaper on”Maze solving using Imaze Analysis” has been
successfully completed .

53
Koneru Lakshmaiah College Of Engineering
Maze Solving Using Image Analysis

References

1.Digital Image Processing 3rd edition by Rafael C.Gonzalez and Richard


E.Woods
2.www.Wikipedia.com..... search on image processing and various topics
3.www.mathworks.com
4.http://www.ee.lamar.edu/gleb/dip/10-1%20-%20Morphological%20Image
%20Processing.pdf
5.Lectures on Image Processing : Alan Peters : Free Download &
Streaming : Internet Archive

54
Koneru Lakshmaiah College Of Engineering

You might also like