• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

转载:图像跟踪中像素误差、重叠率、AUC的计算:Matlab实现

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

        视频图像跟踪算法的评估常常需要计算重叠率(Overlap Rate)、像素误差(Pixel Error)还有AUC(Area Under Curve)。这些技术指标都比较好理解,如果不理解的话可以参见我之前的博客。这篇博客主要就是贴上Matlab的代码,使用Matlab计算这些参数,并绘制出曲线图。

        如果你是想放在Paper中的话,可以下载Visual Track BenchMark中提供的代码,可以画出和Paper上一样的样式,这篇博客只是博主对单个视频自己写的小demo,便于自己分析实验的,如果要在Paper使用还需要做样式的修改。

        关于各个指标,之前博客已经介绍过了,这里就简单讲一下

一、重叠率

        重叠率 = 重叠区域面积/(预测矩形的面积+真实矩形的面积-重叠区域的面积)

二、像素误差

        像素误差 = 真实中心和预测中心的欧式距离

三、AUC

        成功率图的曲线下面积

四、Matlab计算

        变量说明:

        数据文件为Object Tracker BenchMark中的数据格式存放在./results_TRE_CVPR13/文件夹中,图像序列(只用到了groundtruth.txt的真实值)存储在F:\Data\sequence\,这个两个量都可以在代码中修改。

        video_set: 图像数据集名称

        method_set: 方法名称

        line_style: 要和method_set的大小相等,每种线条样式method相对应

close all;
clear all;
 
video_set = {'Shaking'};
%video_set = {'BlurCar2','Car2','Car4','Car24','Doll','Human6','RedTeam','Singer1','Walking','Walking2'};
 
method_set = {'FMT', 'kcf_hog8'};
line_style = {'--r', '--g'};
 
base_path = 'F:\Data\sequence\';
results_path = './results_TRE_CVPR13/';
precision{numel(video_set), numel(method_set)} = 0;
 
auc_table{numel(video_set)+1, numel(method_set)+1} = 0;
auc_table{1,1}=0;
 
for i = 1:numel(video_set)
    auc_table{i+1,1}=video_set{i};
    % read groundtruth
    varlist = {'gt','gt_center','gt_rect','gt_area','center','boxes,res_rect','res_area',...
        'overlap_rect','overlap_area','overlap_rate','mask','pixel_error','er'};
    clear(varlist);
    gt_file = fopen([base_path video_set{i} '\groundtruth_rect.txt']);
    try
        groundtruth_roi = textscan(gt_file, '%f,%f,%f,%f', 'ReturnOnError', false);
        gt(:,1)=groundtruth_roi{1};
        gt(:,2)=groundtruth_roi{2};
        gt(:,3)=groundtruth_roi{3};
        gt(:,4)=groundtruth_roi{4};
    catch  %#ok, try different format (no commas)
        frewind(gt_file);
        groundtruth_roi = textscan(gt_file, '%f %f %f %f');
        gt(:,1)=groundtruth_roi{1};
        gt(:,2)=groundtruth_roi{2};
        gt(:,3)=groundtruth_roi{3};
        gt(:,4)=groundtruth_roi{4};
    end
    gt_center(:,1) = gt(:,1) + gt(:,3)/2;
    gt_center(:,2) = gt(:,2) + gt(:,4)/2;
    gt_rect(:,1) = gt(:,1);
    gt_rect(:,2) = gt(:,2);
    gt_rect(:,3) = gt(:,1) + gt(:,3);
    gt_rect(:,4) = gt(:,2) + gt(:,4);
    gt_area = gt(:,3).*gt(:,4);
    % caculate different method precision
    for ii = 1:numel(method_set)
        auc_table{1,ii+1}=method_set{ii};
        clear('fig','boxes','center','er','pixel_error','res_rect','overlap_rect','mask',...
            'overlap_rate','overlap_area','xx','yy');
        %read results (标准格式)
        r = load([results_path lower(video_set{i}) '_' method_set{ii} '.mat']);
        boxes = r.results{1}.res;
        assert(size(boxes,1)==size(gt,1));
        % caculate pixel error
        center(:,1) = boxes(:,1)+boxes(:,3)/2;
        center(:,2) = boxes(:,2)+boxes(:,4)/2;
        er = center - gt_center;
        pixel_error = sqrt(er(:,1).*er(:,1)+er(:,2).*er(:,2));
        % caculate overlaprate
        res_rect(:,1) = boxes(:,1);
        res_rect(:,2) = boxes(:,2);
        res_rect(:,3) = boxes(:,1)+boxes(:,3);
        res_rect(:,4) = boxes(:,2)+boxes(:,4);
        res_area = boxes(:,3).*boxes(:,4);
        overlap_rect(:,1) = max(res_rect(:,1), gt_rect(:,1));
        overlap_rect(:,2) = max(res_rect(:,2), gt_rect(:,2));
        overlap_rect(:,3) = min(res_rect(:,3), gt_rect(:,3));
        overlap_rect(:,4) = min(res_rect(:,4), gt_rect(:,4));
        mask = or((overlap_rect(:,1)>overlap_rect(:,3)), overlap_rect(:,2)>overlap_rect(:,4));
        overlap_area = (overlap_rect(:,3)-overlap_rect(:,1)).*(overlap_rect(:,4)-overlap_rect(:,2));
        overlap_area(mask) = 0;
        overlap_rate = overlap_area ./ (gt_area + res_area - overlap_area + eps);
        % visualization and result
        fig.video = video_set{i};
        fig.method = method_set{ii};
        fig.len = size(boxes,1);
        [yy, xx] = cdfcc(overlap_rate);
        fig.ol = overlap_rate;
        fig.olm = mean(overlap_rate);
        fig.olcdf.x = xx;
        fig.olcdf.x(1) = 0;
        fig.olcdf.x(end) = 1;
        fig.olcdf.y = 1-yy;
        [yy, xx] = cdfcc(pixel_error);
        fig.pe = pixel_error;
        fig.pem = mean(pixel_error);
        fig.pecdf.x = xx;
        fig.pecdf.y = yy;
        precision{i,ii} = fig;
        auc_table{i+1,ii+1} = fig.olm;
    end
    
    % show plot
    if 1,
        figure('Name', 'Pixel Error', 'Color', 'w');
        for ii = 1:numel(method_set),
            plot(1:precision{i,ii}.len, precision{i,ii}.pe, line_style{ii}, 'LineWidth', 2), hold on;
            lg{ii} = [method_set{ii} ' ' sprintf('%.2f', precision{i,ii}.pem)];
        end
        title(video_set{i});xlabel('Frame#');ylabel('Pixel Error');
        legend(lg);
        
        figure('Name', 'Overlap Rate', 'Color', 'w');
        for ii = 1:numel(method_set),
            plot(1:precision{i,ii}.len, precision{i,ii}.ol, line_style{ii}, 'LineWidth', 2), hold on;
            lg{ii} = [method_set{ii} ' ' sprintf('%.2f', precision{i,ii}.olm)];
        end
        title(video_set{i});xlabel('Frame#');ylabel('Overlap Rate');
        legend(lg);
        
        figure('Name', 'Pixel Error Success Plot', 'Color', 'w');
        for ii = 1:numel(method_set),
            plot(precision{i,ii}.pecdf.x, precision{i,ii}.pecdf.y, line_style{ii}, 'LineWidth', 2), hold on;
            %lg{ii} = [method_set{ii} ' ' sprintf('%.2f', trapz(precision{i,ii}.pecdf.x(2:end-1), precision{i,ii}.pecdf.y(2:end-1)))];
        end
        title(video_set{i});xlabel('Pixel Error Threshold');ylabel('Success Rate');
        legend(method_set);
        
        figure('Name', 'Overlap Rate Success Plot', 'Color', 'w');
        for ii = 1:numel(method_set),
            plot(precision{i,ii}.olcdf.x, precision{i,ii}.olcdf.y, line_style{ii}, 'LineWidth', 2), hold on;
            lg{ii} = [method_set{ii} ' ' sprintf('%.2f', trapz(precision{i,ii}.olcdf.x, precision{i,ii}.olcdf.y))];
        end
        title(video_set{i});xlabel('Overlap Rate Threshold');ylabel('Success Rate');
        legend(lg);
        
    end
    
end

 

其中用到了一个函数,也贴上来

1
2
3
4
5
6
7
)
;
;
;
;
;
end

 

        这里已经在图例中放入了计算出的平均像素误差、平均重叠率、AUC的数值。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi如何在Form的标题栏绘制自定义文字 - ╰★张志峰★╮发布时间:2022-07-18
下一篇:
Delphi资源文件(.res)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap