% RGB retrieval
%fid=fopen('ninecolor3_distr.dat','r'); normalized central moments
fid=fopen('ninecolor2_distr.dat','r');
%fid2=fopen('edge2_radon_svd0.dat','r');
%fid1=fopen('edge2_radon_svd90.dat','r');
%fid3=fopen('edge2_radon_0org.dat','r');
%fid4=fopen('edge2_radon_90org.dat','r');
fid2=fopen('ninecolor2_dist.dat','r');
PCACOE=10;
MU=0.78315;
DLT=0.16879;
MAX=1.6582;
MIN=0;
MU1=58.781;
DLT1=19.922;
MAX1=130.83;
MIN1=0;
MU2=2.6843;
DLT2=0.66799;
MAX2=4.5187;
MIN2=0;
%fid1=fopen('avecolor.dat','r');
%for (i=1:910)
% tmp_mom=fread(fid1,10,'float');
% ind12(:,i)=tmp_mom(1:PCACOE);
% tmp_mom=fread(fid2,10,'float');
% ind13(:,i)=tmp_mom(1:PCACOE);
%end
%ind_pca0=ind12';
%ind_pca90=ind13';
%fclose(fid1);
%fclose(fid2);
%for (i=1:910)
% tmp_mom=fread(fid3,128,'float');
% ind14(:,i)=tmp_mom(1:128);
% tmp_mom=fread(fid4,128,'float');
% ind15(:,i)=tmp_mom(1:128);
%end
%ind_0org=ind14';
%ind_90org=ind15';
%fclose(fid3);
%fclose(fid4);
for (i=1:910)
hist1(:,i)=fread(fid2,18,'float');
end
ind_dis=hist1';
fclose(fid2);
for (i=1:910)
hist(:,i)=fread(fid,63,'float');
end
ind_c=hist';
fclose(fid);
NULL_seg=[0 0 0 0 0 0 0];
isize=910;
qi=1;
dist1=0;
qi=input('Query image no:(1-910 or 0 to quit)');
while (qi~=0)
qh=ind_c(qi,:);
for (cnt=1:910)
dist=0;
db=ind_c(cnt,:);
for (j=1:9)
%% L1/L2 Distances
tmp_vec=qh((j-1)*7+1:j*7);
tmp_vec1=db((j-1)*7+1:j*7);
%if ((tmp_vec==NULL_seg)|(tmp_vec1==NULL_seg))
%% if (sum(tmp_vec(4:6))~=0)
%% angl=1-(2/pi)*acos(abs(tmp_vec(4:6)*tmp_vec1(4:6)'));
%% else
%% angl=0;
%% end
%% if (angl<0)
%% angl=0;
%% end
%dist=dist+norm(tmp_vec(1:3)-tmp_vec1(1:3),2)+angl+abs(tmp_vec(7)-tmp_vec1(7));
dist=dist+norm(tmp_vec(1:6)-tmp_vec1(1:6),2)+abs(tmp_vec(7)-tmp_vec1(7));
%dist=dist+norm(tmp_vec-tmp_vec1,1);
end
% Distance of SVD coefficients
%% dist1=0.5*(norm(ind_pca90(qi,:)-ind_pca90(cnt,:),2)+norm(ind_pca0(qi,:)-ind_pca0(cnt,:),2));
%% dist2=0.5*(norm(ind_90org(qi,:)-ind_90org(cnt,:),2)+norm(ind_0org(qi,:)-ind_0org(cnt,:),2));
%% New distance
%%DIST=0;
%% for (k=1:9)
%% DIST=DIST+qh(k*7)^2;
%5 end
%% for (j=1:9)
%% DIST=DIST+db(j*7)^2;
%% end
%% for (k=1:9)
% for (j=1:9)
% tmp_arr=db((j-1)*7+1:j*7);
%
% d1=norm(qh((k-1)*7+1:(k-1)*7+6)-tmp_arr(1:6),2);
% if (d1>0.08)
% a1=0;
% else
% a1=1-d1/0.096;
% end
% DIST=DIST-2*a1*qh(k*7)*tmp_arr(7);
%dist00(k,j)=norm(query0((k-1)*4+1:(k-1)*4+3)-tmp_arr(1:3),2)+sum(abs(query0(k*4)-tmp_arr(4)));
%dist00(k,j)=sum(abs(query0((k-1)*4+1:(k-1)*4+4)-tmp_arr(1:4)));
%%dist00(k,j)=norm(query0((k-1)*4+1:(k-1)*4+3)-tmp_arr(1:3),1)+(1-min(query0(k*4),tmp_arr(4))/max(query0(k*4),tmp_arr(4)));
%%dist01(k,j)=norm(query0((k-1)*2+1:k*2)-tmp_arr(1:2),2);
%dist01(k,j)=norm(ind_ctroid(qi,(k-1)*2+1:k*2)-ind_ctroid(cnt,(j-1)*2+1:j*2),2);
%% dist02(k,j)=norm(hsv_pca0(q_no+k-1,:)-hsv_pca0(db_no+j-1,:),2)+norm(hsv_pca90(q_no+k-1,:)-hsv_pca90(db_no+j-1,:),2);
%% end
%% end
%% dist=DIST;
dist1=norm(ind_dis(qi,:)-ind_dis(cnt,:),1);
%dist=0.0*dist+1.0/1*(dist1-(MU-3*DLT))/(6*DLT);
%dist=0.0*dist+1.0/1*(dist1-MIN)/MAX;
dist2=0;
dist=1.0*(dist-(MU2-3*DLT2))/(6*DLT2)+0.0*(dist1-(MU1-3*DLT1))/(6*DLT1)+0.0*dist2;
result(:,cnt)=[dist cnt]';
end
%查询结果显示
format short g;
result1=result';
%result2(:,1)=result1(:,2);
%result2(:,2)=result1(:,1);
result2=sortrows(result1);
%disp(result2(isize-9:isize,:));
disp(result2(1:10,:));
%Display first ten IMAGES
pause;
%name=input('Search image:','s');
i=0;
%figure;
rank=1;
%for (k=isize:-1:isize-9)
wh=figure;
set(wh,'Color',[0.8 0.8 0.8]);
set(wh,'Units','Normal');
set(wh,'Position',[0.05 0.05 0.9 0.8]);
set(wh,'MenuBar','none');
for (k=1:50)
bmpno=round(result2(k,2)-1);
iname=sprintf('f:\\image\\img\\%d.jpg',bmpno);
[img map]=imread(iname);
if (isrgb(img))
[img map]=rgb2ind(img,256);
end
img=imresize(img,[200 256]); %[128 128]
hdl=subplot(5,10,rank);
sv=strcat('',num2str(result2(k,1)));
% frno=ceil(k/10);
% fcno=mod(k,10);
% if (fcno==0)
% fcno=10;
% end
%subimage((frno-1)*0.1,(fcno-1)*0.1,img,map);
subimage(img,map);
%%set(hdl,'Units','Pixels');
%%set(hdl,'Position',[0.05+mod(rank-1,10)*0.09 0.95-(floor((rank-1)/10)+1)*0.18 0.09 0.18]);
%%lh=get(hdl,'Xlabel');
%%set(lh,'String',sv);
set(hdl,'Title',text('String',sv));
posxy=get(hdl,'Position');
%%set(gcf,'Units','normalized');
rfcbox=uicontrol(gcf,'Style','Checkbox','Units','normalized',...
'Position',[posxy(1) posxy(2)-0.02 0.086 0.052],...
'String','RF=N','CallBack','my_rf');
%% ['set(gca,"RF","N"),','if get(rfcbox,"Value")==1,', 'set(gca,"RF","Y"),','end'] 'String','Box=on',...
set(hdl,'YTickLabel',[]),set(hdl,'XTickLabel',[]);
%set(hdl,'YGrid','off'),set(hdl,'XGrid','off');
set(hdl,'YTick',[]),set(hdl,'XTick',[]);
set(hdl,'Box','off');
rank=rank+1;
end
%end
%flops
qi=input('Query image no:(1-110 or 0 to quit)');
end