View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Content Based Image Retrieval

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.17647
4.2 | 18 ratings Rate this file 112 Downloads (last 30 days) File Size: 14.5 MB File ID: #42008 Version: 1.1
image thumbnail

Content Based Image Retrieval

by

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
Description

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 http://wang.ist.psu.edu/docs/related/
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: https://github.com/kirk86/ImageRetrieval

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 (58)
07 Oct 2016 Chez

Chez (view profile)

Hello @thelatebloomer,
try to use the code from github and see if it changes anything regarding your situation.

Also check my previous answer to @Kryptonite and @RP since your situation is the same because you're using fedora.

Unfortunately I'm on a tight time constraint at the moment to provide support for different operating systems out of the box.

Since this was developed back then in a windows box, you'll most definitely need the change the paths in the code to reflect your operating system, if you haven't already done so.

Comment only
29 Aug 2016 thelatebloomer

Hi Chez,
Thank you for sharing the codes with us.

I have encountered the same problem, which I noticed that you have not yet provided a solution.

I downloaded the Wang dataset, put them in the sub-folder called images. Opened the cbires.fig GUI and created a DB. After successfully loading the dataset, and selecting a query image, when I press QUERY it keeps giving me an error message called "Reference to non-existent field 'popupmenu_DistanceFunctions'."

I am using MATLAB R2012a and Fedora.

It would mean a lot to me, if you could help me out with this. Thank you.

Comment only
16 Aug 2016 Chez

Chez (view profile)

@Kryptonyte: and @RP:
Since you are using a unix like os, it would be wise to change all the backslash "\" entries in the files to forward slashes "/" in order to avoid confusion. This was developed in a windows box back then.

I've tested the application on a mac which is similar to unix like os such as linux and MATLAB R2016a. I didn't had any problems apart from the slash confusion.

@RP: your error is because you're missing the wavelet toolbox from your system. In this case I can't do much.

@Kryptonyte: try to comment the part of code that calls "cmat" and try again. Are you using the correct folder structure and images? Have a look at the older comments.

Comment only
28 Jul 2016 fariba amini

hello. is this code useful for binary shape retrieval? if it is ok ,how can I do that?

Comment only
28 Jul 2016 fariba amini

hello. is this code useful for binary shape retrieval? if it is ok ,how can I do that?

Comment only
13 May 2016 Chez

Chez (view profile)

@SHWETANK SINGH
That's easy put all your images the new plus the old ones in a directory. Then from within the software click the button that says create db from images. Choose the directory where the images are and wait for the program to finish.

Comment only
28 Apr 2016 SHWETANK SINGH

sir, it would be really a great help if u could tell me how to insert more images in the dataset.
plz reply as soon as possible, looking forward for it.
thank you

Comment only
03 Apr 2016 Kryptonyte

At first I select a similarity. Then I click 'Browse image' and select an image. After that I press SVM which shows me error like below,

########################

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>
SVM (1-against-1):
accuracy = 87.00%
Confusion Matrix:
43 7
6 44

Attempted to access cmat(3,3); index out of bounds because size(cmat)=[2,2].

Error in svm (line 77)
precision(c) = cmat(c, c)/sum(cmat(c:end, c));

Error in cbires>btnExecuteSVM_Callback (line 256)
[~, ~, cmat] = svm(numOfReturnedImgs, handles.imageDataset.dataset, handles.queryImageFeature, metric, handles.folder_name, handles.img_ext);

Error in gui_mainfcn (line 95)
feval(varargin{:});

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

Error in @(hObject,eventdata)cbires('btnExecuteSVM_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating UIControl Callback

####################

I am using linux(ubuntu 14.04), MATLAB R2015a.
What could be the problem ?

28 Mar 2016 R P

R P (view profile)

Hi Chez,

When I click the button "Browse for images" , it gives me the following error.

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>
dwt2 is not included in your installed products. These products offer 'dwt2':
Wavelet Toolbox

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 95)
feval(varargin{:});

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

Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cbires('btn_BrowseImage_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

Please help me.
My version of MATLAB is R2016a.

24 Mar 2016 R P

R P (view profile)

My Matlab version is R2010a.

When I click on the Query button, I am having the error

"??? Reference to non-existent field 'popupmenu_DistanceFunctions'.

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

Error in ==> gui_mainfcn at 96
feval(varargin{:});

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

Error in ==>
@(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))


??? Error while evaluating uicontrol Callback "

Can you please help me on how to overcome this error.

Comment only
24 Mar 2016 Chez

Chez (view profile)

@mandy H mandy, it seems like you haven't chosen as classification technique.
First you have to create a dataset or use the existing one, then load the dataset into the program.
Second you have to choose a query image.
So far it seems that you have done the above steps.
Finally you have to choose a classification technique either knn (i.e. a distance function) or svm from the drop down menu. Then you press the query buttton.

Comment only
22 Mar 2016 mandy

mandy (view profile)

Dear Chez, Thanks for uploading the program. Its a great work.
I tried to make a database of 100 images and also of 1000 images. I created database, next i pressed the 'browse for image' button and selected an image. But when i press the query button, it gives me the following error:

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 'popupmenu_DistanceFunctions'.

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

Error in gui_mainfcn (line 96)
feval(varargin{:});

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

Error in
@(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

please help me out. I am in great need of your program.
Please guide me what can i do. I am using 2013a version.
Thanks in advance.

07 Mar 2016 Chez

Chez (view profile)

@egewgweg ewgwegweg: Actually my last comment is wrong. Disregard it. It should have been the if my previous comment was correct but it wasn't.

The reason why is that happening is the different outputs you receive from hsvHistrogram and imhist functions.

hsvHistogram quantizes the image into 8x2x2 equal bins thus it produces a 32-dim vector. While imhist it simply gives you the histogram of a gray scale image which is a 256-dim vector and I use that as it is that's why you get those differences.

Comment only
07 Mar 2016 Chez

Chez (view profile)

@egewgweg ewgwegweg: That's happening because in the case of a gray scale image the autocorrelogram does not apply. Thus in the case of a true color image there another additional preprocessing step which is the autocorrelogram, thus it reduces further the feature vector from 346 to 190 dimensional space.

Comment only
07 Mar 2016 egewgweg ewgwegweg

@Chez:If I use 512*512 uint8 image,i can get 346 feature. if i use same intensity which increases to 512*512*3 uint8 image, i derive 190 features.thanks for your help !

Comment only
06 Mar 2016 Chez

Chez (view profile)

@egewgweg ewgwegweg: If you could elaborate a little bit more then I might be able to provide some help but I cannot clearly understand at the moment your question.

If you want to cite the program you can use the following bibtex format:

@Manual{,
title = {CBIR: Content-based Image Retrieval},
author = {{J.M.}},
organization = {Aristotle University},
address = {Greece},
year = 2014,
url = {http://github.com/kirk86/ImageRetrieval}
}

Although I also plan at some point to release a paper or technical report but unfortunately I didn't had much free time.

Notice:

You have to be aware that as @leeazlee: and earlier @hassan mahmood: pointed out in their comments there is a bug in the correlogram function now that I've checked. It runs only for k=1 which essentially is a bug. As I said I don't have much free time lately and I could correct. If anyone fixes it feel free to send me a pull request.

Comment only
02 Mar 2016 egewgweg ewgwegweg

why use grey scale image have a 346 feature but reference.pdf is a 190 feature and how site your Program

Comment only
20 Feb 2016 khwildi Raoua

Good works. Please you have article? I need it.

16 Feb 2016 Manu BN

Manu BN (view profile)

Works like a charm!! Brilliant work Chez

04 Feb 2016 sudhakar shinde

May i know the base paper u have used

Comment only
18 Jan 2016 Superman-nini

Dear Chez,
I want to know how to build a mat file of my own picture.

thank you!

Comment only
25 Dec 2015 Kobe Tonny

Dear Chez
the program has an error whenever I try to input an image for query and does not see the image at all,This is the details of wrong:
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 96)
feval(varargin{:});

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

Error in @(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback
Thanks!

06 Nov 2015 harrison  
28 Sep 2015 sweta arya

how to run this project,giving error "
??? Error: File: cbires.m Line: 257 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [" && "
Error in ==> @(hObject,eventdata)cbires('btn_BrowseImage_Callback',hObject,eventdata,guidata(hObject))


??? Error while evaluating uicontrol Callback"

Comment only
06 Sep 2015 leeazlee

I would like to ask the same question as hassan mahmood (18 Nov 2014)

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];
through
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?

thank you

Comment only
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
Amir

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)
feval(varargin{:});

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

Error in
@(hObject,eventdata)app('img__Callback',hObject,eventdata,guidata(hObject))


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];
through
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)
feval(varargin{:});

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

Error in
@(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))


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)
feval(varargin{:});

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

Error in
@(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

04 Sep 2014 zhendong zhang  
07 Jul 2014 DGSN

DGSN (view profile)

WIL BE TESTED

Comment only
30 Jun 2014 Chez

Chez (view profile)

@Drumzhead,

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?

Thanks

Comment only
18 May 2014 Chez

Chez (view profile)

@Sun-hwa,

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

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
feval(varargin{:});

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

Error in ==>
@(hObject,eventdata)cbires('btnExecuteQuery_Callback',hObject,eventdata,guidata(hObject))

??? 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: <<anbuaec@gmail.com>>...
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
'double'.

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)
feval(varargin{:});

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

Error in
@(hObject,eventdata)cbires('btn_BrowseImage_Callback',hObject,eventdata,guidata(hObject))

Comment only
04 Oct 2013 Hassan Saad

SVM Button not working with me

Attempted to access
img_names(121); index out of
bounds because
numel(img_names)=120.

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

Updates
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