mosaics (homographies and blending)yboykov/courses/cs484/lectures/lec05_mo… · 3d sidewalk art by...

49
Mosaics (homographies and blending) Many slides from Alexei Efros, Steve Seitz, Rick Szeliski © Jeffrey Martin (jeffrey-martin.com)

Upload: others

Post on 10-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Mosaics (homographies and blending)

Many slides from

Alexei Efros, Steve Seitz, Rick Szeliski

© Jeffrey Martin (jeffrey-martin.com)

Page 2: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

Slide from Brown & Lowe

Page 3: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

• Human FOV = 200 x 135°

Slide from Brown & Lowe

Page 4: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

• Human FOV = 200 x 135°

• Panoramic Mosaic = 360 x 180°

Slide from Brown & Lowe

Page 5: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Mosaics: stitching images together

virtual wide-angle camera

Page 6: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic lens camera

image

plane lens

focal

length fassuming object distance

is very large (infinity)

the ray through lens center

is enough to find projected point

remember from lecture 2

Page 7: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic lens camera

image

plane lens

focal

length f

remember from lecture 2

assuming object distance

is very large (infinity)

Page 8: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic lens camera

image

plane lens

focal

length f

NOTE: rays from a closer 3D point form a circle of confusion on an image plane.

For simplicity, “pin hole” camera model treats such circles as dots.

remember from lecture 2

assuming object distance

is very large (infinity)

Page 9: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic camera model: “pin hole”

image

plane lenssimplified

“pin hole” model

f

remember from lecture 2

Page 10: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic camera model: “pin hole”

image

plane lenssimplified

“pin hole” model

f

“equivalent”

image plane

f

remember from lecture 2

Page 11: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Basic camera model: “pin hole”

(virtual)

image plane

camera’s

“optical center”

f

commonly used simplified representation of a pin hole camera

draws an image plane in front of the optical center

or

“viewpoint”

remember from lecture 2

Page 12: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Rotating camera around fixed viewpoint

camera direction

viewpoint

“image plane”

“image plane”

if camera is

turned

Page 13: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

A pencil of rays contains all views

real

image plane synthetic

image plane

It is possible to generate any synthetic camera view

as long as it has the same center of projection!(domain transformation defined by ray-correspondences)

Page 14: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

mosaic projection plane (PP)

Panorama: general idea (3D interpretation)

The mosaic has a natural interpretation in 3D• The images are re-projected onto a common plane

• The mosaic is formed on this plane

• Mosaic is a synthetic wide-angle camera

NOTE:

mosaic projection plane

is typically an image plane

for one of the taken photos(e.g. in the center of the panorama)

Page 15: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

How to build panorama mosaic?

Basic Iterative Procedure

• Take a sequence of images from the same position

– Rotate the camera about its optical center

• Compute transformation between second image and first

• Transform the second image to overlap with the first

• Blend the two together to create a mosaic

• If there are more images, repeat

However, general 3D geometric interpretation of panorama

mosaicing helps to understand the type of transformation

needed for image reprojection.

NOTE: knowing scene geometry is not needed to build panoramas

Page 16: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Aligning images

Translations are not enough to align the images

left on top right on top

So, what is the type of transformation needed for re-projecting images?

Page 17: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Image reprojection

Basic question• How to relate two images from the same camera center?

That is, how to map pixels from PP1 to PP2 ?

PP2

PP1

Answer 1: ray correspondence (as seen earlier)

• Cast a ray through any given pixel in PP1

• Draw the pixel where that ray intersects PP2

But don’t we need to know the positions

of the two planes w.r.t. the viewpoint?

Answer 2: rather than thinking of this

as a 3D reprojection, think of it as a 2D

image warp from one image to another.

What type of 2D image warp can represent 3D reprojections?

Page 18: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Back to Image Warping

Translation

2 unknowns

Affine

6 unknowns

Perspective

8 unknowns

Which t-form is the right one for warping PP1 into PP2?

e.g. translation, Euclidean, affine, projective ?

Page 19: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Central Projection and Homographies

Central projection: mapping between any two PPs with the

same center of projection based on ray-correspondences

• preserves straight lines (Why?)

• parallel lines aren’t (Example?) thus not affine

• rectangle should map to arbitrary quadrilateral

Since straight lines are preserved, it can be

described by a homographic transformation(remember general property of homographies from topic 4)

PP2

PP1

=

1

yx

*********

w

wy'wx'

H pp’using homogeneous representation of 2D points

w.r.t. arbitrary coordinate basis in each plane

Extra assumptions (e.g. orthogonal basis) allow to express central projection

as some transformation with d.o.f. < 8 [Heartlely and Zisserman, Sec. 2.3]

Page 20: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Image warping with homographies

image plane in front image plane below

black area

where no pixel

maps to

“down”

view

Page 21: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Image warping with homographies

image plane in front image plane below

black area

where no pixel

maps to

“down”

view

“side”

view

Page 22: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Image rectification

To unwarp (rectify) an image

• Find the homography H given a set of p and p’ pairs

• How many correspondences are needed?

• Tricky to write H analytically, but we can solve for it!

• Find such H that “best” transforms points p into p’

• Use least-squares if more than 4 point correspondences

pp’

Page 23: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Computing Homography

Consider one point-correspondence

Hpp ='

)''(')( ,, yxpyxp =→=

=

1

'

'

y

x

ihg

fed

cba

w

wy

wx

ihygx

cbyaxx

++

++='

ihygx

feydxy

++

++='

See p.35

in Hartley and

Zisserman

eliminating w = gx+hy+i :

3 equations,

but we do not

care about w

0''' =−−−++ ixhyxgxxcbyax

0''' =−−−++ iyhyygxyfeydx

Two equations linear w.r.t unknown coefficients of matrix H and

quadratic w.r.t. known point coordinates (x,y,x’,y’)

or

Page 24: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Computing Homography

Consider 4 point-correspondences

0''' =−−−++ kkkkkkk ixxhyxgxcbyax

0''' =−−−++ kkkkkkk iyyhyygxfeydx

)''(')( ,, kkkkkk yxpyxp =→=

kk Hpp ='

=

1

'

'

k

k

k

kk

kk

y

x

ihg

fed

cba

w

yw

xw

for k=1,2,3,4

Special case of

DLT method

(see p.89

in Hartley and

Zisserman)

Can solve for unknown Homography parameters

from 8 (=2x4) linear equations above plus additional assumption

},,,,,,,,{ ihgfedcba

1=i

OK if p=(0,0) maps to p’ that is not a point at infinity (Why?)

Page 25: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Fun with homographies

Virtual camera rotations

Original image

Page 26: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Panoramas

1. Pick one image (red)

2. Warp the other images towards it (usually, one by one)

3. blend

Page 27: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

changing camera center

Does it still work? synthetic PP

PP1

PP2

What

color?

is not even

visible in PP1

ray correspondences no longer work for a common PP (for a general scene)

Page 28: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Planar scene (or far away)

PP3 is a projection plane of both centers of projection,

so we are OK!

This is how big aerial photographs are made

PP1

PP3

PP2

Page 29: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Planar mosaic

Page 30: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Blending the mosaic

An example of image compositing:

the art (and sometime science) of

combining images together…

Page 31: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Feathering

01

01

+

=

Encoding transparency

I(x,y) = (aR, aG, aB, a)

αleft αright

Normally, αleft + αright = 1

Iblend = Ileft + Iright

Page 32: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Feathering

01

01

+

=

αleft αright

Page 33: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Assume images projected onto common PP

im 1 on

common

PP

im 2 on

common

PP

overlap

region

common PP

Page 34: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha: simple averaging

alpha = .5 in overlap region

im 1 on

common

PP

im 2 on

common

PP

alpha1 (for im 1)

alpha2 (for im 2)

Page 35: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha: simple averaging

alpha = .5 in overlap region

im 1 on

common

PP

im 2 on

common

PP

alpha1 (for im 1)

blended

image

Page 36: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Image feathering

Weight each image proportional to its distance from the edge

(distance map [Danielsson, CVGIP 1980]

1. Generate weight map for each image (based on distance from edge)

2. Normalize: sum up all of the weights and divide by sum:

weights sum up to 1: wi’ = wi / ( ∑i wi)

w1 w2 w3

w1’ w2’ w3’

after normalization(can be used as alphas)

common PPImage 1 Image 2 Image 3

common PPImage 1 Image 2 Image 3

Page 37: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha:

im 1 on

common

PP

im 2 on

common

PP

overlap

region

common PP

Page 38: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha:

Distance

Transforms(distance from “borders”)

overlap

region

dtrans1 dtrans2

common PP

For simplicity, compute

distances from

rectangular borders in

the original image plane

(which is trivial)

and project onto common

PP by applying the same

homography used for

mapping the image

Page 39: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha: center seam

alpha1 = logical(dtrans1>dtrans2)

dtrans1 dtrans2

alpha2 = logical(dtrans2>dtrans1)

alpha1 (for im 1)

Page 40: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha: blurred seam

alpha = blurred

dtrans1 dtrans2

alpha1 (for im 1)

Page 41: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Setting alpha: center weighting

alpha = dtrans1 / (dtrans1+dtrans2)

Ghost!

dtrans1 dtrans2

alpha1 (for im 1)

Page 42: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Programming Project

Homographies and Panoramic Mosaics

• Capture photographs (and possibly video)

• Might want to use tripod

• Compute homographies (define correspondences)

• will need to figure out how to setup system of eqs.

• (un)warp an image (undo perspective distortion)

• Produce 3 panoramic mosaics (with blending)

• Do some of the Bells and Whistles

Page 43: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Bells and Whistles

Blending and Compositing

• use homographies to combine images or video and images

together in an interesting (fun) way. E.g.

– put fake graffiti on buildings or chalk drawings on the ground

– replace a road sign with your own poster

– project a movie onto a building wall

– etc.

3D Sidewalk Art by Julian Beever (see links for more)

Page 44: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Bells and Whistles

3D Sidewalk Art by Edgar Müller

Page 45: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Bells and Whistles

3D Sidewalk Art by Edgar Müller

Page 46: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Bells and Whistles

Capture creative/cool/bizzare panoramas

• Example from UW (by Brett Allen):

Capture a 360 panorama

a bit trickier… projecting all images onto a common

“reference” cylinder or sphere, rather than a plane

Page 47: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Bells and Whistles

Video Panorama

• Capture two (or more) stationary videos (either from the

same point, or of a planar/far-away scene). Compute

homography and produce a video mosaic. Need to worry

about synchronization (not too hard).

• e.g. capturing a football game from the sides of the stadium

Other interesting ideas?

• talk to me

Page 48: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

From previous year’s classes

Eunjeong Ryu (E.J), 2004

Ben Hollis, 2004

Ben Hollis, 2004

Matt Pucevich , 2004

Page 49: Mosaics (homographies and blending)yboykov/Courses/cs484/Lectures/lec05_mo… · 3D Sidewalk Art by Julian Beever (see links for more) Bells and Whistles 3D Sidewalk Art by Edgar

Go Explore!

Ken Chu, 2004