角点测评可重复率函数原始

编程入门 行业动态 更新时间:2024-10-10 17:22:47

角点测评可重复率<a href=https://www.elefans.com/category/jswz/34/1771370.html style=函数原始"/>

角点测评可重复率函数原始

角点测评可重复率函数原始

function Result=Comparison_cpda()close allclcticResult=[];parfor cnt =1:23cntldpath = sprintf('%d.bmp',cnt);f=imread(ldpath);[original_corners]=cpda(f);         %获得原始图片的角点Ar_a=[];Le_a=[];%% 旋转%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 旋转%rotation transformation,from -90°to 90°,at 10° apart,excluding 0°toppoints=[];Le_a_for_rotation=[];                                 %存放图片旋转后的定位误差Ar_a_for_rotation=[];                                 %存放图片旋转后的平均重复率for angle=0fr=imrotate(f,angle);%[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];endfor angle=-90:10:-10fr=imrotate(f,angle);[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];endfor angle=10:10:90fr=imrotate(f,angle);[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];end  Ar_a_for_rotation=mean(Ar_a_for_rotation);             %平均Le_a_for_rotation=mean(Le_a_for_rotation);Ar_a=[Ar_a;Ar_a_for_rotation];Le_a=[Le_a;Le_a_for_rotation];%% 旋转End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 旋转End%% 比例%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 比例%%uniform and nonuniform scaling transformation,x from 0.5 to 2.0,at 0.1 apart,y from 0.5 toppoints=[];Ar_a_for_scale=[];Le_a_for_scale=[];for scale_x=0.5:0.1:2.0for scale_y=0.5:0.1:2.0if scale_x~=1 ||scale_y~=1 T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);fu= imtransform(f,T);a_first_change=nonuniform_coordinate_change(original_corners,scale_x,scale_y);[Ar,Le]=calculate(fu,a_first_change,toppoints);Le_a_for_scale=[Le_a_for_scale;Le];Ar_a_for_scale=[Ar_a_for_scale;Ar];endendendAr_a_for_scale=mean(Ar_a_for_scale);Le_a_for_scale=mean(Le_a_for_scale);Ar_a=[Ar_a;Ar_a_for_scale];Le_a=[Le_a;Le_a_for_scale];%% 比例End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 比例变换End%% 仿射%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 仿射%combined(affine) transformation,angles range form -30°to -30°;x,y from %0.8 to 1.2,at 0.1 apart,y from 0.8 to 1.2,at 0.1 apart,excluding x=ytoppoints=[]; Le_a_for_affine=[];Ar_a_for_affine=[];angle_array=[-30 -20 -10 10 20 30 ];for i=1:6angle=angle_array(i);for scale_x=0.8:0.1:1.2for scale_y=0.8:0.1:1.2if abs(scale_x-scale_y)>1e-3if scale_x~=1 ||scale_y~=1 T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);fr=imrotate(f,angle);fu= imtransform(fr,T);[a_first_change1,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);a_first_change2=nonuniform_coordinate_change(a_first_change1,scale_x,scale_y);if isempty(toppoints)==0toppoints=floor(toppoints.*repmat([scale_y scale_x],[size(toppoints,1),1]));end[Ar,Le]=calculate(fu,a_first_change2,toppoints);Le_a_for_affine=[Le_a_for_affine;Le];Ar_a_for_affine=[Ar_a_for_affine;Ar];endendendendendAr_a_for_affine=mean(Ar_a_for_affine);Le_a_for_affine=mean(Le_a_for_affine);Ar_a=[Ar_a;Ar_a_for_affine];Le_a=[Le_a;Le_a_for_affine];%% 仿射End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 仿射变换End%% Jpeg%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jpegtoppoints=[];Le_a_for_compression=[];Ar_a_for_compression=[];for quality_factor=5:5:100imwrite(f,'a_compression.jpg','Quality',quality_factor,'mode','lossy');fc=imread('a_compression.jpg');[Ar,Le]=calculate(fc,original_corners,toppoints);Le_a_for_compression=[Le_a_for_compression;Le];Ar_a_for_compression=[Ar_a_for_compression;Ar];endAr_a_for_compression=mean(Ar_a_for_compression);Le_a_for_compression=mean(Le_a_for_compression);Ar_a=[Ar_a;Ar_a_for_compression];Le_a=[Le_a;Le_a_for_compression];%% JpegEnd%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% JpegEnd%% 高斯噪声%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 高斯噪声toppoints=[];Le_a_for_noise=[];Ar_a_for_noise=[];for noise=0.005:0.005:0.05fi=imnoise(f,'Gaussian',noise);[Ar,Le]=calculate(fi,original_corners,toppoints);Le_a_for_noise=[Le_a_for_noise;Le];Ar_a_for_noise=[Ar_a_for_noise;Ar];endAr_a_for_noise=mean(Ar_a_for_noise);Le_a_for_noise=mean(Le_a_for_noise);Ar_a=[Ar_a;Ar_a_for_noise];Le_a=[Le_a;Le_a_for_noise];Ar_a=Ar_aLe_a=Le_aResult=[Result;Ar_a];Result=[Result;Le_a];%% 高斯噪声End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 高斯噪声Endend % end cnt =1:12xlswrite('03Output/result_sum_cpda.xlsx',Result);toc
end%本函数为图片旋转后,GT角点应该也响应旋转
%In:
%corners:Ground Truth为原来角点
%image_or为原始图片
%image_ch为旋转后的图片
%angele为图片旋转后的角度%Out:
%corners:
function [corners,toppoints]=rotation_coordinate_change(corners,image_or,image_ch,angle)if isempty(corners)==0theta=-angle*pi/180;[cyo,cxo]=size(image_or);[cy_ro,cx_ro]=size(image_ch);tp1=[1 1];tp2=[1 cyo];tp3=[cxo 1];tp4=[cxo cyo];xo=corners(:,2);yo=corners(:,1);corners=[tp1;tp2;tp3;tp4;xo yo];corners_change_axis=corners.*repmat([1 -1],[size(corners,1),1])+repmat([-cxo/2 cyo/2],[size(corners,1),1]);corners_rotate=corners_change_axis*[cos(theta) -sin(theta);sin(theta) cos(theta)];corners_restore=corners_rotate.*repmat([1 -1],[size(corners_rotate,1),1])+repmat([cx_ro/2 cy_ro/2],[size(corners_rotate,1),1]);corners_restore=floor(corners_restore);corners=[corners_restore(:,2) corners_restore(:,1)];toppoints=corners(1:4,:);corners=corners(5:size(corners,1),:);elsecorners=[];toppoints=[];end
endfunction [Ar,Le]=calculate(f,change_corners,toppoints)[detect_corners]=cpda(f);detect_corners2=detect_corners;size_change=size(change_corners,1);size_detect=size(detect_corners,1);Nc=size_change;Nd=size(detect_corners,1);Nr=0;Ar=0;Le=0;% mark=[];% miss=[];% false_corners=detect_corners;%% match first level cornersif isempty(detect_corners)==0for i=1:size_changecompare_first_corner=detect_corners-ones(size_detect,1)*change_corners(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)==0%             Nm=Nm+1;%             miss=[miss;change_corners(i,:)];elsedetect_corners(find(compare_first_corner==min(compare_first_corner)),:)=0;Nr =Nr+1;Le=Le+min(compare_first_corner);endend%%if isempty(toppoints)==0for i=1:4compare_first_corner=detect_corners2-ones(size_detect,1)*toppoints(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)~=0Nd=Nd-size(mark,1);endendend    %%Le=sqrt(Le/Nd);  Ar=Nr/2*(1/Nc+1/Nd);elseLe=0;Ar=0;endend%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%change the standard corners' coordinate when the images transformed with
%%uniform or nonuniform scaling
function [corners]=nonuniform_coordinate_change(corners,scale_x,scale_y)if isempty(corners)==0corners=floor(corners.*repmat([scale_y scale_x],[size(corners,1),1]));elsecorners=[];end
end

角点测评基于。。重复率函数

function Result=Comparisonb_superpiont()close allclcticResult=[];Precision_a=[];
Recall_a=[];
ACU_a=[];
F_a=[];
PicCount=0;addpath('superpoint_original');
addpath('gttxt');
addpath('02Images');for cnt =1:21PicCount=PicCount+1;ResultCol=[];
%     gttxtfilename=strcat('gttxt/',num2str(cnt),'.txt')a_first=getCoord(txtfilename);
%    a_first(:,[1, 2] ) =  a_first(:,[2, 1] );ldpath = sprintf('%d.png',cnt);  %这里不需要检测坐标,但是还是需要读取原图f=imread(ldpath);%     原始角点or_filename=strcat(num2str(cnt),'_r_0.txt');or_corner=getCoord(or_filename)or_corner(:,[1, 2] ) =  or_corner(:,[2, 1] );
%      用gt对原始角点过滤filerorigin=filter_origion(or_corner,a_first);cnt%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Rotation
%rotation transformation,from -90°to 90°,at 10° apart,excluding 0°Ar_a=[];Le_a=[];
%% 旋转%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 旋转
%rotation transformation,from -90°to 90°,at 10° apart,excluding 0°
toppoints=[];
Le_a_for_rotation=[];                                 %存放图片旋转后的定位误差
Ar_a_for_rotation=[];                                 %存放图片旋转后的平均重复率
for angle=0fr=imrotate(f,angle);filename=strcat(num2str(cnt),'_r_',num2str(angle),'.txt')[filerorigin_change,toppoints]=rotation_coordinate_change(filerorigin,f,fr,angle);[Ar,Le]=calculate(filename,filerorigin_change,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];end
for angle=-90:10:-10fr=imrotate(f,angle);filename=strcat(num2str(cnt),'_r_',num2str(angle),'.txt');[filerorigin_change,toppoints]=rotation_coordinate_change(filerorigin,f,fr,angle);[Ar,Le]=calculate(filename,filerorigin_change,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];end
for angle=10:10:90fr=imrotate(f,angle);filename=strcat(num2str(cnt),'_r_',num2str(angle),'.txt');[filerorigin_change,toppoints]=rotation_coordinate_change(filerorigin,f,fr,angle);[Ar,Le]=calculate(filename,filerorigin_change,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];endAr_a_for_rotation=mean(Ar_a_for_rotation);             %平均Le_a_for_rotation=mean(Le_a_for_rotation);Ar_a=[Ar_a;Ar_a_for_rotation];Le_a=[Le_a;Le_a_for_rotation];%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% scaling
%%uniform and nonuniform scaling transformation,x from 0.5 to 2.0,at 0.1 apart,y from 0.5 
%%to 2.0,at 0.1 apart,excluding x=y
toppoints=[];
Ar_a_for_scale=[];
Le_a_for_scale=[];
for scale_x=0.5:0.1:2.0for scale_y=0.5:0.1:2.0if scale_x~=1 ||scale_y~=1 filename=strcat(num2str(cnt),'_s_',num2str(scale_x),'_',num2str(scale_y),'.txt');T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);%fu= imtransform(f,T);filerorigin_change=nonuniform_coordinate_change(filerorigin,scale_x,scale_y);[Ar,Le]=calculate(filename,filerorigin_change,toppoints);Le_a_for_scale=[Le_a_for_scale;Le];Ar_a_for_scale=[Ar_a_for_scale;Ar];endend
endAr_a_for_scale=mean(Ar_a_for_scale);Le_a_for_scale=mean(Le_a_for_scale);Ar_a=[Ar_a;Ar_a_for_scale];Le_a=[Le_a;Le_a_for_scale];%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    Affine
%combined(affine) transformation,angles range form -30°to -30°;x,y from 
%0.8 to 1.2,at 0.1 apart,y from 0.8 to 1.2,at 0.1 apart,excluding x=y
toppoints=[]; 
Le_a_for_affine=[];
Ar_a_for_affine=[];angle_array=[-30 -20 -10 10 20 30 ];
for i=1:6angle=angle_array(i);for scale_x=0.8:0.1:1.2for scale_y=0.8:0.1:1.2if abs(scale_x-scale_y)>1e-3if scale_x~=1 ||scale_y~=1 filename=strcat(num2str(cnt),'_a_',num2str(angle),'_',num2str(scale_x),'_',num2str(scale_y),'.txt');T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);fr=imrotate(f,angle);fu= imtransform(fr,T);[filerorigin_change1,toppoints]=rotation_coordinate_change(filerorigin,f,fr,angle);filerorigin_change2=nonuniform_coordinate_change(filerorigin_change1,scale_x,scale_y);if isempty(toppoints)==0toppoints=floor(toppoints.*repmat([scale_y scale_x],[size(toppoints,1),1]));end[Ar,Le]=calculate(filename,filerorigin_change2,toppoints);Le_a_for_affine=[Le_a_for_affine;Le];Ar_a_for_affine=[Ar_a_for_affine;Ar];endendendend
endAr_a_for_affine=mean(Ar_a_for_affine);Le_a_for_affine=mean(Le_a_for_affine);Ar_a=[Ar_a;Ar_a_for_affine];Le_a=[Le_a;Le_a_for_affine];% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jpeg
%Jpeg lossy compression ,quality factors range from 5 to 100,at 5 apart
toppoints=[];
Le_a_for_compression=[];
Ar_a_for_compression=[];for quality_factor=5:5:100
%     quality_factor
%     thresh = graythresh(f);%自动确定阈值
%     fuu=im2bw(f,thresh);filename=strcat(num2str(cnt),'_j_',num2str(quality_factor),'.txt');%     imwrite(fuu,'a_compression.jpg','Quality',quality_factor,'mode','lossy');
%     fc=imread('a_compression.jpg');[Ar,Le]=calculate(filename,filerorigin,toppoints);Le_a_for_compression=[Le_a_for_compression;Le];Ar_a_for_compression=[Ar_a_for_compression;Ar];
endAr_a_for_compression=mean(Ar_a_for_compression);Le_a_for_compression=mean(Le_a_for_compression);Ar_a=[Ar_a;Ar_a_for_compression];Le_a=[Le_a;Le_a_for_compression];%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   Gaussian
%gaussian white noise, range from0.005 to 0.05,at 0.005 apart
toppoints=[];
Le_a_for_noise=[];Ar_a_for_noise=[];
for noise=0.005:0.005:0.05filename=strcat(num2str(cnt),'_n_',num2str(noise),'.txt')%     f=f.*255;
%     fi=imnoise(f,'Gaussian',noise);[Ar,Le]=calculate(filename,filerorigin,toppoints);Le_a_for_noise=[Le_a_for_noise;Le];Ar_a_for_noise=[Ar_a_for_noise;Ar];endAr_a_for_noise=mean(Ar_a_for_noise);Le_a_for_noise=mean(Le_a_for_noise);Ar_a=[Ar_a;Ar_a_for_noise];Le_a=[Le_a;Le_a_for_noise];Ar_a=Ar_aLe_a=Le_aResult=[Result;Ar_a];Result=[Result;Le_a];Result=[Result;ResultCol];endpathname=strcat('result/','repeate_superpoint_');% mkdir(pathname);
filename=strcat(datestr(now,'ddmmmyyyyHHMMSS'),'.xlsx');
outputname=strcat(pathname,filename);  
xlswrite(outputname,Result);function [coord]=getCoord(filename)fid = fopen(filename,'r');formatSpec = '%f\t%f';sizeA = [2 Inf];A = fscanf(fid,formatSpec,sizeA);
%      A([1, 2],: ) =  A([2, 1],: );
%    A= fopen(fid,formatSpec,sizeA);fclose(fid);a_first=A';   %需要转置coord=a_first;function [corners,toppoints]=rotation_coordinate_change(corners,image_or,image_ch,angle)
if size(image_or,3)==3% Transform RGB image to a Gray one.image_or=rgb2gray(image_or);
endif size(image_ch,3)==3% Transform RGB image to a Gray one.image_ch=rgb2gray(image_ch);
end
if isempty(corners)==0theta=-angle*pi/180;[cyo,cxo]=size(image_or);[cy_ro,cx_ro]=size(image_ch);tp1=[1 1];tp2=[1 cyo];tp3=[cxo 1];tp4=[cxo cyo];xo=corners(:,2);yo=corners(:,1);corners=[tp1;tp2;tp3;tp4;xo yo];corners_change_axis=corners.*repmat([1 -1],[size(corners,1),1])+repmat([-cxo/2 cyo/2],[size(corners,1),1]);corners_rotate=corners_change_axis*[cos(theta) -sin(theta);sin(theta) cos(theta)];corners_restore=corners_rotate.*repmat([1 -1],[size(corners_rotate,1),1])+repmat([cx_ro/2 cy_ro/2],[size(corners_rotate,1),1]);corners_restore=floor(corners_restore);corners=[corners_restore(:,2) corners_restore(:,1)];toppoints=corners(1:4,:);corners=corners(5:size(corners,1),:);
elsecorners=[];toppoints=[];
end%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%change the standard corners' coordinate when the images transformed with
%%uniform or nonuniform scaling
function [corners]=nonuniform_coordinate_change(corners,scale_x,scale_y)
if isempty(corners)==0corners=floor(corners.*repmat([scale_y scale_x],[size(corners,1),1]));
elsecorners=[];
end%%%%%%%%%%%%%%%%%检测到的角点和gt比较%%%%%%%%%%%%%%%%%%
function [filtercorners]=filter_origion(corners,cor_first)original_cor=corners; size_first=size(cor_first,1);size_corners=size(corners,1);
%   filter_origion_corners=[];No=size_first;Nt=size(corners,1);Nr=0;Nf=0;Nm=0;mark=[];miss=[];filtercorners=[];false_corners=corners;if isempty(corners)==0for i=1:size_firstcompare_first_corner=corners-ones(size_corners,1)*cor_first(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=9);if size(mark,1)==0Nm=Nm+1;miss=[miss;cor_first(i,:)];elsefiltercorners=[filtercorners;cor_first(i,:)];corners(find(compare_first_corner==min(compare_first_corner)),:)=0false_corners(find(compare_first_corner==min(compare_first_corner)),:)=0Nr =Nr+1;endendmiss=miss;false_corners=false_corners;%     filtercorners1=original_cor-false_corners
%     indexzero= all(filtercorners1~=0,2)
%      indexnozero=find(indexzero)
%      filtercorners=[filtercorners;filtercorners1(indexnozero,:)]Nf=Nt-Nr;  elseNm=size_first;Nr=0;Nf=0;end
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%filename:变换图片检测的坐标
%cor_first:原图检测坐标进行相应变换
%toppoints:旋转后出现的四个角坐标
function [Ar,Le]=calculate(filename,change_corners,toppoints)
[detect_corners]=getCoord(filename);%%%%%%%this can be replaced by other corner detectors
if size(detect_corners,1)>0
detect_corners(:,[1, 2] ) =  detect_corners(:,[2, 1] );
% imgfilename=filename;
% imgfilename(size(imgfilename,2)-3:size(imgfilename,2))='.jpg';
% figure;imshow(imgfilename);
% hold on;
% plot(corners(:,2),corners(:,1),'r*');
% [corners]=FilterCorner(corners,toppoints);
% figure;imshow(imgfilename); hold on; plot(corners(:,2),corners(:,1),'b*');detect_corners2=detect_corners;size_change=size(change_corners,1);size_detect=size(detect_corners,1);Nc=size_change;Nd=size(detect_corners,1);Nr=0;Ar=0;Le=0;% mark=[];% miss=[];% false_corners=detect_corners;%% match first level cornersif isempty(detect_corners)==0for i=1:size_changecompare_first_corner=detect_corners-ones(size_detect,1)*change_corners(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)==0%             Nm=Nm+1;%             miss=[miss;change_corners(i,:)];
%                      Nr=0;
%                      Le=0;elsedetect_corners(find(compare_first_corner==min(compare_first_corner)),:)=0;Nr =Nr+1;Le=Le+min(compare_first_corner);endend%%if isempty(toppoints)==0for i=1:4compare_first_corner=detect_corners2-ones(size_detect,1)*toppoints(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)~=0Nd=Nd-size(mark,1);endendend    %%
%     Le=sqrt(Le/Nd);   
%     Ar=Nr/2*(1/Nc+1/Nd);if Nd~=0Le=sqrt(Le/Nd);  elseLe=0;endif Nc==0Ar=Nr/2*(1/Nd);elseif Nd==0Ar=Nr/2*(1/Nc); elseAr=Nr/2*(1/Nc+1/Nd);endelseLe=0;Ar=0;endelseLe=0;Ar=0;
endfunction [corner]=FilterCorner(oldcorner,toppoints)
%corners中有部分坐标是由于旋转后边缘检测的,需要删除
new_c=[];
if isempty(toppoints)==0dist=15;for i=1:size(oldcorner,1)P=oldcorner(i,:)';%line1Q1=toppoints(1,:)';Q2=toppoints(2,:)';d1=abs(det([Q2-Q1,P-Q1]))/norm(Q2-Q1);%line2Q1=toppoints(1,:)';Q2=toppoints(2,:)';d2=abs(det([Q2-Q1,P-Q1]))/norm(Q2-Q1);%line3Q1=toppoints(1,:)';Q2=toppoints(2,:)';d3=abs(det([Q2-Q1,P-Q1]))/norm(Q2-Q1);%line4Q1=toppoints(1,:)';Q2=toppoints(2,:)';d4=abs(det([Q2-Q1,P-Q1]))/norm(Q2-Q1);if(d1>dist&&d2>dist&&d3>dist&&d4>dist)new_c=[new_c;oldcorner(i,:)];continue;endendcorner=new_c;
elsecorner=oldcorner;end

基于。。的可重复率不是读取文件的

function Result=Comparison_weae()close allclcticResult=[];for cnt =1:21cntldpath = sprintf('%d.png',cnt);f=imread(ldpath);f=rgb2gray(f);s = ['load(''' int2str(cnt) '.mat'')'];a=eval(s);a_first=a.first;[original_corners1]=weae_g(f);  %获得原始图片的角点original_corners= filter_origion(original_corners1,a_first);%             figure(1);
%             imshow(f);
%             hold on;
%             plot(a_first(:,2), a_first(:,1),'ro','MarkerSize',2,'MarkerFaceColor','r');
%             
%             
%              figure(2);
%              imshow(f);
%             hold on;
%             plot(original_corners1(:,2), original_corners1(:,1),'ro','MarkerSize',2,'MarkerFaceColor','r');
%             
%            original_corners1= filter_origion(original_corners,a_first)
%            figure(3);
%             imshow(f);
%             hold on;
%             plot(original_corners(:,2), original_corners(:,1),'ro','MarkerSize',2,'MarkerFaceColor','r');Ar_a=[];Le_a=[];%% 旋转%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 旋转%rotation transformation,from -90°to 90°,at 10° apart,excluding 0°toppoints=[];Le_a_for_rotation=[];                                 %存放图片旋转后的定位误差Ar_a_for_rotation=[];                                 %存放图片旋转后的平均重复率for angle=0fr=imrotate(f,angle);%[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];endfor angle=-90:10:-10fr=imrotate(f,angle);[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];endfor angle=10:10:90fr=imrotate(f,angle);[change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);[Ar,Le]=calculate(fr,change_corners,toppoints);Ar_a_for_rotation=[Ar_a_for_rotation;Ar];Le_a_for_rotation=[Le_a_for_rotation;Le];end  Ar_a_for_rotation=mean(Ar_a_for_rotation);             %平均Le_a_for_rotation=mean(Le_a_for_rotation);Ar_a=[Ar_a;Ar_a_for_rotation];Le_a=[Le_a;Le_a_for_rotation];%% 旋转End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 旋转End%% 比例%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 比例%%uniform and nonuniform scaling transformation,x from 0.5 to 2.0,at 0.1 apart,y from 0.5 toppoints=[];Ar_a_for_scale=[];Le_a_for_scale=[];for scale_x=0.5:0.1:2.0for scale_y=0.5:0.1:2.0if scale_x~=1 ||scale_y~=1 T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);fu= imtransform(f,T);a_first_change=nonuniform_coordinate_change(original_corners,scale_x,scale_y);[Ar,Le]=calculate(fu,a_first_change,toppoints);Le_a_for_scale=[Le_a_for_scale;Le];Ar_a_for_scale=[Ar_a_for_scale;Ar];endendendAr_a_for_scale=mean(Ar_a_for_scale);Le_a_for_scale=mean(Le_a_for_scale);Ar_a=[Ar_a;Ar_a_for_scale];Le_a=[Le_a;Le_a_for_scale];%% 比例End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 比例变换End%% 仿射%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 仿射%combined(affine) transformation,angles range form -30°to -30°;x,y from %0.8 to 1.2,at 0.1 apart,y from 0.8 to 1.2,at 0.1 apart,excluding x=ytoppoints=[]; Le_a_for_affine=[];Ar_a_for_affine=[];angle_array=[-30 -20 -10 10 20 30 ];for i=1:6angle=angle_array(i);for scale_x=0.8:0.1:1.2for scale_y=0.8:0.1:1.2if abs(scale_x-scale_y)>1e-3if scale_x~=1 ||scale_y~=1 T = maketform('affine',[scale_x 0 0; 0 scale_y 0; 0 0 1]);fr=imrotate(f,angle);fu= imtransform(fr,T);[a_first_change1,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);a_first_change2=nonuniform_coordinate_change(a_first_change1,scale_x,scale_y);if isempty(toppoints)==0toppoints=floor(toppoints.*repmat([scale_y scale_x],[size(toppoints,1),1]));end[Ar,Le]=calculate(fu,a_first_change2,toppoints);Le_a_for_affine=[Le_a_for_affine;Le];rAr_a_for_affine=[Ar_a_for_affine;Ar];endendendendendAr_a_for_affine=mean(Ar_a_for_affine);Le_a_for_affine=mean(Le_a_for_affine);Ar_a=[Ar_a;Ar_a_for_affine];Le_a=[Le_a;Le_a_for_affine];%% 仿射End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 仿射变换End%% Jpeg%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jpegtoppoints=[];Le_a_for_compression=[];Ar_a_for_compression=[];for quality_factor=5:5:100imwrite(f,'a_compression.jpg','Quality',quality_factor,'mode','lossy');fc=imread('a_compression.jpg');[Ar,Le]=calculate(fc,original_corners,toppoints);Le_a_for_compression=[Le_a_for_compression;Le];Ar_a_for_compression=[Ar_a_for_compression;Ar];endAr_a_for_compression=mean(Ar_a_for_compression);Le_a_for_compression=mean(Le_a_for_compression);Ar_a=[Ar_a;Ar_a_for_compression];Le_a=[Le_a;Le_a_for_compression];%% JpegEnd%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% JpegEnd%% 高斯噪声%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 高斯噪声toppoints=[];Le_a_for_noise=[];Ar_a_for_noise=[];for noise=0.005:0.005:0.05fi=imnoise(f,'Gaussian',noise);[Ar,Le]=calculate(fi,original_corners,toppoints);Le_a_for_noise=[Le_a_for_noise;Le];Ar_a_for_noise=[Ar_a_for_noise;Ar];endAr_a_for_noise=mean(Ar_a_for_noise);Le_a_for_noise=mean(Le_a_for_noise);Ar_a=[Ar_a;Ar_a_for_noise];Le_a=[Le_a;Le_a_for_noise];Ar_a=Ar_aLe_a=Le_aResult=[Result;Ar_a];Result=[Result;Le_a];%% 高斯噪声End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 高斯噪声Endend % end cnt =1:12xlswrite('result/ccn_result_sum_weae-1-21.xlsx',Result);toc
end%本函数为图片旋转后,GT角点应该也响应旋转
%In:
%corners:Ground Truth为原来角点
%image_or为原始图片
%image_ch为旋转后的图片
%angele为图片旋转后的角度%Out:
%corners:function [corners,toppoints]=rotation_coordinate_change(corners,image_or,image_ch,angle)if isempty(corners)==0theta=-angle*pi/180;[cyo,cxo]=size(image_or);[cy_ro,cx_ro]=size(image_ch);tp1=[1 1];tp2=[1 cyo];tp3=[cxo 1];tp4=[cxo cyo];xo=corners(:,2);yo=corners(:,1);corners=[tp1;tp2;tp3;tp4;xo yo];corners_change_axis=corners.*repmat([1 -1],[size(corners,1),1])+repmat([-cxo/2 cyo/2],[size(corners,1),1]);corners_rotate=corners_change_axis*[cos(theta) -sin(theta);sin(theta) cos(theta)];corners_restore=corners_rotate.*repmat([1 -1],[size(corners_rotate,1),1])+repmat([cx_ro/2 cy_ro/2],[size(corners_rotate,1),1]);corners_restore=floor(corners_restore);corners=[corners_restore(:,2) corners_restore(:,1)];toppoints=corners(1:4,:);corners=corners(5:size(corners,1),:);elsecorners=[];toppoints=[];end
end
%%%%%%%%%%%%%%%%%检测到的角点和gt比较%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%检测到的角点和gt比较%%%%%%%%%%%%%%%%%%
function [filtercorners]=filter_origion(corners,cor_first)original_cor=corners; size_first=size(cor_first,1);size_corners=size(corners,1);
%   filter_origion_corners=[];No=size_first;Nt=size(corners,1);Nr=0;Nf=0;Nm=0;mark=[];miss=[];filtercorners=[];false_corners=corners;if isempty(corners)==0for i=1:size_firstcompare_first_corner=corners-ones(size_corners,1)*cor_first(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=9);if size(mark,1)==0Nm=Nm+1;miss=[miss;cor_first(i,:)];elsefiltercorners=[filtercorners;cor_first(i,:)];corners(find(compare_first_corner==min(compare_first_corner)),:)=0false_corners(find(compare_first_corner==min(compare_first_corner)),:)=0Nr =Nr+1;endendmiss=miss;false_corners=false_corners;%     filtercorners1=original_cor-false_corners
%     indexzero= all(filtercorners1~=0,2)
%      indexnozero=find(indexzero)
%      filtercorners=[filtercorners;filtercorners1(indexnozero,:)]Nf=Nt-Nr;  elseNm=size_first;Nr=0;Nf=0;end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Ar,Le]=calculate(f,change_corners,toppoints)[detect_corners]=weae_g(f);detect_corners2=detect_corners;size_change=size(change_corners,1);size_detect=size(detect_corners,1);Nc=size_change;Nd=size(detect_corners,1);Nr=0;Ar=0;Le=0;% mark=[];% miss=[];% false_corners=detect_corners;%% match first level cornersif isempty(detect_corners)==0for i=1:size_changecompare_first_corner=detect_corners-ones(size_detect,1)*change_corners(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)==0%             Nm=Nm+1;%             miss=[miss;change_corners(i,:)];
%                      Nr=0;
%                      Le=0;elsedetect_corners(find(compare_first_corner==min(compare_first_corner)),:)=0;Nr =Nr+1;Le=Le+min(compare_first_corner);endend%%if isempty(toppoints)==0for i=1:4compare_first_corner=detect_corners2-ones(size_detect,1)*toppoints(i,:);compare_first_corner=compare_first_corner.^2;compare_first_corner=compare_first_corner(:,1)+compare_first_corner(:,2);mark=find(compare_first_corner<=18);if size(mark,1)~=0Nd=Nd-size(mark,1);endendend    %%
%     Le=sqrt(Le/Nd);   
%     Ar=Nr/2*(1/Nc+1/Nd);if Nd~=0Le=sqrt(Le/Nd);  elseLe=0;endif Nc==0Ar=Nr/2*(1/Nd);elseif Nd==0Ar=Nr/2*(1/Nc); elseAr=Nr/2*(1/Nc+1/Nd);endelseLe=0;Ar=0;endend%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%change the standard corners' coordinate when the images transformed with
%%uniform or nonuniform scaling
function [corners]=nonuniform_coordinate_change(corners,scale_x,scale_y)if isempty(corners)==0corners=floor(corners.*repmat([scale_y scale_x],[size(corners,1),1]));elsecorners=[];end
end

更多推荐

角点测评可重复率函数原始

本文发布于:2024-02-25 12:40:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1698996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   原始

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!