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

📄 create_dist_matrix.m

📁 彩色图像纹理提取的一种算法
💻 M
字号:
function [dist_matrix, dist_vector] = create_dist_matrix(ts, mirror, howdist)

% Create Distance Matrix, (Adam Meadows: ameadows@cs.ucr.edu)
% [dist_matrix, dist_vector] = create_dist_matrix(ts, mirror, howdist)
% 
% TS is a collection of time series to be used to create the dist matrix
% MIRROR is a flag used to check mirror images of objects (0=no/1=yes)
% HOWDIST is a flag for what distance measure to use (0=euclidean)
%
% DIST_MATRIX returns an NxN distance matrix where N is the length of TS
% DIST_VECTOR returns a distance vector for dendogram creation
%


s = size(ts);
number_of_ts = s(1);
disp(['There are ',int2str(number_of_ts),' time series'])

dist_matrix = zeros(number_of_ts,number_of_ts);
dist_vector = [];

for i = 1 : number_of_ts
   for j = i+1 : number_of_ts       
        A = ts(i,:);
        B = ts(j,:);
        dist_matrix(i,j) = icon_dist(A,B,mirror,howdist);
        dist_matrix(j,i) = dist_matrix(i,j);
        dist_vector = [dist_vector icon_dist(A,B,mirror,howdist)];
   end;    
end;

%end of dist_matrix function

%==========================================================================
%==========================================================================





%local function for calculating distance between 2 timeseries
function dist =  icon_dist(A,B,mirror,howdist)
%A= (A-min(A))/max(A);
%B= (B-min(B))/max(B);
%dist = sum(((A-B).^2));

dist = inf;
for i =1:length(A)  
    temp = [A(end-(i-2):end) , A(1:end-i+1)];
    if(howdist == 0) %Euclidean Distance
        d = sum(((temp-B).^2));
    elseif(howdist == 1) %DTW
        [d, tempD, tempk, tempw] = dtw(B, temp);
        elseif(howdist == 2) %SAX-Euclidean
    end

    if d < dist
        dist = d;   
    end
end

%if mirror == 1, match mirror image too
if mirror == 1
    %flip it
    A = fliplr(A);
   
    %check all rotations of new image
    for i =1:length(A)  
        temp = [A(end-(i-2):end) , A(1:end-i+1)];
        if(howdist == 0) %Euclidean Distance
            d = sum(((temp-B).^2));
        elseif(howdist == 1) %DTW
            [d, tempD, tempk, tempw] = dtw(B, temp);
            elseif(howdist == 2) %SAX-Euclidean
        end

        if d < dist
            dist = d;   
        end
    end
    
    
end %end of if we're supposed to check the mirror image too

%end

% for i =1:length(A)  
%   
%     temp = [A(end-(i-2):end) , A(1:end-i+1)];
%     temp = fliplr(flipud(temp));
%     d = sum(((temp-B).^2));
%     if d < dist
%      dist = d;   
%     end
%    
% end
 

% dist = inf;
% for i =1:length(A)  
%   
%     temp = [A(end-(i-2):end) , A(1:end-i+1)];
%     d = sum(((temp(10:end-10)-B(10:end-10)).^2));
%     if d < dist
%      dist = d;   
%     end
%     
% end

% dist = inf;
% for i = [1:40 length(A)-40: length(A)   ] %length(A)  
%   
%     temp = [A(end-(i-2):end) , A(1:end-i+1)];
%     d = sum(((temp(3:end-3)-B(3:end-3)).^2));
%     if d < dist
%      dist = d;   
%     end
%     
% end
 
%end of dist function

%==========================================================================
%==========================================================================

⌨️ 快捷键说明

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