只筛选nr

E:\graduate-experience\version2可重复性测评0930 - 副本\可重复性测评\0827sumerizeCornertest\01Algorithm\gcm

function Result=Comparison_cpda()
close all
clc
tic
Result=[];
for cnt =1:21
cnt
ldpath = sprintf(‘%d.png’,cnt);
f=imread(ldpath);
f=rgb2gray(f);
s = [‘load(’‘’ int2str(cnt) ‘.mat’‘)’];
a=eval(s);
a_first=a.first;
original_corners=GCMDetector(f); %获得原始图片的角点

% 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=0
            fr=imrotate(f,angle);
            %
            [change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);
            [change_afirst,toppoints]=rotation_coordinate_change( a_first,f,fr,angle);
            [Ar,Le]=calculate(fr,change_corners,change_afirst,toppoints);
            
            Ar_a_for_rotation=[Ar_a_for_rotation;Ar];
            Le_a_for_rotation=[Le_a_for_rotation;Le];
        end
        for angle=-90:10:-10
            fr=imrotate(f,angle);
            [change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);
            [change_afirst,toppoints]=rotation_coordinate_change( a_first,f,fr,angle);
            [Ar,Le]=calculate(fr,change_corners,change_afirst,toppoints);
            
            Ar_a_for_rotation=[Ar_a_for_rotation;Ar];
            Le_a_for_rotation=[Le_a_for_rotation;Le];
        end
        for angle=10:10:90
            fr=imrotate(f,angle);
            [change_corners,toppoints]=rotation_coordinate_change(original_corners,f,fr,angle);
            [change_afirst,toppoints]=rotation_coordinate_change( a_first,f,fr,angle);
            [Ar,Le]=calculate(fr,change_corners,change_afirst,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.0
            for scale_y=0.5:0.1:2.0
                if 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);
                    change_afirst=nonuniform_coordinate_change( a_first,scale_x,scale_y);
                    [Ar,Le]=calculate(fu,a_first_change,change_afirst,toppoints);
                    Le_a_for_scale=[Le_a_for_scale;Le];
                    Ar_a_for_scale=[Ar_a_for_scale;Ar];
                end
            end
        end
        Ar_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=y
        toppoints=[]; 
        Le_a_for_affine=[];
        Ar_a_for_affine=[];
        angle_array=[-30 -20 -10 10 20 30 ];
        for i=1:6
            angle=angle_array(i);
            for scale_x=0.8:0.1:1.2
                for scale_y=0.8:0.1:1.2
                    if abs(scale_x-scale_y)>1e-3
                        if 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);
                            [change_afirst1,toppoints]=rotation_coordinate_change(a_first,f,fr,angle);
                            change_afirst2=nonuniform_coordinate_change(change_afirst1,scale_x,scale_y);
                            if isempty(toppoints)==0
                            toppoints=floor(toppoints.*repmat([scale_y scale_x],[size(toppoints,1),1]));
                            end
                            [Ar,Le]=calculate(fu,a_first_change2,change_afirst2,toppoints);
                            Le_a_for_affine=[Le_a_for_affine;Le];
                            Ar_a_for_affine=[Ar_a_for_affine;Ar];
                        end
                    end
                end
            end
        end

        Ar_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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jpeg
        toppoints=[];
        Le_a_for_compression=[];
        Ar_a_for_compression=[];
        for quality_factor=5:5:100
            imwrite(f,'a_compression.jpg','Quality',quality_factor,'mode','lossy');
            fc=imread('a_compression.jpg');
            [Ar,Le]=calculate(fc,original_corners,a_first,toppoints);
            Le_a_for_compression=[Le_a_for_compression;Le];
            Ar_a_for_compression=[Ar_a_for_compression;Ar];
        end

        Ar_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.05
            fi=imnoise(f,'Gaussian',noise);
            [Ar,Le]=calculate(fi,original_corners,a_first,toppoints);
            Le_a_for_noise=[Le_a_for_noise;Le];
            Ar_a_for_noise=[Ar_a_for_noise;Ar];
        end

        Ar_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_a
        Le_a=Le_a
        
        Result=[Result;Ar_a];
        Result=[Result;Le_a];

        %% 高斯噪声End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 高斯噪声End
end % end cnt =1:12
xlswrite('result/ccn_result_gcm1-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)==0
theta=-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)😅;
else
corners=[];
toppoints=[];
end
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)0
for i=1:size_first
compare_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)0
Nm=Nm+1;
miss=[miss;cor_first(i,:)];
else
filtercorners=[filtercorners;cor_first(i,:)];
corners(find(compare_first_corner
min(compare_first_corner)),:)=0;
false_corners(find(compare_first_corner
min(compare_first_corner)),:)=0;
Nr =Nr+1;
end
end
miss=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;
else
Nm=size_first;
Nr=0;
Nf=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Ar,Le]=calculate(f,change_corners,change_afirst,toppoints)
[detect_corners]=GCMDetector(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;
reapeatecorner=[];
% mark=[];
% miss=[];
% false_corners=detect_corners;
%% match first level corners
if isempty(detect_corners)==0

    for i=1:size_change
        compare_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;
else
detect_corners(find(compare_first_corner==min(compare_first_corner)),:)=0;
reapeatecorner=[reapeatecorner;change_corners(i,:)];
Nr =Nr+1;
Le=Le+min(compare_first_corner);
end
end

%%
    if isempty(toppoints)==0
        for i=1:4
        compare_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)~=0
            Nd=Nd-size(mark,1);
        end
        end
    end    
%%
filterreapeatecorner=filter_origion(reapeatecorner,change_afirst);
Nrgt=size(filterreapeatecorner,1);

% Le=sqrt(Le/Nd);
% % Ar=Nr/2*(1/Nc+1/Nd);
% Ar=Nrgt/2*(1/Nc+1/Nd);
if Nd~=0
Le=sqrt(Le/Nd);
else
Le=0;
end

    if Nc==0
        Ar=Nrgt/2*(1/Nd);
     
     elseif Nd==0
         Ar=Nrgt/2*(1/Nc); 
    else
        Ar=Nrgt/2*(1/Nc+1/Nd);
    end
else
    Le=0;
    Ar=0;
end

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)==0
corners=floor(corners.*repmat([scale_y scale_x],[size(corners,1),1]));
else
corners=[];
end
end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值