File Exchange

image thumbnail

Image retrieval - Query by Example Demo

version 1.0 (6.92 MB) by

This demo provides a simple query by image example method, based on HSV values.

4.21053
20 Ratings

15 Downloads

Updated

View License

Editor's Note: Popular File 2014

Content-based image retrieval is the task of searching images in databases by analyzing the image contents. In this demo, a simple image retrieval method is presented, based on the color distribution of the images. The user simply provides an "example" image and the search is based upon that example (query by image example). For this first version of the demo no relevance feedback is used.

Almost 1000 images have been used for populating the database. For each image a 3-D histogram of it's HSV values is computed. At the end of the training stage, all 3D HSV histograms are stored in the same .mat file.
In order to retrieve M (user-defined) query results, the following steps are executed:

The 3D (HSV) histogram of the query image is computed. Then, the number of bins in each direction (i.e., HSV space)is duplicated by means of interpolation.
For each image i in the database:
Load its histogram Hist(i).
Use interpolation for duplicating the number of bins in each direction.
For each 3-D hist bin, compute the distance (D) between the hist of the query image and the i-th database image.
Keep only distances (D2) for which, the respective hist bins of the query image are larger than a predefined threshold T (let L2 the number of these distances).
Use a 2nd threshold: find the distance (D3) values which are smaller than T2, and let L3 be the number of such values.
The similarity measure is defined as: S(i) = L2 * average(D3) / (L3^2).
Sort the similarity vector and prompt the user with the images that have the M smaller S values.

Comments and Ratings (53)

dolly indra

when i am running this program , the program can not running with comment "Not enough input arguments". i using matlab 2012a Thanks

can any one help me to run EMR code

Atul Prakash

Can i use this code in iPhone App. If so, how it will be possible. Can u please guide me.

Jitender Rana

Jitender Rana

when i am running the searchImagehist.m i am keep getting an error:

Not enough input arguments.

Error in searchImageHist (line 14)
load(modelName);

Can you plz help me out here.

Jitender Rana

when i am running the searchImagehist.m i am keep getting an error:

Not enough input arguments.

Error in searchImageHist (line 14)
load(modelName);

Can you plz help me out here.

Jitender Rana

when i am running the searchImagehist.m i am keep getting an error:

Not enough input arguments.

Error in searchImageHist (line 14)
load(modelName);

Can you plz help me out here.

Jitender Rana

when i am running the searchImagehist.m i am keep getting an error:

Not enough input arguments.

Error in searchImageHist (line 14)
load(modelName);

Can you plz help me out here.

great work really good and simple concept for color classification
for getting image names in new folder i used imageSet
imgsea= imageSet('C:\DatabaseImages\sea');
files={};
Hists={};
ii=1;

for k=1:imgsforest.Count
%imgr=read(imgsforest,k);
% imgr=imresize(imgr,sz);
[Hist, RGBt] = getImageHists(imgsforest.ImageLocation{k}, 0);
files{ii}=imgsforest.ImageLocation{k};
Hists{ii}=Hist;
ii=ii+1;
end

hello comrade some one can help me to know how i can start to program in matlab because i want to use in my project, how to retrieve image using matlab

navreen kaur

thanks for the code... but can you please help me with the code for relevance feedback also

Hoang

Hoang (view profile)

shefalli

Pls tell me why we have taken i=3 in loop not 1???my id is shefalligoyal@gmail.com
function [Hists,files] = getImageHistsDir(DirName)
D = dir(DirName);
count = 0;

for (i=3:length(D))
if ((strcmpi(D(i).name(end-3:end), '.jpg')==1) | (strcmpi(D(i).name(end-3:end), '.jpeg')==1))
count = count + 1;
Hists{count}=getImageHists([DirName '\\' D(i).name]);
files{count}=[DirName '\\' D(i).name];
fprintf('%.4d File %40s computed...\n',count,files{count});
end
end
savefile='mydatabase';
save (savefile, 'files', 'Hists')

shefalli

sir how can we train the data

Joel

Joel (view profile)

This program uses Euclidean Distance to compare the similarities. Instead can someone change the code to compute the similarities as one of the following please.

Canberra Distance or City Block Distance

http://stn.spotfire.com/spotfire_client_help/hc/hc_city_block_distance.htm

http://en.wikipedia.org/wiki/Canberra_distance

Joel

Joel (view profile)

How can I train a batch of images to this project.

Thank

Joel

Joel (view profile)

How can I add my own images to this project?

Thanks

Johnny

Johnny (view profile)

Jess

Jess (view profile)

Hi Muhammad Imran,

It won't help in your understanding by explaining line-by-line. Try running the command in Matlab workspace and utilize the plot/imshow etc to display the changes for each step. You will be able to understand how the code work and learn Matlab at the same time. For concepts learning, search related literature.

Thanx for such a nice upload, plz tell me why you use interpolation and what is the concept behind threshold and range , waiting for your reply thanx

M@lik Ali

Hi all,

I am new to matlab and image processing, this code is work fine with me, but i can't can understand it in detail. can any one help me to explaining the code line by line.
you can email me to malikimran110@gmail as well.
hoping to hear from you.

Jess

Jess (view profile)

Hi Muhammad Imran,
"modelName" is the name of a variable. Author provided model1Hist.mat as training data (generate own training data using getImageHists.m). Refer to documentation on how to properly run the command. For example,
searchImageHist('beach.JPG','model1Hist',5);

M@lik Ali

i try to run this program but it give error , any one can help
??? Input argument "modelName" is undefined.

Error in ==> searchImageHist at 14
load(modelName);

Adnan Munir

??? Error using ==> strfind
Input strings must have one row.

Error in ==> imread at 340
if (strfind(filename, '://'))

Error in ==> getImageHists at 4
RGB = imread(imageName);

Error in ==> searchImageHist at 18
[Hist, RGBQ] = getImageHists(imageName);

im getting this error by runnig ur code and im unable to solve it....do help me plz its urgent

prabagaran M

i want to know how to check similarity between two images can anyone help pls

Great work for all of you.

Cevat

Cevat (view profile)

good
but i need some help to create code to check for similar images on the web in matlab
how do i do that as i am creating a cancer detecting software

wu

wu (view profile)

hi, your code is very helpful for me, but i have a question about the measure of distance and similarity.
i want to know why use this formula S(i) = L2 * average(D3) / (L3^2) to compute similarity.
if any literature mention this method , it cant be better more

thanks for your answer

Jess

Jess (view profile)

Addition to ampire Ê (20 May 2009), can provide user with flexibility to select any directory (with images) by adding one line after the function name.

>function getImageHistsDir

DirName = uigetdir();

>D = dir(DirName);
>count = 0;
>
>for (i=3:length(D))
> if ((strcmpi(D(i).name(end-3:end), '.jpg')==1) | (strcmpi(D(i).name(end-3:end), '.jpeg')==1))
> count = count + 1;
> >Hists{count}=getImageHists([DirName '\\' D(i).name]);
> files{count}=[DirName '\\' D(i).name];
> fprintf('%.4d File %40s computed...\n',count,files{count});
> end
>end
>savefile='mydatabase';
>save (savefile, 'files', 'Hists')

Jess

Jess (view profile)

hello Mr Rajkumar,

nResults is one of the input parameter when you call searchImageHist

how is the nResults computed?

hello Mr. Nicola Franzoso
i tried ur code for developing a new model for a new database but i got an error as shown bellow. i used 653 .jpg images

Driver: []
URL: []
Constructor: []
Message: 'Function requires three or five arguments to be defined'
Handle: []
TimeOut: []
AutoCommit: []
Type: []
is there any other means to correct it?

Hi MUKUND SARDA, thank you for your interest. There is a quite detailed description of the algorithm above. In general the idea is quite simple: an empirical measure is defined on the thresholded distances of the HSV feature space. Then this similarity measure is sorted for returning the closest images. If you have any particular questions, please feel free to ask.

MUKUND SARDA

sir will u pls provide detail algorithm of this program so that i can undersatnd it easily...

sjye

sjye (view profile)

Faizal

Faizal (view profile)

How about the GUI?

Faizal

Faizal (view profile)

TQ VERY MUCH...
i'm very appreciate with...
hmm...do u has any idea if i want to used Integrated Histogram Bin Matching tecnique to image similarity..
i hope u can help me..

akash mehra

hi... everyone thnx 4 the code and the posts....
i am trying to add new images to the existing database but i'm not able to write the code....
if anyone could... plz post here......
thnx........ a lot...

mansi verma

image retrieval code is not getting downloaded. its showing an error of invalid archieve. please update it and if possible send a copy to
mansiverma65@gmail.com

thank u!!

Raksha

Raksha (view profile)

ampire Ê

thank you for your code! But I think the code above is not very exact.it's code based on you:
function [Hists,files] = getImageHistsDir(DirName)
D = dir(DirName);
count = 0;

for (i=3:length(D))
if ((strcmpi(D(i).name(end-3:end), '.jpg')==1) | (strcmpi(D(i).name(end-3:end), '.jpeg')==1))
count = count + 1;
Hists{count}=getImageHists([DirName '\\' D(i).name]);
files{count}=[DirName '\\' D(i).name];
fprintf('%.4d File %40s computed...\n',count,files{count});
end
end
savefile='mydatabase';
save (savefile, 'files', 'Hists')
Making use of it,you can get imagesdir in your images files.thank you!

mubashar khan

i managed to get the images to be computed however i couldnt get the .mat file saved in a way so that when i used the code from the original to run it, it would jus come up with the error about Nfiles. can any 1 help me out with this? thanks

mubashar khan

its k.. managed to solve it!! :-D

Liviu Vladutu

Try the example with the 'Classical_guitar.jpg'. It fails miserably to find the closest (as resemblance) figure, ie 'Classical_Guitar_two_views.jpg'.
Try: warning off;searchImageHist('Classical_Guitar.jpg', 'model1Hist', 11);

Hi guys, thanx alot for your comments. Sorry for the looong delay, but I hadn't checked the forum for quite a long time. Anyway, I am posting a simple function that computes the color histograms of a whole directory of images. In this way you will be also able to build your training data. You can use this function and then store the returned histograms (along with the filenames) in a mat file.

Matlab code:

function [Hists, files] = getImageHistsDir(DirName)

D = dir(DirName);

count = 0;

for (i=3:length(D))
if ((strcmpi(D(i).name(end-3:end), '.jpg')==1) | (strcmpi(D(i).name(end-3:end), '.jpeg')==1))
count = count + 1;
[Hists{count}] = getImageHists([DirName '\\' D(i).name]);
files{count} = [DirName '\\' D(i).name];
fprintf('%.4d File %40s computed...\n',count,files{count})
end
end

As you can see, you just specify the directory name in which the images are stored. This is actually what Nicola Franzoso has provided, but in a function mode.

kartik

kartik (view profile)

i am trying to build a image retrival system with information provided for each image ,hence actin as an image based search engine
program works great!!!!!!!!!!!!!!!!!

i would like to know about the deccison threshold used in in the program.on what basis the threshold were set ,how threshold values mentioned in the program were calculated,were they on the basis of intensity value or something else .i would like to undrstand the threshold in program

the threshold given are t=0.010 AND t2=0.8
how were these given and how it was calcualted and compared

kartik

kartik (view profile)

since i am new to matlab,and i am trying to learn all the basics as quick as possible,,

i would like to know how exactly the database is created for images say if i have 10 images,where would i write the program for creating the database in matlab,and if images are in folder then how would i link it
explanation given above in one of the comment is not making me understand it properly

can anybody make this thing clear to me
requesting all the pioneers in Digtial image processing
need help in quick time.

cqupt cqupt

I has solve it!

Great work Theodoros.
About for create a database of new images i have try with this and work. In my sample the images are 17 from 1 to 17.jpg:

savefile = 'mydatabase.mat';

for numimma = 1:17 % 17 images in my sample

imageName = strcat(num2str(numimma), '.jpg');

% compute 3-D image histograms (HSV color space):
[Hist, RGBQ] = getImageHists(imageName);

isto = {Hist};
imshow(RGBQ);
drawnow
dataisto(numimma) = isto;
datafile(numimma) = {imageName};

end

save (savefile, 'datafile', 'dataisto')

Amir abbas

Harsh Sundani

Thanks a lot for the program....It works great!!.....

I am trying to create a image retrival program for medical images and will be using this code for the program. Could you please help me create my own database(with new image histograms) and storing it in a new .mat file...

MATLAB Release
MATLAB 7.5 (R2007b)

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

» Watch video