⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbir_query.m

📁 matlab编程
💻 M
字号:
function  CBIR_Query(q_imgid, dist_id, lamda)
% EE6850 HW3, Content-Based Image Retrieval
% CBIR_Query() --- main script
% take query, compute distance, rank them, display result
% input:
%   query image ID
% output:
% 
% 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
    lamda = 0.7;
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
    w = [lamda 1-lamda];
    c_dist = w*dist;
    
% sort the distance
[score(1,:), score(2,:)] = sort(c_dist);
%score(1,:) = score(1,:)/max(score(1,:));

% pick up the top N=CxR images and display in C-columns and R-rows
N = 10; C = 2; R = 5; 
figure
for i = 1 : N
    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -