plz solve cbir implementation

6 views (last 30 days)
DEEPTHI
DEEPTHI on 24 Jan 2013
i am deepthi i am implementing the project in CBIR...i have to implement for large image database...i dono how to use large image db in base.txt.. plz help me....
function varargout = main(varargin)
% MAIN M-file for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% 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
% Edit the above text to modify the response to help main
% Last Modified by GUIDE v2.5 18-Jan-2013 20:29:55
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
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
% --- Executes just before main is made visible.
function main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(hObject, eventdata, handles)
% 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)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- 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)
[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.gif';'*.*';},'pick an image file');
S=imread([pathname,filename]);
axes(handles.axes1);
imshow(S);
handles.S=S;
handles.a=[pathname,filename];
guidata(hObject,handles);
% --- Executes on button press in colorSearch.
function colorSearch_Callback(hObject, eventdata, handles)
% hObject handle to colorSearch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.a;
A=imread(I);
[X,map]=rgb2ind(A,256);
[handles.queryx,handles.querymap]=imread(I);
cd('C:\images');
fid=fopen('base.txt');
resultValues=[];
resultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
disp(imagename);
Z=imread(imagename);
[Y,map1]=rgb2ind(Z,256);
D=quadratic(X,map,Y,map1);
resultValues(i)=D;
resultNames(j)={imagename};
i=i+1;
j=j+1;
end
fclose(fid);
[sortedValues,index]=sort(resultValues);
cd('C:\results');
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 parts done');
displayResults('colorResults.txt','Color Results..');
cd('c:/results');
% --- Executes on button press in textureSearch.
function textureSearch_Callback(hObject, eventdata, handles)
% hObject handle to textureSearch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.a;
A=imread(I);
[handles.queryx,handles.querymap]=imread(I);
querymap=rgb2hsv(A);
cd('C:\images');
fid=fopen('base.txt');
queryEnergies=obtainEnergies(handles.queryx,6);
fresultValues=[];
fresultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
X=imread(imagename);
imageEnergies=obtainEnergies(X,6);
E=euclideanDistance(queryEnergies,imageEnergies);
fresultValues(i)=E;
fresultNames(j)={imagename};
i=i+1;
j=j+1;
end
fclose(fid);
disp('Texture results obtained');
[sortedValues,index]=sort(fresultValues);
cd('C:\results');
fid=fopen('textureResults.txt','w+');
for i=1:10
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:\results');
% --- Executes on button press in shapeSearch.
function shapeSearch_Callback(hObject, eventdata, handles)
% hObject handle to shapeSearch (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.a;
A=imread(I);
B=shape(A);
cd('C:\images');
fid=fopen('base.txt');
sresultValues=[];
sresultNames={};
i=1;
j=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
K=imread(imagename);
result=shape(K);
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};
i=i+1;
j=j+1;
end
end
disp('Shape results obtained');
fclose(fid);
cd('c:/results');
fid=fopen('shapeResults.txt','w+');
[sortedValues,index]=sort(sresultValues);
for i=1:10
imagename=char(sresultNames(index(i)));
fprintf(fid,'%s\r',imagename);
end
disp(imagename);
disp(sortedValues(i));
disp('');
fclose(fid);
disp('Shape parts done');
disp('Shape results saved...');
disp('');
displayResults('shapeResults.txt','Shape Results...');
cd('C:\results');
function value=quadratic(X1,map1,X2,map2)
[count1,y1]=imhist(X1,map1);
[count2,y2]=imhist(X2,map2);
q=count1-count2;
s=abs(q);
A=similarityMatrix(map1,map2);
d=s.'*A*s;
d=d^1/2;
d=d/1e8;
value=d;
function value=obtainEnergies(iMatrix,n)
dm=iMatrix;
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
sorted=-sort(-energies);
value=sorted(1:n);
function[Tl,Tr,Bl,Br]=decompose(imMatrix)
[A,B,C,D]=dwt2(imMatrix,'db1');
Tl=wcodemat(A);
Tr=wcodemat(B);
Bl=wcodemat(C);
Br=wcodemat(D);
function value=energyLevel(aMatrix)
[r,c]=size(aMatrix);
value=sum(sum(abs(aMatrix)))/(r*c);
function value=euclideanDistance(X,Y)
[r,c]=size(X);
e=[];
for i=1:c
e(i)=(X(i)-Y(i))^2;
end
Euclid=sqrt(sum(e));
value=Euclid;
function value=similarityMatrix(I,J)
[r,c]=size(I);
A=[];
for i=1:r
for j=1:r
M1=(I(i,2)*sin(I(i,1))-J(j,2)*sin(J(j,1)))^2;
M2=(I(i,2)*cos(I(i,1))-J(j,2)*cos(J(j,1)))^2;
M3=(I(i,3)-J(j,3))^2;
M0=sqrt(M1+M2+M3);
A(i,j)=1-(M0/sqrt(5));
end
end
value=A;
function result=shape(S)
S=im2bw(S);
[H,theta,rho]=hough(S);
datas=[];
for cnt=1:max(max(H))
datas(cnt)=sum(sum(H==cnt));
end
datas(datas==0)=NaN;
[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
function displayResults(filename,header)
figure('Position',[200 100 700 400],'MenuBar','none','Name',header,'Resize','off','NumberTitle','off');
fid=fopen(filename);
i=1;
while 1
imagename=fgetl(fid);
if ~ischar(imagename),break,end
x=imread(imagename);
subplot(2,5,i);
subimage(x);
xlabel(imagename);
i=i+1;
end
fclose(fid);
errors
??? Error using ==> minus
Matrix dimensions must agree.
Error in ==> main>quadratic at 266
q=count1-count2;
Error in ==> main>colorSearch_Callback at 136
D=quadratic(X,map,Y,map1);
??? Subscripted assignment dimension mismatch.
Error in ==> main>obtainEnergies at 279
energies(i)=energyLevel(tl);
Error in ==> main>textureSearch_Callback at 169
queryEnergies=obtainEnergies(handles.queryx,6);
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 72
In main>shape at 335
In main>shapeSearch_Callback at 224
In gui_mainfcn at 96
In main at 42
In @(hObject,eventdata)main('shapeSearch_Callback',hObject,eventdata,guidata(hObject))
??? Error using ==> imread at 372
File "" does not exist.
Error in ==> main>shapeSearch_Callback at 223
K=imread(imagename);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> main at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)main('shapeSearch_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
  2 Comments
Image Analyst
Image Analyst on 24 Jan 2013
Edited: Image Analyst on 24 Jan 2013
FYI, (in case anyone is wondering) CBIR is Content-Based Image Retrieval. For example "retrieve for me all images of beaches".
Walter Roberson
Walter Roberson on 24 Jan 2013
I notice you have edited the question, but you have not responded to my Answer.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 24 Jan 2013
Set breakpoints and examine variables. You need to find out why you're passing a null filename into imread(), and some arrays (X,map,Y,map1) not having the proper size. Using the debugger you will be able to figure this out. We can't since we don't have your .fig file and don't have your images.

Walter Roberson
Walter Roberson on 24 Jan 2013
Your file base.txt is either empty or has a blank first line.
  5 Comments
DEEPTHI
DEEPTHI on 28 Jan 2013
Edited: Walter Roberson on 28 Jan 2013
thanks sir i got it for color....but didnt get for texture..
errors
Subscripted assignment dimension mismatch.
Error in ==> main>obtainEnergies at 279 energies(i)=energyLevel(tl);
Error in ==> main>textureSearch_Callback at 169 queryEnergies=obtainEnergies(handles.queryx,6);
for shape i got warning sir
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 72
In main>shape at 335
In main>shapeSearch_Callback at 224
In gui_mainfcn at 96
In main at 42
In @(hObject,eventdata)main('shapeSearch_Callback',hObject,eventdata,guidata(hObject))
Walter Roberson
Walter Roberson on 28 Jan 2013
Are you sure you wrote the code?
It should be obvious that decompose() is going to return arrays given that input.
What is not obvious is why you repeatedly apply decompose() to the same inputs "for j = 1 : 5". The body of your loop has no reference to j.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!