赞
踩
- clc;
- clear;
- close all;
- warning off;
- addpath 'func\'
-
- %1的话设置连线
- Feature_point = 1;
- %是否需要重新特征提取,%1:对以一组新的图片,需要选择1,对于同一组图片,直接设置0
- sel = 1;
- t = sqrt(2).^([0]);%选择不同的角度t,arccos(1/t);
-
- %读取图片
- img1 = imresize(imread('A1.jpg'),0.8);
- img2 = imresize(imread('杂草模板\B.jpg'),0.8);
-
- %转换为灰度图
- [R,C,K] = size(img1);
- if K == 3
- img1s = rgb2gray(img1);
- else
- img1s = img1;
- end
-
- [R,C,K] = size(img2);
- if K == 3
- img2s = rgb2gray(img2);
- else
- img2s = img2;
- end
-
-
- %计算图片的大小
- [m1,n1] = size(img1s);
- [m2,n2] = size(img2s);
-
- %对两个图片分别进行角度选择和不同角度的特征提取
- if sel == 1
- tic;
- disp('对图片1进行处理');
- [Hrl_feature1,Hr_pointl_feature1,cnt1]=func_sift_angle(img1s,m1,n1,t);
- Time = toc;
- disp('对图片2进行处理');
- [Hrl_feature2,Hr_pointl_feature2,cnt2]=func_sift_angle(img2s,m2,n2,t);
- save feature_data_B1.mat Hrl_feature1 Hr_pointl_feature1 Hrl_feature2 Hr_pointl_feature2 cnt1 cnt2 Time
- else
- load feature_data_B1.mat
- end
-
- %进行配准
- pp = 0;
- level = 0.7;%这个参数要根据不同的测试样本进行调整
- image_match1 = [];
- image_match2 = [];
- for i = 1:(cnt1 - 1)
- for j = 1:(cnt2 -1)
- pp = pp + 1;
- fprintf('处理进度:');fprintf('%3.2f',100*pp/(cnt1*cnt2));fprintf('%%\n\n');
- NF1(i) = size(Hrl_feature1{i},1);
- NF2(j) = size(Hrl_feature2{j},1);
- same_feature = func_feature_match(Hrl_feature1{i},Hrl_feature2{j},level);
- ind1 = find(same_feature);
- ind2 = same_feature(ind1);
- %根据门限来选择一定区域内的配准点
- ind = find(sqrt(sum(((Hrl_feature1{i}(ind1,:)-Hrl_feature2{j}(ind2,:)).^2),2)) <= level);
- ind1 = ind1(ind);
- ind2 = ind2(ind);
- Match1Tmp = Hr_pointl_feature1{i}(ind1,[ 1 2 3 end ]);
- Match2Tmp = Hr_pointl_feature2{j}(ind2,[ 1 2 3 end ]);
- image_match1 = [image_match1;Match1Tmp];
- image_match2 = [image_match2;Match2Tmp];
- end
- end
- close all;
- %显示最后处理的定位效果
- [LineCoordX,LineCoordY,N] = func_figure(img1s,image_match1,img2s,image_match2,Feature_point);
-
-
- figure;
- imshow(img1);
- hold on
- r=40;
- theta=0:pi/50:2*pi;
- for i = 1:N
- x0=LineCoordX(1,i);
- y0=LineCoordY(1,i);
- x=x0+r*cos(theta);
- y=y0+r*sin(theta);
- plot(x,y,'g-','linewidth',2);
- hold on
- end
-
-
-
-
-
A10-49
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。