Professional Documents
Culture Documents
Every orientation work has an imprint of many people and it becomes the duty of the
team to express deep gratitude for the same.
We are very grateful to our Head of the Computer Technology Department Prof.
N.J.Janwe for providing us with an environment to complete our project successfully and for his
unwavering support during the entire course of this project.
We take this opportunity to express our gratitude towards our esteemed project guide Mr.
Prof. N.J.Janwe, for his valuable guidance and support. We are also earnestly thankful to our,
project in-charge Prof. Manisha Pise and Prof. Manisha More, for their encouragement and
timely guidance.
We thank all the staff members, for their indispensable support, priceless suggestions and
for valuable time lent as and when required.
Finally, we take this opportunity to extend our deep appreciation to our project members
and friends, for all that they meant to us during the crucial times of the completion of our project.
1
INDEX
1. CHAPTER 1 10
ABSTRACT
2. CHAPTER 2 11
INTRODUCTION
2.1 DEFINITION
3 CHAPTER 3 13
LITERATURE SURVEY
4 CHAPTER 4 14
PROBLEM STATEMENT
2
5 CHAPTER 5 15
PROPOSED SOLUTION
6 CHAPTER 6 16
SYSTEM REQUIREMENT
7 CHAPTER 7 17
TECHNOLOGIES
FEATURE
3
7.1.5 COLOR UNIFORMITY
7.1.8 QUANTIZATION
7.1.9 ADVANTAGES
7.2.1 DEFINITION
WAVELET TRANSFORM
4
7.3 SHAPE FEATURE
7.3.1 DEFINITION
8 CHAPTER 8 41
ARCHITECTURE OF PROJECT
9 CHAPTER 9 42
CODE
9.1 GUI
10 CHAPTER 10 67
5
OUTPUT
10.1 COLOR
10.2 TEXTURE
10.3 SHAPE
11 CHAPTER 11 71
11.1 ADVANTAGES
11.2 DISADVANTAGES
12 CHAPTER 12 72
CONCLUSION
13 CHAPTER 13 73
FUTURE EXPANSION
14 CHAPTER 14 74
REFERENCES
15 CHAPTER 15 75
BIBLIOGRAPHY
6
FIGURE INDEX
7
WAVELET TRANSFORM
14. FLOWCHART FOR 33
TEXTURE
15. BOUNDARY-BASED AND 34
REGION-BASED
16. HOUGH TRANSFORM 35
17. CO-ORDINATE POINTS 36
AND POSSIBLE STRAIGHT
LINE FITTINGS
18. PARAMETRIC 37
DESCRIPTION OF A
STRAIGHT LINE
19. FLOWCHART FOR SHAPE 39
20. ARCHITECTURE OF 40
PROJECT
8
CHAPTER 1
ABSTRACT
The purpose of this report is to describe our research and solution to the problem of
designing a Content Based Image Retrieval, CBIR system. It outlines the problem, the proposed
solution, the final solution and the accomplishments achieved. Due to the enormous increase in
image database sizes, as well as its vast deployment in various applications, the need for CBIR
development arose. Firstly, this report outlines a description of the primitive features of an
image; texture, colour, and shape. These features are extracted and used as the basis for a
similarity check between images. The algorithms used to calculate the similarity between
extracted features, are then explained. Our final result was a MatLab built software application,
with an image database, that utilized texture and colour features of the images in the database as
the basis of comparison and retrieval. The structure of the final software application is illustrated.
Furthermore, the results of its performance are illustrated by a detailed example.
9
CHAPTER 2
INTRODUCTION
2. Introduction to CBIR:-
2.1 Definition:-
CBIR or Content Based Image Retrieval is the retrieval of images based on visual features
such as colour, texture and shape. Reasons for its development are that in many large image
databases, traditional methods of image indexing have proven to be insufficient, laborious, and
extremely time consuming. These old methods of image indexing, ranging from storing an image
in the database and associating it with a keyword or number, to associating it with a categorized
description, have become obsolete. This is not CBIR. In CBIR, each image that is stored in the
database has its features extracted and compared to the features of the query image. It involves
two steps:
10
Feature Extraction: The first step in the process is extracting image features to a
distinguishable extent.
Matching: The second step involves matching these features to yield a result that is
visually similar.
QBIC or Query By Image Content was developed by IBM, Almaden Research Centre, to
allow users to graphically pose and refine queries based on multiple visual properties
such as colour, texture and shape. It supports queries based on input images, user-
constructed sketches, and selected colour and texture patterns.
VIR Image Engine by Virage Inc., like QBIC, enables image retrieval based on primitive
attributes such as colour, texture and structure. It examines the pixels in the image and
performs an analysis process, deriving image characterization features.
VisualSEEK and WebSEEK were developed by the Department of Electrical
Engineering, Columbia University. Both these systems support colour and spatial
location matching as well as texture matching.
11
NeTra was developed by the Department of Electrical and Computer Engineering,
University of California. It supports colour, shape, spatial layout and texture matching, as
well as image segmentation.
MARS or Multimedia Analysis and Retrieval System was developed by the Beckman
Institute for Advanced Science and Technology, University of Illinois. It supports colour,
spatial layout, texture and shape matching.
Viper or Visual Information Processing for Enhanced Retrieval was developed at the
Computer Vision Group, University of Geneva. It supports colour and texture matching.
CHAPTER 3
LITERATURE SURVEY
The features drawn from histograms between the query image and corresponding
database images, in RGB color space, serve as local descriptors of color and texture. From
Reference [1], we have studied and implemented Color Histograms and the Quadratic Distance
formulae for the computation of two Histograms.
The Hough Transform technique for Shape Detection has been implemented by
taking reference from [2] as given in the reference chapter.
The concept of Edge Detection has been implemented by taking reference from
Reference no. [3].
The concept of Color Space and Color Segmentation has been studied by taking
reference from Reference no. [4].
12
CHAPTER 4
PROBLEM STATEMENT
Image databases and collections can be enormous in size, containing hundreds, thousands
or even millions of images. The conventional method of image retrieval is searching for a
keyword that would match the descriptive keyword assigned to the image by a human
categorizer [6]. Currently under development, even though several systems exist, is the retrieval
of images based on their content, called Content Based Image Retrieval, CBIR. While
computationally expensive, the results are far more accurate than conventional image indexing.
Hence, there exists a tradeoff between accuracy and computational cost. This tradeoff decreases
as more efficient algorithms are utilized and increased computational power becomes
inexpensive.
13
The problem involves entering an image as a query into a software application that is
designed to employ CBIR techniques in extracting visual properties, and matching them. This is
done to retrieve images in the database that are visually similar to the query image.
CHAPTER 5
PROPOSED SOLUTION:-
The solution initially proposed was to extract the primitive features of a query image and
compare them to those of database images. The image features under consideration were colour,
texture and shape. Thus, using matching and comparison algorithms, the colour, texture and
shape features of one image are compared and matched to the corresponding features of another
image. This comparison is performed using colour, texture and shape distance metrics. In the
end, these metrics are performed one after another, so as to retrieve database images that are
similar to the query. The similarity between features was to be calculated using algorithms used
by well known CBIR systems such as IBM's QBIC. For each specific feature there was a specific
algorithm for extraction and another for matching.
14
Figure: Block Diagram of CBIR
CHAPTER 6
SYSTEM REQUIREMENTS
MatLab:-
15
MATLAB is a numerical computing environment and fourth-generation programming
language. Developed by The MathWorks, MATLAB allows matrix manipulation, plotting of
functions and data, implementation of algorithms, creation of user interfaces, and interfacing
with programs in other languages.
Images can be conveniently represented as matrices in MATLAB. One can open an image
as a matrix using imread command. The matrix may simply be m x n form or it may be 3
dimensional arrays or it may be an indexed matrix, depending upon image type. The image
processing may be done simply by matrix calculation or matrix manipulation.
RAM of 1 GB capacity
Hard disk of 40 GB capacity
CHAPTER 7
TECHNOLOGIES
7. Feature:-
Feature is anything that is localized, meaningful and detectable. In an image noticeable
features include corners, lines, objects, color, shape, spatial location, motion and texture. No
particular visual feature is most suitable for retrieval of all types of images.
Color visual feature is most suitable for describing and representing color images.
16
Texture is most suitable for describing and representing visual patterns, surface properties
and scene depth. CBIR system using texture is particularly useful in satellite images,
medical images and natural scenes like clouds.
Shape is suitable for representing and describing boundaries of real world objects and
edges. In reality no one particular feature can completely describe an image.
Histogram-based search method can be applied in two different color spaces. Histogram
search characterizes an image by its color distribution, or histogram. Many histogram distances
can be used to define the similarity of two color histogram representations. Euclidean distance
and its variations can be used.
A color space is defined as a model for representing color in terms of intensity values.
Typically, a color space defines a one- to four-dimensional space. The following two models are
commonly used in color image retrieval system.
The RGB color model is composed of the primary colors Red, Green, and Blue. They
are considered the "additive primaries" since the colors are added together to produce the desired
color. The RGB model uses the Cartesian coordinate system as shown in Figure 1. (a). Notice
the diagonal from (0,0,0) black to (1,1,1) white which represents the grey-scale. Figure 1. (b) is a
view of the RGB color model looking down from "White" to origin.
17
Figure 1. (a) RGB coordinates system
18
7.1.1.b. HSV Color Model:-
The HSV stands for the Hue, Saturation, and Value based on the artists (Tint, Shade,
and Tone). The coordinate system in a hexacone in Figure 2.(a). And Figure 2.(b) a view of the
HSV color model. The Value represents intensity of a color. The hue and saturation components
are intimately related to the way human eye perceives color resulting in image processing
algorithms with physiological basis. As hue varies from 0 to 1.0, the corresponding colors vary
from red, through yellow, green, cyan, blue, and magenta, back to red, so that there are actually
red values both at 0 and 1.0. As saturation varies from 0 to 1.0, the corresponding colors (hues)
vary from unsaturated (shades of gray) to fully saturated (no white component). As value, or
brightness, varies from 0 to 1.0, the corresponding colors become increasingly brighter.
19
Figure 2. (b) HSV color model
In order to use a good color space for a specific application, color conversion is needed
between color spaces. The good color space for image retrieval system should preserve the
perceived color differences. In other words, the numerical Euclidean difference should
approximate the human perceived difference.
In Figure 3., the obtainable HSV colors lie within a triangle whose vertices are defined by the
three primary colors in RGB space:
20
.
Figure 3. Obtainable HSV color from RGB color space
The hue of the point P is the measured angle between the line connecting P to the triangle
center and line connecting RED point to the triangle center.The saturation of the point P is the
distance between P and triangle center.The value (intensity) of the point P is represented as
height on a line perpendicular to the triangle and passing through its center.The grayscale points
are situated onto the same line. And the conversion formula is as follows:
,
,
The color histogram for an image is constructed by counting the number of pixels of
each color. The following steps are followed for computing the color histogram:
21
(3) Computation of histograms.
An image histogram refers to the probability mass function of the image intensities. This
is extended for color images to capture the joint probabilities of the intensities of the three color
channels. More formally, the color histogram is defined by,
where A, B and C represent the three color channels (R, G, B or H, S, V) and N is the number of
pixels in the image.
The RGB color space is far from being perceptually uniform. To obtain a good color
representation of the image by uniformly sampling the RGB space it is necessary to select the
quantization step sizes to be fine enough such that distinct colors are not assigned to the same
bin. The drawback is that over sampling at the same time produces a larger set of colors than
may be needed. The increase in the number of bins in the histogram impacts performance of
database retrieval.
However, the HSV color space offers improved perceptual uniformity. It represents with
equal emphasis the three color variants that characterize color: Hue, Saturation and Value
(Intensity). This separation is attractive because color image processing performed independently
on the color channels does not introduce false colors. Furthermore, it is easier to compensate for
many artifacts and color distortions. For example, lighting and shading artifacts are typically be
isolated to the lightness channel. Thus we have converted RGB color space to HSV color space
and computed the histogram.
22
7.1.6. Color Histogram Discrimination:-
There are several distance formulas for measuring the similarity of color histograms.
This is because visual perception determines similarity rather than closeness of the probability
distributions. Essentially, the color distance formulas arrive at a measure of similarity between
images based on the perception of color content.
Three distance formulas that have been used for image retrieval including histogram Euclidean
distance, histogram intersection and histogram quadratic (cross) distance.These three histogram
distance measures are used in RGB color space and in HSV color space separately, which makes
up the six retrieval methods.
Let h and g represent two color histograms. The euclidean distance between the color
histograms h and g can be computed as:
In this distance formula, there is only comparison between the identical bins in the
respective histograms. Two different bins may represent perceptually similar colors but are not
compared cross-wise. All bins contribute equally to the distance.
7.1.8. Quantization:
23
In order to reduce computation time, a 256x256x256 = 16777216 color image is
quantized into a 8 x 8 x 8 = 512 color image in RGB color space. Otherwise, it will take really
long time to compute and compare 16777216 bins of a histogram with others. This is a trade-off
between performance and time. A RGB color space image should first be transformed to a HSV
color space image. In HSV color space, H is quantized to 18 levels and S & V is quantized to 3
levels. The quantized HSV space has 18x3x3 = 162 histogram bins. Once a query image and a
retrieval method are chosen by users, the rest of whose process is done automatically. However,
the histogram data for all images in database are computed and saved in DB (Database) in
advance so that only the image indexes and histogram data can be used to compare the query
image with images in DB.
7.1.9. Advantage:-
In a viewpoint of computation time, using HSV color space is faster than using RGB
color space. Thus, we can conclude that the Histogram Euclidean-based image retrieval in HSV
color space is most desirable among six retrieval methods mentioned in considering both
computation time and retrieval effectiveness
24
7.2. Texture Feature:-
7.2.1. Definition:-
Texture is that innate property of all surfaces that describes visual patterns, each having
properties of homogeneity. It contains important information about the structural arrangement of
the surface, such as; clouds, leaves, bricks, fabric, etc. It also describes the relationship of the
surface to the surrounding environment. In short, it is a feature that describes the distinctive
physical composition of a surface.
25
(c) Rocks
(a) Clouds
(b) Bricks
Coarseness
Contrast
Directionality
Line-likeness
Regularity
Roughness
Figure: Examples of Textures…
There are three principal approaches used to describe texture; statistical, structural and
spectral.
Statistical techniques characterize textures using the statistical properties of the grey
levels of the points/pixels comprising a surface image. Typically, these properties are
computed using: the grey level co-occurrence matrix of the surface, or the wavelet
transformation of the surface.
Structural techniques characterize textures as being composed of simple primitive
structures called “texels” (or texture elements). These are arranged regularly on a
surface according to some surface arrangement rules.
Spectral techniques are based on properties of the Fourier spectrum and describe
global periodicity of the grey levels of a surface by identifying high-energy peaks in
the Fourier spectrum.
26
For optimum classification purposes, what concern us are the statistical techniques of
characterization. This is because it is these techniques that result in computing texture properties.
The most popular statistical representations of texture are:
Co-occurrence Matrix
Tamura Texture
Wavelet Transform
27
example; with an 8 grey-level image representation and a vector t that considers only one
neighbor, we would find:
At first the co-occurrence matrix is constructed, based on the orientation and distance
between image pixels. Then meaningful statistics are extracted from the matrix as the texture
representation. Haralick proposed the following texture features:
28
10. Difference Variance
11. Difference Entropy
12. Measure of Correlation 1
13. Measure of Correlation 2
14. Local Mean
Hence, for each Haralick texture feature, we obtain a co-occurrence matrix. These co-
occurrence matrices represent the spatial distribution and the dependence of the grey levels
within a local area. Each (i,j) th entry in the matrices, represents the probability of going from one
pixel with a grey level of 'i' to another with a grey level of 'j' under a predefined distance and
angle. From these matrices, sets of statistical measures are computed, called feature vectors.
By observing psychological studies in the human visual perception, Tamura explored the
texture representation using computational approximations to the three main texture features of:
coarseness, contrast, and directionality. Each of these texture features are approximately
computed using algorithms.
Coarseness is the measure of granularity of an image, or average size of regions that have
the same intensity.
Contrast is the measure of vividness of the texture pattern. Therefore, the bigger the
blocks those make up the image, the higher the contrast. It is affected by the use of
varying black and white intensities.
Directionality is the measure of directions of the grey values within the image [12].
29
a curve, signal etc., can be described in terms of a coarse level description in addition to others
with details that range from broad to narrow scales.
Unlike the usage of sine functions to represent signals in Fourier transforms, in wavelet
transform, we use functions known as wavelets. Wavelets are finite in time, yet the average value
of a wavelet is zero. In a sense, a wavelet is a waveform that is bounded in both frequency and
duration. While the Fourier transform converts a signal into a continuous series of sine waves,
each of which is of constant frequency and amplitude and of infinite duration, most real-world
signals (such as music or images) have a finite duration and abrupt changes in frequency. This
account for the efficiency of wavelet transforms. This is because wavelet transforms convert a
signal into a series of wavelets, which can be stored more efficiently due to finite time, and can
be constructed with rough edges, thereby better approximating real-world signals.
Examples of wavelets are Coiflet, Morlet, Mexican Hat, Haar and Daubechies. Of these,
Haar is the simplest and most widely used, while Daubechies have fractal structures and are vital
for current wavelet applications. These two are outlined below:
Haar Wavelet
Daubechies Wavelet
30
Figure: Daubechies Wavelet Example
Using the pyramid-structured wavelet transform, the texture image is decomposed into
four sub images, in low-low, low-high, high-low and high-high sub-bands. At this point, the
energy level of each sub-band is calculated. This is first level decomposition. Using the low-low
sub-band for further decomposition, we reached fifth level decomposition, for our project. The
reason for this is the basic assumption that the energy of an image is concentrated in the low-low
band. For this reason the wavelet function used is the Daubechies wavelet.
31
Figure: Pyramid-Structured Wavelet Transform.
2. Calculate the energy of all decomposed images at the same scale, using [2]:
m n
1
E X i , j
M N i1 j1
where M and N are the dimensions of the image, and X is the intensity of the pixel located at
row i and column j in the image map.
3. Repeat from step 1 for the low-low sub-band image, until index ind is equal to 5.
Increment ind.
Using the above algorithm, the energy levels of the sub-bands were calculated, and
further decomposition of the low-low sub-band image. This is repeated five times, to reach fifth
32
level decomposition. These energy level values are stored to be used in the Euclidean distance
algorithm.
x
k
2
Di k y i ,k
k 1
33
7.2.2.5. Flowchart for Texture:-
7.3.1. Definition:-
Shape may be defined as the characteristic surface configuration of an object; an outline or
contour. It permits an object to be distinguished from its surroundings by its outline. Shape
representations can be generally divided into two categories:
Boundary-based, and
Region-based.
34
Figure: Boundary-based & Region-based…
Boundary-based shape representation only uses the outer boundary of the shape. This is
done by describing the considered region using its external characteristics; i.e., the pixels along
the object boundary. Region-based shape representation uses the entire shape region by
describing the considered region using its internal characteristics; i.e., the pixels contained in that
region.
Boundary-based:
Super quadrics
Fourier Descriptors
Implicit Polynomials
Blum's skeletons
The most successful representations for shape categories are Fourier Descriptor and Moment
Invariants:
35
The main idea of Fourier Descriptor is to use the Fourier transformed boundary as the
shape feature.
The main idea of Moment invariants is to use region-based moments, which are invariant
to transformations as the shape feature.
36
transform technique is that it is tolerant of gaps in feature boundary descriptions and is relatively
unaffected by image noise.
As a simple example, consider the common problem of fitting a set of line segments to
a set of discrete image points (e.g. pixel locations output from an edge detector). Figure 1 shows
some possible solutions to this problem. Here the lack of a priori knowledge about the number
of desired line segments (and the ambiguity about what constitutes a line segment) render this
problem under-constrained.
37
We can analytically describe a line segment in a number of forms. However, a
convenient equation for describing a set of lines uses parametric or normal notion:
where r is the length of a normal from the origin to this line and ɵ is the orientation of r with
respect to the X-axis.(See Figure 2.) For any point (x,y) on this line, r and ɵ are constant.
In an image analysis context, the coordinates of the point(s) of edge segments (i.e.
(xi,yi)) in the image are known and therefore serve as constants in the parametric line equation,
while r and ɵ are the unknown variables we seek. If we plot the possible (r,ɵ) values defined by
each (xi,yi), points in Cartesian image space map to curves (i.e. sinusoids) in the polar Hough
parameter space. This point-to-curve transformation is the Hough transformation for straight
lines. When viewed in Hough parameter space, points which are collinear in the Cartesian image
space become readily apparent as they yield curves which intersect at a common (r,ɵ) point.
The transform is implemented by quantizing the Hough parameter space into finite
intervals or accumulator cells. As the algorithm runs, each (xi,yi) is transformed into a
38
discredited (r,ɵ) curve and the accumulator cells which lie along this curve are incremented.
Resulting peaks in the accumulator array represent strong evidence that a corresponding straight
line exists in the image.
We can use this same procedure to detect other features with analytical descriptions.
For instance, in the case of circles, the parametric equation is
where a and b are the coordinates of the center of the circle and r is the radius. In this case, the
computational complexity of the algorithm begins to increase as we now have three coordinates
in the parameter space and a 3-D accumulator. (In general, the computation and the size of the
accumulator array increase polynomially with the number of parameters. Thus, the basic Hough
technique described here is only practical for simple curves.)
39
7.3.4. Flowchart for Shape:-
40
CHAPTER 8
ARCHITECTURE OF PROJECT
41
CHAPTER 9
Main function:-
42
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
43
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(hObject, eventdata, handles)
44
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
45
% --- Executes on button press in loadImage.
function loadImage_Callback(hObject, eventdata, handles)
% hObject handle to loadImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%for i=1:60
%cd('C:\Users\compaq\desktop\pics');
[filename, pathname]= uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*';}, 'pick an image file');
S=imread([pathname,filename]);
%cd('C:\Users\compaq\desktop\cbir1');
axes(handles.axes1);
imshow(S);
handles.S=S;
handles.a=[pathname,filename];
guidata(hObject, handles);
%fid=fopen('colorbase1.txt','a+');
% fprintf(fid,'%s\r',filename);
%end
%cd('C:\Users\compaq\desktop\cbir1');
46
[X,map] = rgb2ind(A,256);
%querymap=rgb2hsv(A);
%figure
%imshow(A);
[handles.queryx, handles.querymap]=imread(I);
cd('C:\Users\compaq\Desktop\pics');
fid=fopen('colorbase1.txt');
resultValues=[];
resultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
disp(imagename);
%figure
%imshow(imagename);
Z=imread(imagename);
[Y,map1] = rgb2ind(Z,256);
%HSVmap=rgb2hsv(RGBmap);
D=quadratic(X,map,Y,map1);
resultValues(i)=D;
resultNames(j)={imagename};
i=i+1;
j=j+1;
end
fclose(fid);
47
fid=fopen('colorResults.txt','w+');
for i=1:10
tempstr=char(resultNames(index(i)));
fprintf(fid,'%s\r',tempstr);
disp(resultNames(index(i)));
disp(sortedvalues(i));
disp(' ')
end
fclose(fid);
disp('color part done')
%cd('C:\Users\compaq\Desktop\cbir1');
displayResults('colorResults.txt','Color Results');
cd('C:\Users\compaq\Desktop\cbir1');
48
fresultValues = []; % Results matrix...
fresultNames = {};
i = 1; % Indices...
j = 1;
while 1
imagename = fgetl(fid);
if ~ischar(imagename), break, end % Meaning: End of File...
X = imread(imagename);
E = euclideanDistance(queryEnergies, imageEnergies);
fresultValues(i) = E;
fresultNames(j) = {imagename};
i = i + 1;
j = j + 1;
end
fclose(fid);
disp('Texture results obtained...');
% Sorting final results...
49
imagename = char(fresultNames(index(i)));
fprintf(fid, '%s\r', imagename);
disp(imagename);
disp(sortedValues(i));
disp(' ');
end
fclose(fid);
disp('Texture parts done...');
disp('Texture results saved...');
disp(' ');
displayResults('textureResults.txt', 'Texture Results...');
cd('C:\Users\compaq\Desktop\cbir1');
cd('C:\Users\compaq\Desktop\cbir1');
fid=fopen('colorbase.txt');
sresultValues = []; % Results matrix...
sresultNames = {};
i = 1; % Indices...
j = 1;
50
%fid = fopen('shapeResults.txt', 'w+');
while 1
imagename=fgetl(fid);
if ~ischar(imagename), break, end
K=imread(imagename);
result=shape(K);
%B=similarityMatrix(shape,result);
%d = s.'*A*s;
%d = d^1/2;
%d = d / 1e8;
if strcmp(result,'Square')
result='Square';
end
if strcmp(result,'Round')
result='Round';
end
if strcmp(result,'Triangle')
result='Triangle';
end
C=strcmp(B,result);
if C>0
sresultValues(i)=C;
sresultNames(j)={imagename};
%fprintf(fid,'%s\r',imagename);
%disp(imagename);
i=i+1;
j=j+1;
end
end
disp('Shape results obtained');
fclose(fid);
51
% Sorting final results...
fid = fopen('shapeResults.txt', 'w+');
52
fid=fopen('database.txt');
resultValues=[];
resultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
disp(imagename);
[X,RGBmap]=imread(imagename);
HSVmap=rgb2hsv(RGBmap);
D=quadratic(handles.queryx, handles.querymap,X,HSVmap);
resultValues(i)=D;
resultNames(j)={imagename};
i=i+1;
j=j+1;
end
fclose(fid);
fid=fopen('colorResults.txt','w+');
for i=1:20
tempstr=char(resultNames(index(i)));
fprintf(fid,'%s\r',tempstr);
disp(resultNames(index(i)));
disp(sortedvalues(i));
disp(' ')
end
53
fclose(fid);
fid=fopen('colorResults.txt');
queryEnergies = obtainEnergies(handles.queryx, 6);
while 1
imagename = fgetl(fid);
if ~ischar(imagename), break, end % Meaning: End of File...
X = imread(imagename);
E = euclideanDistance(queryEnergies, imageEnergies);
fresultValues(i) = E;
fresultNames(j) = {imagename};
i = i + 1;
j = j + 1;
end
fclose(fid);
disp('Color texture results obtained...');
% Sorting final results...
54
[sortedValues, index] = sort(fresultValues); % Sorted results... the vector index
% is used to find the resulting files.
disp(imagename);
disp(sortedValues(i));
disp(' ');
end
fclose(fid);
disp('Texture parts done...');
disp('Texture results saved...');
disp(' ');
displayResults('colorTexture.txt', 'Color Texture Results...');
cd('C:\Users\compaq\Desktop\cbir1');
55
cd('C:\Users\compaq\Desktop\CBIR\imagedatabase');
fid=fopen('database.txt');
resultValues=[];
resultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
disp(imagename);
[X,RGBmap]=imread(imagename);
HSVmap=rgb2hsv(RGBmap);
D=quadratic(handles.queryx, handles.querymap,X,HSVmap);
resultValues(i)=D;
resultNames(j)={imagename};
i=i+1;
j=j+1;
end
fclose(fid);
fid=fopen('colorResults.txt','w+');
for i=1:20
tempstr=char(resultNames(index(i)));
fprintf(fid,'%s\r',tempstr);
disp(resultNames(index(i)));
disp(sortedvalues(i));
disp(' ')
56
end
fclose(fid);
% Shape part starting......
I=handles.a;
A=imread(I);
B=shape(A);
cd('C:\Users\compaq\Desktop\CBIR\imagedatabase');
fid=fopen('colorResults.txt');
sresultValues = []; % Results matrix...
sresultNames = {};
i = 1; % Indices...
j = 1;
%fid = fopen('shapeResults.txt', 'w+');
while 1
imagename=fgetl(fid);
if ~ischar(imagename), break, end
K=imread(imagename);
result=shape(K)
%B=similarityMatrix(shape,result);
%d = s.'*A*s;
%d = d^1/2;
%d = d / 1e8;
if strcmp(result,'Square')
result='Square';
end
if strcmp(result,'Round')
result='Round';
end
if strcmp(result,'Triangle')
result='Triangle';
57
end
C=strcmp(B,result);
if C>0
sresultValues(i)=C;
sresultNames(j)={imagename};
%fprintf(fid,'%s\r',imagename);
%disp(imagename);
i=i+1;
j=j+1;
end
end
disp('Shape results obtained');
fclose(fid);
% Sorting final results...
fid = fopen('colorShape.txt', 'w+');
58
displayResults('colorShape.txt', 'Color Shape Results...');
guidata(hObject,handles);
Quadratic function:-
59
% Return the distance metric.
value = d;
% ------------------------------------------------------------
% ------------------------------------------------------------
% Executes on being called, with input vectors X and Y.
% ------------------------------------------------------------
function value = euclideanDistance(X, Y)
e = [];
for i = 1:c
e(i) = (X(i)-Y(i))^2;
end
Euclid = sqrt(sum(e));
%Obtain energyLevel...
60
value = Euclid;
% ------------------------------------------------------------
% Executes on being called, with input matrix.
% ------------------------------------------------------------
function value = energyLevel(aMatrix)
%Obtain energyLevel...
value = sum(sum(abs(aMatrix)))/(r*c);
% Works to obtain the first 'n' energies of the passed grayscale image...
% ------------------------------------------------------------
% Executes on being called, with input matrix & constant 'n'.
% ------------------------------------------------------------
function value = obtainEnergies(iMatrix, n)
61
energies = [];
i = 1;
for j = 1:5
[tl, tr, bl, br] = decompose(dm);
energies(i) = energyLevel(tl);
energies(i+1) = energyLevel(tr);
energies(i+2) = energyLevel(bl);
energies(i+3) = energyLevel(br);
i = i + 4;
dm = tl;
end
Decompose function:-
[A,B,C,D]=dwt2(imMatrix,'db1');
62
Tr=wcodemat(B); % Top right...
Bl=wcodemat(C); % Bottom left...
Br=wcodemat(D); % Bottom right...
% ------------------------------------------------------------
% Executes on being called, with input matrices I and J.
% ------------------------------------------------------------
function value = similarityMatrix(I, J)
A = [];
for i = 1:r
for j = 1:r
% (sj * sin hj - si * sin hi)^2
M1 = (I(i, 2) * sin(I(i, 1)) - J(j, 2) * sin(J(j, 1)))^2;
% (sj * cos hj - si * cos hi)^2
M2 = (I(i, 2) * cos(I(i, 1)) - J(j, 2) * cos(J(j, 1)))^2;
63
% (vj - vi)^2
M3 = (I(i, 3) - J(j, 3))^2;
M0 = sqrt(M1 + M2 + M3);
Shape function:-
function result=shape(S)
S=im2bw(S);
[H, theta,rho]=hough(S);
%axes(handles.axes2);
%figure
%imshow(H,[],'xdata',theta,'ydata',rho);
%xlabel('\theta'),ylabel('\rho')
%axis on, axis normal;
%title('Hough Matrix');
datas=[];
%clear datas;
for cnt = 1:max(max(H))
datas(cnt) = sum(sum(H == cnt));
end
%axes(handles.axes3);
64
datas(datas==0)=NaN;
%figure
%plot(datas,'--x');
%xlabel('Hough Matrix Intensity'),ylabel('Counts')
%handles.data = data;
%data = handles.data;
[maxval,maxind] = max(datas);
medval = median(datas);
[p]=polyfit(1:maxind-5,datas(1:maxind-5),2);
if maxval<3*medval
result='Triangle';
elseif p(3)>100
result='Square';
else
result='Round';
end
% ------------------------------------------------------------
% Executes on being called, with inputs:
% filename - the name of the text file that has the
% list of images
% header - the figure header name
% ------------------------------------------------------------
function displayResults(filename, header)
65
figure('Position',[200 100 700 400], 'MenuBar', 'none', 'Name', header, 'Resize', 'off',
'NumberTitle', 'off');
while 1
imagename = fgetl(fid);
if ~ischar(imagename), break, end % Meaning: End of File...
x = imread(imagename);
subplot(2,5,i);
subimage(x);
xlabel(imagename);
i = i + 1;
end
fclose(fid);
CHAPTER 10
OUTPUT
66
10.1. For Color:-
Loading an Image:-
Output:-
Loading an Image:-
67
Output:-
68
10.3 For Shape:-
Loading an Image:-
Output:-
69
CHAPTER 11
11.1. ADVANTAGES:-
An image retrieval system is a computer system for browsing, searching and retrieving
images in an image database. In text-based retrieval, images are indexed using keywords,
subject headings or classification codes, which in turn are used as retrieval keys during
search and retrieval.
Text-based retrieval is non-standardized because different users use different keywords
for annotation. Text descriptions are sometimes subjective and incomplete because it
cannot depict complicated image features very well. Examples are texture images that
cannot be described by text.
70
In text retrieval ,humans are required to personally describe every image in the database,
so for a large image database the technique is cumbersome, expensive and labour-
intensive.
Content-based image retrieval (CBIR) technique use image content to search and retrieve
digital images. Content-based image retrieval system was introduced to address the
problems associated with text-based image.
Using application on intranet provides the advantage of accessing the application by
multiple users.
CHAPTER 12
CONCLUSION
The dramatic rise in the sizes of images databases has stirred the development of
effective and efficient retrieval systems. The development of these systems started with
retrieving images using textual connotations but later introduced image retrieval based on
content. This came to be known as CBIR or Content Based Image Retrieval. Systems using
CBIR retrieve images based on visual features such as colour, texture and shape, as opposed to
depending on image descriptions or textual indexing. In this project, we have researched various
modes of representing and retrieving the image properties of colour, texture and shape. Due to
lack of time, we were only able to fully construct an application that retrieved image matches
based on colour and texture only.
71
The application performs a simple colour-based search in an image database for an input
query image, using colour histograms. It then compares the colour histograms of different
images using the Quadratic Distance Equation. Further enhancing the search, the application
performs a texture-based search in the colour results, using wavelet decomposition and energy
level calculation. It then compares the texture features obtained using the Euclidean Distance
Equation. A more detailed step would further enhance these texture results, using a shape-based
search.
CBIR is still a developing science. As image compression, digital image processing, and
image feature extraction techniques become more developed, CBIR maintains a steady pace of
development in the research field. Furthermore, the development of powerful processing power,
and faster and cheaper memories contribute heavily to CBIR development. This development
promises an immense range of future applications using CBIR.
CHAPTER 13
Future Expansion:-
Providing methods for Web searching, allowing users to identify images of interest in remote
sites by a variety of image and textual cues.
Better user interaction, including improved techniques for image browsing and exploiting
user feedback.
72
CHAPTER 14
REFERENCES:-
[1]. Content Based Image Retrieval based on Color, Texture and Shape features using Image
and its complement by P. S. Hiremath and Jagadeesh Pujari, Dept. of P.G. Studies and
Research in Computer Science, Gulbarga University, Gulbarga, Karnataka, India.
[2]. Hough Transform by R. Fisher, S. Perkins, A. Walker, and E. Wolfart.
[3].Image Retrieval with Shape Features Extracted using Gradient Operators and Slope
Magnitude Technique with BTC by Dr. H. B. Kekre, Priyadarshini Mukherjee, Shobhit
Wadhwa, SVKM’s NMIMS University, MPSTME Mumbai.
[4].Content Based Image Retrieval using Low-Dimensional Shape Index.
73
CHAPTER 15
BIBLIOGRAPHY:-
Website: http://mathworks.com.
Content-based Image Retrieval Using Gabor Texture Features Dengsheng Zhang, Aylwin
Wong, Maria Indrawan, Guojun Lu.
74
Ballard, D. H. (1987). Generalizing the hough transform to detect arbitrary shapes.
Object Detection using a Max-Margin Hough Transform by Subhransu Maji, Jitendra Malik.
75