工具1:给定坐标点输出成marker文件
部分数据集给的groundtruth可能是以坐标点的形式呈现,但是vaa3d中需要的往往是.marker文件的形式,因此我们可能需要使用matlab将坐标转换成为marker文件。
function [ ] = coordinate2marker( input_args,filename )
%UNTITLED5 此处显示有关此函数的摘要
% 此处显示详细说明
if exist(filename)
delete(filename)
end
sizeofinput=size(input_args);
if sizeofinput(1)==2&&sizeofinput(1)~=2
cor=input_args';
elseif sizeofinput(2)==2
cor=input_args;
elseif sizeofinput(2)~=2&&sizeofinput(1)~=2
error('please input true cordi')
end
for i=1:size(cor,1)
m_struct{i}.x=cor(i,1);
m_struct{i}.y=cor(i,2);
m_struct{i}.z=1;
m_struct{i}.radius = 0;
m_struct{i}.shape = 1;
m_struct{i}.name = '';
m_struct{i}.comment = '';
m_struct{i}.r=255;
m_struct{i}.g=0;
m_struct{i}.b=0;
end
save_v3d_marker_file(m_struct,filename);
end
这个代码需要用到v3d中带v3d_external\matlab_io_basicdatatype文件夹,但是这个文件夹下的版本可能不同,其中较低版本的marker文件没有颜色属性,请注意。
工具2 match实验集和ground truth两个marker文件
%假设experiment_marker 和ground_truth_marker均不存在重复的点
clear
clc
experiment_filename='02_manual1_no_clu_23_15_52_14.marker';
ground_truth_filename='02_manual1.tif_groundtruth.marker';
experiment_marker=load_v3d_marker_file(experiment_filename);
ground_truth_marker=load_v3d_marker_file(ground_truth_filename);
distance_2p=10;
color_a=[255 0 255];% 小红 exp未匹配
color_b=[0 255 0];% 浅黄 exp距离匹配
color_c=[0 255 0];% 绿色 exp完全匹配 gt完全匹配
color_d=[0 255 0];%浅绿色 gt距离匹配
color_e=[255 0 0]; %大红色 漏检 gt 未匹配
color_f=[255 127 0];%橙色 gt多匹配
%init
for i=1:length(experiment_marker)
experiment_marker{i}.name='0';
end
for i=1:length(ground_truth_marker)
ground_truth_marker{i}.name='0';
end
for i=1:length(experiment_marker)
expmarker=experiment_marker{i};
flag_match=0;%0 没有匹配 1 完全匹配 2 距离匹配 % 3多匹配
mindist=distance_2p+10;
match_object=1;
for j=1:length(ground_truth_marker)
gtmarker=ground_truth_marker{j};
a=[expmarker.x expmarker.y];
b=[gtmarker.x gtmarker.y];
if expmarker.x==gtmarker.x&&expmarker.y==gtmarker.y
%精确匹配
flag_match=1;
match_object=j;
break;
elseif sqrt((a-b)*(a-b)')<distance_2p&&sqrt((a-b)*(a-b)')<mindist
%距离内匹配
flag_match=2;
mindist=sqrt((a-b)*(a-b)');
match_object=j;
end
end
%chaxun jieshu
%开始处理
gtmarker=ground_truth_marker{match_object};
if flag_match==1
%精确匹配
if (expmarker.name=='0')| (expmarker.name=='')
experiment_marker{i}.name='1';
elseif expmarker.name=='1'
disp(['expmarker.name:' expmarker.name])
error('expmarker.name==1')
end
if (gtmarker.name=='0')|(gtmarker.name=='')
ground_truth_marker{match_object}.name='1';
elseif (gtmarker.name=='1')|(gtmarker.name=='2')
ground_truth_marker{match_object}.name='3';%多匹配
end
elseif flag_match==2
%距离内匹配
if (expmarker.name=='0')| (expmarker.name=='')
experiment_marker{i}.name='2';
elseif expmarker.name=='1'
disp(['expmarker.name:' expmarker.name])
error('expmarker.name==1')
end
if (gtmarker.name=='0')|(gtmarker.name=='')
ground_truth_marker{match_object}.name='2';
elseif (gtmarker.name=='2' ) | ( gtmarker.name=='1' )
ground_truth_marker{match_object}.name='3';%多匹配
end
elseif flag_match==0
%未匹配
if (expmarker.name=='0') | (expmarker.name=='')
experiment_marker{i}.name='0';
end
end
end
%输出 计数
count0=0;count1=0;count2=0;
count3=0;count4=0;count5=0;
% colors=[255,200,200];
for i=1:length(experiment_marker)
if experiment_marker{i}.name=='0'
experiment_marker{i}.r=color_a(1);
experiment_marker{i}.g=color_a(2);
experiment_marker{i}.b=color_a(3);
count0=count0+1;
elseif experiment_marker{i}.name=='1'
experiment_marker{i}.r=color_c(1);
experiment_marker{i}.g=color_c(2);
experiment_marker{i}.b=color_c(3);
count1=count1+1;
elseif experiment_marker{i}.name=='2'
experiment_marker{i}.r=color_b(1);
experiment_marker{i}.g=color_b(2);
experiment_marker{i}.b=color_b(3);
count2=count2+1;
elseif experiment_marker{i}.name==''
experiment_marker{i}.r=color_a(1);
experiment_marker{i}.g=color_a(2);
experiment_marker{i}.b=color_a(3);
error('what??? experiment_marker{i}.name=='' ')
else
disp(experiment_marker{i})
error('what??? impossible')
end
outputStruct{i}=experiment_marker{i};
end
for i=1:length(ground_truth_marker)
if ground_truth_marker{i}.name=='0'
ground_truth_marker{i}.r=color_e(1);
ground_truth_marker{i}.g=color_e(2);
ground_truth_marker{i}.b=color_e(3);
count3=count3+1;
elseif ground_truth_marker{i}.name=='1'
%不需要再次加入
ground_truth_marker{i}.r=color_c(1);
ground_truth_marker{i}.g=color_c(2);
ground_truth_marker{i}.b=color_c(3);
continue;
elseif ground_truth_marker{i}.name=='2'
ground_truth_marker{i}.r=color_d(1);
ground_truth_marker{i}.g=color_d(2);
ground_truth_marker{i}.b=color_d(3);
count4=count4+1;
elseif ground_truth_marker{i}.name=='3'
ground_truth_marker{i}.r=color_f(1);
ground_truth_marker{i}.g=color_f(2);
ground_truth_marker{i}.b=color_f(3);
count5=count5+1;
elseif ground_truth_marker{i}.name==''
disp(ground_truth_marker{i})
error('what??? ground_truth_marker{i}')
end
outputStruct{length(outputStruct)+1}=ground_truth_marker{i};
end
save_v3d_marker_file(outputStruct,[experiment_filename '_verify.marker'])
save_v3d_marker_file(ground_truth_marker,[experiment_filename '_verify_gt.marker'])
save_v3d_marker_file(experiment_marker,[experiment_filename '_verify_exp.marker'])
disp('参数:')
disp(['匹配阈值距离 :' num2str(distance_2p)])
precise=count0/length(experiment_marker);
disp(['误检率: ' num2str(1-precise)])
disp(['误检数量: ' num2str(count0) ',输入marker数量: ' num2str(length(experiment_marker))])
recall=count3/length(ground_truth_marker);
disp(['漏检率: ' num2str(1-recall)])
disp(['漏检数量: ' num2str(count3) ',ground truth 数量: ' num2str(length(ground_truth_marker))])