harris角点检测与ncc匹配(Harris point detection
and NCC match)
harris角点检测与ncc匹配(Harris point detection and NCC match)
Harris corner detection and NCC matching
File1:----------------------------------------------------- --------------------------------- Function, [y1, Y2, R, c]=harris (X)
% corner detection using the Harris algorithm % output is an image
% [result, CNT, R, c]=harris (X) % CLC, clear all; % filename='qiao1.bmp';
% X= imread ('filename.bmp');% reads the image % Info=imfinfo (filename);%; this is customary % f=rgb2gray (X); F=X; %
Ori_im=double (f) /255;%unit8 is converted to 64 double precision double64
FX = [-2, -1 01, 2],% X direction gradient operator (for Harris corner extraction algorithm)
Ix = Filter2 (FX, ori_im);% x directional filtering is good at using filter
% FY = [5 85; 000; -5, -8, -5];% Gauss function, first order differential, Y direction (for improved Harris corner extraction algorithm)
FY = [-2; -1; 0; 1; 2];% Y direction gradient operator (used in Harris corner extraction algorithm)
Iy = Filter2 (FY, ori_im);% y directional filtering Ix2 = Ix.^2; Iy2 = Iy.^2; Ixy = Ix.*Iy; Clear Ix;
Clear Iy =% elimination variable ha
H=, fspecial ('gaussian', [10, 10], 2);% produces Gauss window functions of 7*7, sigma=2
Ix2 = Filter2 (h, Ix2); Iy2 = Filter2 (h, Iy2);
Ixy = Filter2 (h, Ixy);% Gauss filtering, respectively Height = size (ori_im, 1); Width = size (ori_im, 2);
Result = zeros (height, width);% record corner position, corner value is 1, background is black ha
R = zeros (height, width);
Rmax = 0;% the maximum R value in the image in order to set the threshold
For I = 1:height For J = 1:width
M = [Ix2 (I, J), Ixy (I, J); Ixy (I, J), Iy2 (I, J)];%2*2 matrix R (I, J) = det (M) -0.06* (trace (M)) ^2;% calculates R and obtains RMAX, which appears to be the whole, and the corner response function
If R (I, J) > Rmax Rmax = R (I, J); End; End; End;
CNT = 0;% record count For I = 2:height-1
For J = 2:width-1% carry on non maximum suppression, window 3*3 If R (I, J) > 0.01*Rmax & & R (I, J) > R (i-1, J-1) and R (I, J) > R (i-1, J) and R (I, J) > R (i-1, j+1) and R (I, J) (I, J-1 > R) and R (I, J) > R (I, j+1) and R (I, J) > R (i+1, J-1) and R (I, J) > R (I +1 J) and R (I, J) > R (i+1, j+1)
Result (I, J) = 1; CNT = cnt+1; End; End; End;
% % i=1;
% for j=1:height % for k=1:width % if result (J, K) ==1; % corners1 (I, 1) =j; % corners1 (I, 2) =k; % i=i+1; % end; % end; % end;
[posr, posc] = find (result = 1); % corner number
% imshow (ori_im)% and X have the same effect % hold on;
% plot (posr, POSC,'r.'); Y1=result; Y2=cnt;
R=posr; c=posc; Return;
File2--------------------------------------------------------------------------------------------------------------------------------
Function, res=match (A1, cnt1, R1, C1, A2, CNT2, R2, C2) % res=match (A1, A2)
% will find the best match point in A2 from A1 and get the res extracted from A2, that is, one-way search
% [result1, cnt1, R11, c11]=harris (A1); CNT2, R22, [result2%, c22]=harris
(A2);%%%%%%%%%%%%%%%%%%%%%%%%%%%% can ensure to match what is, what % figure;
% imshow (result1); title ('result1 corner position); % figure; title ('result2 corner position); % imshow (result2);
Win=[1/9 1/9 1/9; 1/9 1/9 1/9; 1/9 1/9 1/9]; U1=filter2 (win, A1);
U2=filter2 (win, A2);% for mean
Research on image registration algorithm based on point feature A1=double (A1); A2=double (A2);
A=filter2 (win, (a1-u1).^2)% for variance B=filter2 (win, (a2-u2).^2); [m1, n1]=size (A1); [m2, n2]=size (A2); Res1=zeros (M1, N1);
Res2=zeros (m2, N2);% searched for matching points For s=1:cnt1
Max=0; p=0; q=0; i=r1 (s, 1); j=c1 (s, 1);%p.q stores coordinates For v=1:cnt2