function CBIR_Query_minmax(q_imgid, dist_id, return_no)
% EE6850 HW3, Content-Based Image Retrieval
% CBIR_Query() --- main script
% take query, compute distance, rank them, display result
% input:
% query image ID (1~245)
% distance metric you want to use (1x2 vector) default histogram intersection
% # of output images (default 10)
% output:
% display
% 10-19-2001, xlx@ee.columbia.edu
% some global constants
VERBOSE = 1;
imgdir = 'H:\courses\vis\hw3\images\';
fetdir = 'H:\courses\vis\hw3\features\';
imgno = 1:245;
imgsuffix = '.png';
% parse input
if nargin < 1
q_imgid=input('input query image id (1~242):');
end
if nargin < 2 | isempty(dist_id)
dist_id = [3 3];
end
if nargin < 3
return_no = 10;
end
% load query feature
q_feature = load([fetdir,num2str(q_imgid),'.mat']);
q_feature = q_feature.feature;
% read features in the database, calculate the distance
dist = zeros(2, length(imgno));
for i=imgno
load([fetdir,num2str(i),'.mat']); % "feature": the structure containing features in the database
% get distance measure here
if dist_id(1) == 1
dist(1,i) = dist(1,i) + CBIR_L2dist(q_feature.colorhist, feature.colorhist);
elseif dist_id(1) == 2
dist(1,i) = dist(1,i) + CBIR_cosinedist(q_feature.colorhist, feature.colorhist);
elseif dist_id(1) == 3
dist(1,i) = dist(1,i) + CBIR_histintersection(q_feature.colorhist, feature.colorhist);
end
if dist_id(2) == 1
dist(2,i) = dist(2,i) + CBIR_L2dist(q_feature.edgedirection, feature.edgedirection);
elseif dist_id(2) == 2
dist(2,i) = dist(2,i) + CBIR_cosinedist(q_feature.edgedirection, feature.edgedirection);
elseif dist_id(2) == 3
dist(2,i) = dist(2,i) + CBIR_histintersection(q_feature.edgedirection, feature.edgedirection);
end
% ...
end
% combine two distance measures
%dist(1,:) = dist(1,:)/std(dist(1,:));
%dist(2,:) = dist(2,:)/std(dist(2,:));
% weights of different features
%lamda = 0 : 0.1 : 1;
lamda = [0 1];
for i = 1:length(lamda)
w = [lamda(i) 1-lamda(i)];
c_dist(i,:) = w*dist;
% sort the distance list
[d(i,:), index(i,:)] = sort(c_dist(i,:));
rank(i,index(i,:)) = 1:length(c_dist);
%rank = index;
end
% then sort the rank list, pick up the "consistently close" ones
c_rank = max(c_dist);
[score(1,:), score(2,:)] = sort(c_rank);
% pick up the top N=CxR images and display in C-columns and R-rows
R = 5;
C = ceil(return_no/R);
figure
for i = 1 : return_no
img = imread([imgdir,num2str(score(2,i)),imgsuffix]);
subplot(C, R, i);
imshow(img);
title(['No.', num2str(score(2,i)), ' d=', num2str( round(score(1,i)*1e4)*0.0001 )]);
end
- 1
- 2
- 3
- 4
- 5
- 6
前往页