Understanding Homography in Computer Vision

Homography
KH wong
Homography 220218a
1
Introduction
Map one set of planar 3D points to another plane
Ref
https://medium.com/all-things-about-robotics-
and-computer-vision/homography-and-how-to-
calculate-it-8abf3a13ddc5
https://www.uio.no/studier/emner/matnat/its/TEK5030/v1
9/lect/lecture_4_3-estimating-homographies-from-
feature-correspondences.pdf
Homography 220218a
2
Define the problem
H=homography, 2 examples
Homography 220218a
3
x1
x2
A planar surface mapped to two images
Equation
Homography 220218a
4
x1
x2
Planar object
Point X on
Plane X
Alternatively
Homography 220218a
5
x1
x2
Planar object
Point X on
Plane X
Demo1: Matlab test (assume no noise)
for noisy images, use
https://www.mathworks.com/matlabcentral/fi
leexchange/28760-2d-2d-projective-
homography-3x3-estimation 
%homography, khw 2022.2.18, assume no noise, for noisy images
%for noisy images, use https://www.mathworks.com/matlabcentral/fileexchange/28760-2d-2d-projective-homography-3x3-estimation
function
 homography_demo()
% https://www.uio.no/studier/emner/matnat/its/TEK5030/v19/lect/lecture_4_3-estimating-homographies-from-feature-correspondences.pdf
clc
close 
all
clear
pwm=5*(10^-6) 
%5um = Pixel Width in Meter
%pwm=1;
f=1000; 
%focal length in pixel
anx=20*pi/180,any=10*pi/180,anz=8*pi/180 
%extrsinc cam rotation , in radian
T1=[0,0,0]'/pwm; 
%T1 is at reference position
T2=[0.005, 0.01, 0.0025]'/pwm; 
%a 3D plane projected to two images
ox=1000;oy=1000;
kint=[f 0 ox; 0 f oy ; 0 0 1];
%intrinsic cam parameters
R1=rpyMat([0,0,0]); 
%R1 is at reference position
R2=rpyMat([anx,any,anz]);
kext1=[R1 T1]
kext2=[R2 T2]
%%% gen 3D points
N=10
zz=0.6; 
%Z depth of the obejct center
obj=[rand(2,N);zeros(1,N)] +repmat([0,0,zz]',1,N);
%plannar,centered(0,0,zz)
%obj=[rand(3,N)] +repmat([0,0,zz]',1,N) ;% non-plannar; not for  homography
p=[obj/pwm;ones(1,N)] 
%becomes pixels,add last row 1, make homogenous corrd
figure(3)
clf
plot3(p(1,:),p(2,:),p(3,:),
'+'
)
x1=kint*kext1*p
x2=kint*kext2*p
u1=x1(1,:)./x1(3,:)
v1=x1(2,:)./x1(3,:)
w1=x1(3,:)
u2=x2(1,:)./x2(3,:)
v2=x2(2,:)./x2(3,:)
w2=x2(3,:)
figure(1)
clf
subplot(2,2,1)
plot(u1,v1,
'+'
);
xlabel(
'left image'
)
subplot(2,2,2)
plot(u2,v2,
'o'
);
xlabel(
'right image'
)
%form A matrix fro DLT programming
for
 i=1:2:N
    A(i,:)=  [0 0 0 -u1(i) -v1(i) -1 v2(i)*u1(i) v2(i)*v1(i) v2(i)];
    A(i+1,:)=[u1(i) v1(i) 1 0 0 0 -u2(i)*u1(i) -u2(i)*v1(i) -u2(i)];
end
size(A)
[u,s,v]=svd(A)
h=v(:,end) 
%last column of v
%h=v(:,4) %last column of v
err=A*h 
% shoudl be very small , =9x1 zeros, they should be zeros
H=reshape(h,3,3)'; 
%need to transpose because MATLAB reshape is row first
uv2_homo=H*[u1;v1;ones(1,N)] 
%map from image 1 to image2
u2_cal=uv2_homo(1,:)./uv2_homo(3,:)
% from homogenous coord. to pixel
v2_cal=uv2_homo(2,:)./uv2_homo(3,:)
u2-u2_cal 
%should be 0
v2-v2_cal 
%should be 0
'finished'
% Author: Rodrigo Carceroni
% Disclaimer: This code comes with no guarantee at all and its author
%   is not liable for any damage that its utilization may cause.
%khw added 3.3002 , input angs is a 1x3 matrix,
%    angs(1) is yaw   angle about x-axis
%    angs(2) is pitch angle about y-aixs
%    angs(3) is roll  angle about z-axis
%then X'=RX+T; X,T are 3X1 matrixes for [X,Y,Z]' 3D corrd. and translations.
function
 R = rpyMat (angs)
% Return the 3x3 rotation matrix described by a set of Roll, Pitch and Yaw
% angles.
cosA = cos (angs(3));
sinA = sin (angs(3));
cosB = cos (angs(2));
sinB = sin (angs(2));
cosC = cos (angs(1));
sinC = sin (angs(1));
cosAsinB = cosA .* sinB;
sinAsinB = sinA .* sinB;
R = [ cosA.*cosB  cosAsinB.*sinC-sinA.*cosC  cosAsinB.*cosC+sinA.*sinC ;
    sinA.*cosB  sinAsinB.*sinC+cosA.*cosC  sinAsinB.*cosC-cosA.*sinC ;
    -sinB            cosB.*sinC                 cosB.*cosC         ];
Homography 220218a
6
Application: merge 2 images
Take 2 images of a planar surface from different views, some parts are overlapped
Homography 220218a
7
Warp image using H
Step1: Find 4 or more
point-correspondences
(use sift or hand click)
between image 1 and 2
Step2: find H
Step3: map (wrap) image2
to image 1 coordinates
using H and merge them
An example of Point-correspondence
Demo2
http://www.cse.cuhk.edu.hk/~khwong/www2/cmsc5711/homography_file_x2.zip
see readme inside for user manual
Image 1 are2 are taken
by user
Use image1 and image2
to find Homography H
[su2;sv2;s]=H*[u1,v1,1]
Blue points are mapped
to red points
Mapped from pixels of
image 1 by H*[u1;v1;1]
Inspection: image 3 is
similar to image2
Homography 220218a
8
Image 1:Pixels are [u1;v1]
Image2: Pixels are [u2;v2]
Homography H
H*[u1;v1;1]
Image3: mapped from image1
Conclusion
Studied the basic principle of plane-to-plane
homography mapping
Studied a program that can achieve homography
mapping
Homography 220218a
9
Slide Note
Embed
Share

Homography is a fundamental concept in computer vision that involves mapping points from one plane to another. It helps in scenarios like image stitching and object recognition. This content covers the definition of homography, equations, practical examples, and tools for implementation such as MATLAB demos. Explore the importance of homography and its applications in transforming planar points between images.


Uploaded on Aug 23, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Homography KH wong Homography 220218a 1

  2. Introduction Map one set of planar 3D points to another plane Ref https://medium.com/all-things-about-robotics- and-computer-vision/homography-and-how-to- calculate-it-8abf3a13ddc5 https://www.uio.no/studier/emner/matnat/its/TEK5030/v1 9/lect/lecture_4_3-estimating-homographies-from- feature-correspondences.pdf Homography 220218a 2

  3. Define the problem H=homography, 2 examples x2 x1 A planar surface mapped to two images Homography 220218a 3

  4. Equation ?1 ?1 1 ?2 ?2 1 ?1 = , ?2 = x2 x1 1 4 7 2 5 8 3 6 9 Planar object Point X on Plane X H = ?1,?2 ??? ????????? ????? ????? in homogenous coordinates ? ?2 ? ?2 ? ?1 ?1 1 1 4 7 2 5 8 3 6 9 = , assume s=1 ?2= ?1* 1 + ?1 2 + 3 ?2= ?1* 4 + ?1 5 + 6 1= ?1* 7 + ?1 8 + 9 , rearrange terms, write in matrix form 0 ?1 ?2 ?1 ?2 ?1 ?2 ?2 ?1 1, 2, 3, 4, 5, 6, 7, 8, 9 =[ 0,0,0] 0 ?1 0 1 ?1 0 ?1 0 ?2 ?1 1 0 ?2 ?2 ?1 ?2 ?1 0 ?2 ?1 ?2 ?1 0 ?2 ?2 0 Homography 220218a 4

  5. Alternatively ?1 ?1 1 ?2 ?2 1 ?1 = , ?2 = x2 x1 11 21 31 12 22 32 13 23 33 Planar object Point X on Plane X H = ? ?2 ? ?2 ? ?1 ?1 1 1 4 7 2 5 8 3 6 9 ?1,?2 ??? ????????? ????? ????? in homogenous coordinates = Eliminate s, we can get ?(? ?) (9 1)= 0, for i=1,3,5,..N-1, total N feature points where 2 row pairs for each i are for i=1:2:N A(i,:)= [0 0 0 -u1(i) -v1(i) -1 v2(i)*u1(i) v2(i)*v1(i) v2(i)]; A(i+1,:)=[u1(i) v1(i) 1 0 0 0 -u2(i)*u1(i) -u2(i)*v1(i) -u2(i)]; end = 1, 2, 3, 4, 5, 6, 7, 8, 9? To recover u2,v2, use u2=(s*u2)/s and v2=(s*v2)/s Homography 220218a 5

  6. Demo1: Matlab test (assume no noise) for noisy images, use https://www.mathworks.com/matlabcentral/fi leexchange/28760-2d-2d-projective- homography-3x3-estimation %homography, khw 2022.2.18, assume no noise, for noisy images %for noisy images, use https://www.mathworks.com/matlabcentral/fileexchange/28760-2d-2d-projective-homography-3x3-estimation function homography_demo() % https://www.uio.no/studier/emner/matnat/its/TEK5030/v19/lect/lecture_4_3-estimating-homographies-from-feature-correspondences.pdf clc close all clear pwm=5*(10^-6) %5um = Pixel Width in Meter %pwm=1; f=1000; %focal length in pixel anx=20*pi/180,any=10*pi/180,anz=8*pi/180 %extrsinc cam rotation , in radian T1=[0,0,0]'/pwm; %T1 is at reference position T2=[0.005, 0.01, 0.0025]'/pwm; %a 3D plane projected to two images ox=1000;oy=1000; kint=[f 0 ox; 0 f oy ; 0 0 1];%intrinsic cam parameters R1=rpyMat([0,0,0]); %R1 is at reference position R2=rpyMat([anx,any,anz]); kext1=[R1 T1] kext2=[R2 T2] %%% gen 3D points N=10 zz=0.6; %Z depth of the obejct center Homography 220218a 6 obj=[rand(2,N);zeros(1,N)] +repmat([0,0,zz]',1,N);%plannar,centered(0,0,zz) %obj=[rand(3,N)] +repmat([0,0,zz]',1,N) ;% non-plannar; not for homography

  7. Application: merge 2 images Take 2 images of a planar surface from different views, some parts are overlapped An example of Point-correspondence Step1: Find 4 or more point-correspondences (use sift or hand click) between image 1 and 2 Step2: find H Step3: map (wrap) image2 to image 1 coordinates using H and merge them Warp image using H Homography 220218a 7

  8. Demo2 http://www.cse.cuhk.edu.hk/~khwong/www2/cmsc5711/homography_file_x2.zip see readme inside for user manual Homography H Image 1 are2 are taken by user Use image1 and image2 to find Homography H [su2;sv2;s]=H*[u1,v1,1] Blue points are mapped to red points Mapped from pixels of image 1 by H*[u1;v1;1] Inspection: image 3 is similar to image2 Image 1:Pixels are [u1;v1] Image2: Pixels are [u2;v2] H*[u1;v1;1] Image3: mapped from image1 Homography 220218a 8

  9. Conclusion Studied the basic principle of plane-to-plane homography mapping Studied a program that can achieve homography mapping Homography 220218a 9

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#