• 只筛选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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159

    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,:)];
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    % 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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    % 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    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

  • 相关阅读:
    数据结构之顺序表
    JAVA线程池
    MySQL特殊字符处理方式
    csdn_export_md
    【OpenCV入门】第九部分——模板匹配
    Sketch 98 中文版-mac矢量绘图设计
    【毕业设计】基于java+SSH+jsp的网上体育商城设计与实现(毕业论文+程序源码)——网上体育商城
    SoftPlc on docker 测试
    什么是电商云仓储?
    【Spring】Spring学习入门案例
  • 原文地址:https://blog.csdn.net/ZYYYYYYY123/article/details/125608341