File Exchange

image thumbnail

Content Based Image Retrieval

version 1.1 (14.5 MB) by

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

172 Downloads

Updated

View License

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

Comments and Ratings (65)

Ganesh Raut

Hello sir, In this code KNN for image retrieval is not available.
please help me for this and tell me which content we use for image retrieval.
and send me information and code on graut1389@gmail.com

hello everyone, can anyone help me out?

i want to retrieve by using hilbert huang transform technique. can anyone give the support that how could i be approach to the process. under this cbir scheme?

zameer faiz

Hi, can some one help my using this code? i am newbie to matlab and have to do a CBIR job and have downloaded this code but I absolutely no idea how to do it.

sumaira aslam

khazima Anam

i am looking for the code of image classification based on color, but couldn't find the download zip ..kindly guide me....

Thank you so much for this implementation , But i have a question , do you know why he proposedd gabor+wavelet to form the feature vector in the paper ? and not just one of them?

Javed

Javed (view profile)

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.

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.

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.

fariba amini

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

fariba amini

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

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.

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

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 ?

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.

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.

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.

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.

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.

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.

@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 !

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.

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

khwildi Raoua

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

Manu BN

Manu BN (view profile)

Works like a charm!! Brilliant work Chez

May i know the base paper u have used

Superman-nini

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

thank you!

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!

harrison

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"

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

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.

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.

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

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.

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

Chez

Chez (view profile)

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

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.

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

Arpita

Arpita (view profile)

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

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

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

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?

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

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?

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

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

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!

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?

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

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

DGSN

DGSN (view profile)

WIL BE TESTED

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!

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

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.

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?

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

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

Chez

Chez (view profile)

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

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))

Hassan Saad

SVM Button not working with me

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

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);

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

1.1

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

MATLAB Release
MATLAB 8.0 (R2012b)

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

» Watch video