Code covered by the BSD License  

Highlights from
Content Based Image Retrieval

3.8 | 11 ratings Rate this file 153 Downloads (last 30 days) File Size: 14.5 MB File ID: #42008 Version: 1.1
image thumbnail

Content Based Image Retrieval


Chez (view profile)


30 May 2013 (Updated )

Simple content based image retrieval for demonstration purposes. Either using knn or classification

| Watch this File

File Information

This a simple demonstration of a content based image retrieval using 2 techniques.
1. Using knn for image retrieval
2. Using svm for image retrieval.

Notice: Please follow these steps in order to avoid common mistakes.

1. Go to the following link
and download the 100 test images zip file

2. Extract the images from the zip file to the ImageRetrieval/images folder and overwrite any existing images that previously existed in that directory

3. In order to make any queries you'll be asked to load the dataset firt. No worries the directory contains the full dataset.mat file which you can load and then fire up your queries.

You can also download the source code from github:

Required Products Bioinformatics Toolbox
Data Acquisition Toolbox
Datafeed Toolbox
Fuzzy Logic Toolbox
Image Acquisition Toolbox
Image Processing Toolbox
Optimization Toolbox
Signal Processing Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (33)
30 Jul 2015 Chez

Chez (view profile)

@Rishnaki Jain: I think I have already incorporated the ability to handle grey scale images. If it doesn't work then try downloading it from the github repository in the description.

Comment only
27 Jul 2015 Rishanki Jain

@ Chez. I have a set of grey images that I need to retrieve and that too of one type of class. They all are medical scans i just have to identify by the severity so what will be the changes that I have to take care of while modifying the program.

Comment only
05 Jul 2015 vengala kiran

generally CBIR works based on Euclidean distance but here it work with SVM classification can any one explain the code in detail please

Comment only
14 Jun 2015 Chez

Chez (view profile)

@Amir Motlagh: Have a look at the files L1.m and L2.m. I think that you'll find what you need in the file L2.m.

Comment only
29 May 2015 Amir Motlagh

Dear Chez

I was wondering how I could modify the similarity metric tool bar and replace it with our own programs and algorithms.

Kind Regards

Comment only
24 Apr 2015 Chez

Chez (view profile)

@Aprita. Look the file "reference.pdf" in the github repository link found in the Description section.

Comment only
24 Apr 2015 Chez

Chez (view profile)

@ Anuvab Chhotray. Yes it can. Keep in mind that if you use a bigger training dataset with great variability then the model will take into account that variability when trying to actually do the classification on a unseen image outside the dataset.

Comment only
22 Apr 2015 Anuvab Chhotray

I was wondering if this can be extended to find similar images when a query image is given outside the dataset of training images.

Comment only
14 Apr 2015 Arpita

Arpita (view profile)

Hello Chez,
Pretty handy to use- Thank you. But I couldn't find your full name & details for reference.

Comment only
12 Apr 2015 mina tomate

Processing orientation 1
Processing orientation 2
Processing orientation 3
Processing orientation 4
Processing orientation 5
Processing orientation 6

Code for <Variation in Phase Symetry> Starts
Taking Median for scale 1/4
Taking Median for scale 2/4
Taking Median for scale 3/4
Taking Median for scale 4/4
Code End for <Variation in Phase Symetry>
Reference to non-existent field 'image_quantity'.

Error in app>img__Callback (line 348)
handles.numOfReturnedImages = get(handles.image_quantity, 'Value');

Error in gui_mainfcn (line 96)

Error in app (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in

Error using figure
Error while evaluating uicontrol Callback

10 Apr 2015 mina tomate

thank you very much if you can explain me briefly each function of the code i really need it and I thank you cordially

25 Mar 2015 zhang chi

Hello, I want to ask you if the file is writed according to a published paper? May I know the name of the paper?

20 Feb 2015 pradeep kaushik

The File cbir.fg not working properly.GUI is not working properly.

19 Feb 2015 piya choudhary

sir,instead of using classification i would like to make cluster(using k means) of these images based on similarity metric after feature extraction can you provide me the code for that?

Comment only
05 Feb 2015 Sushant Hiwale

@chez I would like to know which research paper you referred to implement this code. Please provide a link to the paper or if possible the paper itself.

18 Nov 2014 hassan mahmood

hi everyone:
in the "function correlogram(photo, Cm, K)", "for k = 1:K"
is used as loop.
where K is passed from
distances = [1 3 5 7];
colorAutoCorrelogram = correlogram(rgb, map, distances)
I have read through huang paper, but couldn't get it.

1- the FOR loop is run only once for k=1 only, k=1 neighbor 8 pixels
why we pass K=[1 3 5 7] to the correlogram function?
2- why we are multiplying the values by distances?
colorAutoCorrelogram(:, :, 1) = colorAutoCorrelogram(:, :, 1)*distances(1);
colorAutoCorrelogram(:, :, 2) = colorAutoCorrelogram(:, :, 2)*distances(2);
colorAutoCorrelogram(:, :, 3) = colorAutoCorrelogram(:, :, 3)*distances(3);
colorAutoCorrelogram(:, :, 4) = colorAutoCorrelogram(:, :, 4)*distances(4);

we are not checking 3 5 7 neighbors? should we do it?
thanks for your time

Comment only
16 Nov 2014 Chez

Chez (view profile)

@Pham Nhung, go to the github link provided in the description above in the "File Information" section. You will find there the reference you are looking for. Check for "reference.pdf" which explains how the dataset was obtained!

Comment only
03 Nov 2014 Pham Nhung

Sorry I do not understand what dataset represents and how you obtain it from the set of images.Can anyone explain to me?

Comment only
31 Oct 2014 Xing Di

Xing Di (view profile)

Reference to non-existent field 'popupmenu_DistanceFunctions'.

Error in cbires>btnExecuteQuery_Callback (line 211)
metric = get(handles.popupmenu_DistanceFunctions, 'Value');

Error in gui_mainfcn (line 95)

Error in cbires (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in

Error while evaluating uicontrol Callback

18 Sep 2014 liu zhiyuan

this is the detail information of error!

Reference to non-existent field 'popupmenu_DistanceFunctions'.

Error in cbires>btnExecuteQuery_Callback (line 197)
metric = get(handles.popupmenu_DistanceFunctions, 'Value');

Error in gui_mainfcn (line 96)

Error in cbires (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in

Error while evaluating uicontrol Callback

04 Sep 2014 zhendong zhang  
07 Jul 2014 DGSN

DGSN (view profile)


Comment only
30 Jun 2014 Chez

Chez (view profile)


Dear Drumzhead,

each of the 6 features you're referring to is on its own a variable length array or a feature vector if you prefer. What that means is that for instance if we take the first feature of the 6 you mentioned which is "hsvHist" and we print its values you can see that it is not a variable or a feature corresponding to one particular value, rather it's a vector of 64 or 128 values. The same holds for the rest of the 6 features you're referring to.

Hope that helps!

Comment only
13 Jun 2014 Drumzhead Chongpratheep

Dear Chez,

I have gone through your code for feature vector extraction and notice that there're about 6 features composing one feature vector as the code below.

File Name: cbir.m / Line: 446
% construct the dataset
set = [hsvHist autoCorrelogram color_moments meanAmplitude msEnergy wavelet_moments];

However, when I open .mat file, it contains 190 columns of value for each vector (excluding the last column allocated the No. of image).

Could you please clarify what is 190 columns of value represent for?


Comment only
18 May 2014 Chez

Chez (view profile)


You have to be aware that the svm button will not work unless you configure it to work with your dataset. What do I mean is that you will have to find out how many classes you have in your dataset and configure the svm.m file accordingly.

For instance if your dataset has 10 classes total then you will have to configure either the names of the images to fall under the wang’s dataset schema or you’ll have to modify the code in svm.m file.

Notice that the wang dataset has 10 classes with 100 images each:
For instance images 0 through 99 belong to class 1
Images 100 through 199 belong to class 2
Images 200 through 299 belong to class 3

So modify your dataset names of images accordingly or as I said above modify the svm.m file at the section where it creates the labels for each class.

Hope that helps.

Comment only
11 May 2014 Sun-hwa

I have a team project about 'Reconizing Flowers.'
While I was looking for some algorithms, I found your program about CBIR.

I have some questions about the program.

Actually, we were going to make a dataset of 'Flowers'. Successfully, we made an flower data set and we activated 'Query' function.
But, there was an error when we tried to excute 'SVM'.

I think we don't know exaclty about how to use this program.

So, Can i get an overall manual of this program if you have that?

Comment only
26 Apr 2014 Vishwajeet

??? Error using ==> plus
Matrix dimensions must agree.

Error in ==> L1 at 23
manhattan(k) = sum( abs(dataset(k, :) - queryImageFeatureVector) ./ ( 1 + dataset(k, :) +
queryImageFeatureVector ) );

Error in ==> cbires>btnExecuteQuery_Callback at 213
L1(numOfReturnedImgs, handles.queryImageFeature, handles.imageDataset.dataset);

Error in ==> gui_mainfcn at 96

Error in ==> cbires at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==>

??? Error while evaluating uicontrol Callback

03 Dec 2013 anbarasa pandian

Hi Friends
i want CBIR techniques source code... Please send me this e-mail id: <<>>...
i am doing project in CBIR using Hyperpectral image...

02 Dec 2013 Chez

Chez (view profile)

@christopher, make sure your matlab version supports dwt2 function, and may I ask what kind of image are you inputting???

Comment only
12 Nov 2013 christopher

the program has an error whenever I try to input an image for query and does not see the image at all

Undefined function 'dwt2' for input arguments of type

Error in waveletTransform (line 9)
coeff_1 = dwt2(imgGray', 'coif1');

Error in cbires>btn_BrowseImage_Callback (line 103)
wavelet_moments = waveletTransform(queryImage);

Error in gui_mainfcn (line 96)

Error in cbires (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in

Comment only
04 Oct 2013 Hassan Saad

SVM Button not working with me

Attempted to access
img_names(121); index out of
bounds because

Comment only
06 Sep 2013 Chez

Chez (view profile)

@Prasad, if you're using an older matlab version than version 8. Try to change the line 243 to: [var1, var2, cmat] = svm(numOfReturnedImgs, handles.imageDataset.dataset, handles.queryImageFeature, metric);

Comment only
03 Sep 2013 Prasad Kalane

following error comes when I run cbires file...

??? Error: File: cbires.m Line: 243 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [.

29 Aug 2013 1.1

I have provided and additional link to my github account where anyone can download the source code of this project!

Contact us