Image Warping. August 20, Abstract

Similar documents
02501 Image analysis, vision and computer graphics Exercise 05 - Image Warping

Image Mosaicing using MATLAB

Introduction to Computer Vision

Perspective Projection [2 pts]

Computer Vision I Name : CSE 252A, Fall 2012 Student ID : David Kriegman Assignment #1. (Due date: 10/23/2012) x P. = z

Image Stitching. Slides from Rick Szeliski, Steve Seitz, Derek Hoiem, Ira Kemelmacher, Ali Farhadi

Chapter 18. Geometric Operations

CS6670: Computer Vision

Image warping , , Computational Photography Fall 2017, Lecture 10

Georeferencing & Spatial Adjustment

Motion. 1 Introduction. 2 Optical Flow. Sohaib A Khan. 2.1 Brightness Constancy Equation

N-Views (1) Homographies and Projection

Georeferencing & Spatial Adjustment 2/13/2018

The Problem. Georeferencing & Spatial Adjustment. Nature Of The Problem: For Example: Georeferencing & Spatial Adjustment 9/20/2016

Homework #4: Creating Panoramas

The Problem. Georeferencing & Spatial Adjustment. Nature of the problem: For Example: Georeferencing & Spatial Adjustment 2/4/2014

Image and Multidimensional Signal Processing

CS4670: Computer Vision

Lecture 6 Geometric Transformations and Image Registration. Lin ZHANG, PhD School of Software Engineering Tongji University Spring 2013

Blacksburg, VA July 24 th 30 th, 2010 Georeferencing images and scanned maps Page 1. Georeference

EN1610 Image Understanding Lab # 4: Corners, Interest Points, Hough Transform

calibrated coordinates Linear transformation pixel coordinates

Mosaics. Today s Readings

Brightness and geometric transformations

Image Transformations

Image warping and stitching

Image Warping and Mosacing

Warping. 12 May 2015

CS4670: Computer Vision

Image warping and stitching

3D Geometry and Camera Calibration

Video Alignment. Final Report. Spring 2005 Prof. Brian Evans Multidimensional Digital Signal Processing Project The University of Texas at Austin

Image warping and stitching

DD2423 Image Analysis and Computer Vision IMAGE FORMATION. Computational Vision and Active Perception School of Computer Science and Communication

Midterm Exam Solutions

Planar homographies. Can we reconstruct another view from one image? vgg/projects/singleview/

Geometric Transformations and Image Warping

MA 323 Geometric Modelling Course Notes: Day 21 Three Dimensional Bezier Curves, Projections and Rational Bezier Curves

Exercise session using MATLAB: Quasiconvex Optimixation

Rotation and Interpolation

CSE 252A Computer Vision Homework 3 Instructor: Ben Ochoa Due : Monday, November 21, 2016, 11:59 PM

Agenda. Rotations. Camera models. Camera calibration. Homographies

6. Rectification 2 hours

XPM 2D Transformations Week 2, Lecture 3

CSCI 5980: Assignment #3 Homography

LAB 2: Resampling. Maria Magnusson, 2012 (last update August 2016) with contributions from Katarina Flood, Qingfen Lin and Henrik Turbell

Announcements. Mosaics. Image Mosaics. How to do it? Basic Procedure Take a sequence of images from the same position =

RESAMPLING DIGITAL IMAGERY TO EPIPOLAR GEOMETRY

Pin Hole Cameras & Warp Functions

Global Flow Estimation. Lecture 9

Announcements. Mosaics. How to do it? Image Mosaics

This week. CENG 732 Computer Animation. Warping an Object. Warping an Object. 2D Grid Deformation. Warping an Object.

CS 335 Graphics and Multimedia. Geometric Warping

Image Analysis. Rasmus R. Paulsen DTU Compute. DTU Compute

EECS 556 Image Processing W 09. Interpolation. Interpolation techniques B splines

Limitations of Thresholding

Lab 6: Graphical Methods

CIS581: Computer Vision and Computational Photography Project 2: Face Morphing and Blending Due: Oct. 17, 2017 at 3:00 pm

CS143: Introduction to Computer Vision Homework Assignment 3

Vector Algebra Transformations. Lecture 4

Linear Algebra and Image Processing: Additional Theory regarding Computer Graphics and Image Processing not covered by David C.

Homographies and RANSAC

Shadows in Computer Graphics

Geometric Transformations and Image Warping Chapter 2.6.5

16720: Computer Vision Homework 1

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

lecture 16 Texture mapping Aliasing (and anti-aliasing)

Vision Review: Image Formation. Course web page:

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

Agenda. Rotations. Camera calibration. Homography. Ransac

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Targil 10 : Why Mosaic? Why is this a challenge? Exposure differences Scene illumination Miss-registration Moving objects

Lecturer: Keyvan Dehmamy

Assignment 2 : Projection and Homography

Implementation of a backprojection algorithm on CELL

XPM 2D Transformations Week 2, Lecture 3

Broad field that includes low-level operations as well as complex high-level algorithms

Terrain correction. Backward geocoding. Terrain correction and ortho-rectification. Why geometric terrain correction? Rüdiger Gens

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Manual image registration in BrainVoyager QX Table of Contents

CSE 252B: Computer Vision II

Splines and Piecewise Interpolation. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Pin Hole Cameras & Warp Functions

Introduction to MATLAB

Image warping introduction

Image Registration Lecture 4: First Examples

Camera Model and Calibration. Lecture-12

CS1114 Assignment 5, Part 1

MET71 COMPUTER AIDED DESIGN

Machine Learning for Signal Processing Fundamentals of Linear Algebra

STIPlotDigitizer. User s Manual

Computer Graphics: Geometric Transformations

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Image Warping and Morphing

Module 4F12: Computer Vision and Robotics Solutions to Examples Paper 2

Global Flow Estimation. Lecture 9

Feature Extraction and Image Processing, 2 nd Edition. Contents. Preface

Computer Vision Projective Geometry and Calibration. Pinhole cameras

Today s lecture. Image Alignment and Stitching. Readings. Motion models

Calculation of the fundamental matrix

Transcription:

Image Warping Mikkel B. Stegmann Informatics and Mathematical Modelling, Technical University of Denmark Richard Petersens Plads, Building 32, DK-2800 Kgs. Lyngby, Denmark August 20, 200 Abstract This note introduces the concept of image warping and treats the special case of Euclidian warping along with a discussion of a Matlab implementation. Secondly an application of image warping is given; namely image mosaicing where images are stitched together e.g. to form a panoramic view. Effort has been put into making the text as self-containing as possible. However, basic knowledge of linear algebra is a requirement. The note is intended for an introductory image analysis course. Keywords: image warping, Euclidian warping, similarity transforms, image mosaicing. Introduction Image warping is in essence a transformation that changes the spatial configuration of an image. Using this definition a simple displacement of an image by say five pixels in the x-direction would be considered a warp. Formalized, this can be written as the vector function: I = f(i), f : IR 2 IR 2 () 2 Euclidian Warping In the following, we will study one particular type of warp namely; the Euclidian warp also called the Euclidian similarity transform. This type of warp involves four parameters: p = [ s α t x t y ] T, which denotes scale, rotation and translation respectively. Let x = [ x y ] T denote a position in the original 2D image, I, and let x = [ x y ] T denote the corresponding position in the warped image, I, (both in homogeneous coordinates). Looking at one pixel equation () can now be written as a simple linear transformation, where T denotes the transformation matrix: Contact: mbs@imm.dtu.dk, http://www.imm.dtu.dk/ mbs/. x = Tx (2)

x y = s cos α s sin α t x s sin α s cos α t y 0 0 x y (3) Observe that instead of warping a single point we could warp a whole image of n points by replacing x with: X = x... x n y... y n (4)... then equation (2) becomes: X = TX (5) The above transformation is implemented in the Matlab script warp where the transformation matrix, T, that rotates an image five degrees is written as: s = ; a = 5*pi/80; tx = 0; ty = 0; T = [ s*cos(a) s*sin(a) tx ; -s*sin(a) s*cos(a) ty ; 0 0 ]; Due the discrete nature of raster images, one is in no way ensured that each input pixel exactly maps to an out pixel. Consequently warping is mostly performed backwards i.e. from the output image to the input image. Since T is square and has full rank we can easily compute the inverse transformation as: In Matlab this is accomplished by: X = T X (6) X = T \ [ Xp(:) Yp(:) ones(n,) ] ; where is the transpose operator, Xp(:) and Yp(:) are column vectors containing the x and y coordinates and ones(n,) is a column vector of ones. What s left now is to lookup (or interpolate) the intensity values in the incoming image, I, at the positions in the X matrix. As seen below this is done for each color channel. xi = reshape( X(,:),wp,hp) ; yi = reshape( X(2,:),wp,hp) ; Ip(:,:,) = interp2(i(:,:,), xi, yi, *bilinear ); % red Ip(:,:,2) = interp2(i(:,:,2), xi, yi, *bilinear ); % green Ip(:,:,3) = interp2(i(:,:,3), xi, yi, *bilinear ); % blue Refer to to appendix A for a full listing of the script warp.m. 2

3 Image Mosaicing One application for image warping is merging of several images into a complete mosaic e.g. to form a panoramic view. Here this is carried out by a Euclidian warp. In mosaicing, the transformation between images is often not known beforehand. In this example, two images are merged and we will estimate the transformation by letting the user give points of correspondence (also called landmarks or fiducial markers etc.) in each of the images. In order to recover the transformation we rearrange the warping equation (2) so that the warping parameters is the vector t in: x = Zt (7) x y = x y 0 0 y x 0 0 0 0 0 0 s cos α s sin α t x t y (8) The warping parameters is now obtained by solving the linear system (7) in Matlab: t = Z \ xp; From (8) we see that (at least) two points are required to determine the four warping parameters. In the Matlab script mosaic we prompt the user to deliver two such points on each image using the function ginput2(). The full code for recovering the parameters is then: figure; image(i); [X Y] = ginput2(2); figure; image(i2); [X2 Y2] = ginput2(2); Z = [ X2 Y2 ; Y2 -X2 ; 0 0 ; 0 0 ] ; xp = [ X Y ] ; t = X \ xp; a = t(); % = s cos(alpha) b = t(2); % = s sin(alpha) tx = t(3); ty = t(4); A demonstration of mosaicing using two input images is given in figure and 2. Actually, a Euclidian warp is rather limited w.r.t the types of camera transformations it can handle. In a real image mosaicing application a projective transformation (a homography) should be applied. 3

first input image second input image 50 50 00 00 50 50 200 200 250 300 250 350 300 50 00 50 200 250 50 00 50 200 250 (a) (b) Figure : (a) First input image for mosaic. (b) Second input image for mosaic. mosaic image 50 00 50 200 250 300 350 50 00 50 200 250 300 350 400 450 Figure 2: Image mosaic produced by mosaic. 4

4 Other Warping Functions Below is listed some of the more commonly used warping functions ordered ascending by their degrees of freedom i.e. the number of warping parameters. For simplicity, these are not written on matrix form. Refer to [] for a review of additional warping functions. Euclidian / Procrustes Affine / st order polynomial Bilinear Perspective 2 nd order polynomial / Biquadratic General polynomial x = ax + by + t x, a = s cos α y = bx + ay + t y, b = s sin α x = a 0 + a x + a 2 y y = b 0 + b y + b 2 y x = a 0 + a xy + a 2 x + a 3 y y = b 0 + b xy + b 2 x + b 3 y x = (a 0 + a x + a 2 y)/(c 0 x + c y + ) y = (b 0 + b x + b 2 y)/(c 0 x + c y + ) x = a 0 + a x + a 2 y + a 3 x 2 + a 4 y 2 + a 5 xy y = b 0 + b x + b 2 y + b 3 x 2 + b 4 y 2 + b 5 xy x = i j a ijx i y j y = i j b ijx i y j Problems This section presents a set of practical and theoretical problems. The former requires that you have a Matlab installation 2 and the files: warp.m, mosaic.m, ginput2.m, left.jpg, right.jpg, checkers.jpg 3. Further the current Matlab dir should be where the above files reside (use Matlab commands pwd and cd). P0: Run the script warp. Try changing the values for s, a, tx, ty. In which order are the three Euclidian operations applied? P: Run the script mosaic. Try doing a mosaic with two nearby points and two points far apart. Which one do you prefer? Why? P2: Show that Tx = Zt (you must not use the equality x = x ). P3: Modify warp to load the image checkers.jpg and experiment with the interpolation schemes supported by the Matlab function interp2(), which are *nearest, *bilinear, *cubic, *spline. What is the observed difference? P4: Why is homogeneous points used in section 2 as opposed to normal two dimensional points? P5: Construct expressions on the form x = Tx and x = Zt for the bilinear warp. P6: What is the minimum number of points you would need to determine the parameters for a bilinear warp e.g. for an image mosaicing application? How many would you prefer? Why? 2 Version 5.3 or greater. 3 Can be downloaded at http://www.imm.dtu.dk/ mbs/downloads/warping.zip 5

P7: Copy the file mosiac.m to mosiac2.m and modify it to perform bilinear mosaicing. Remember that the parameters for backwards transformation can be calculated by interchanging (x, y) and (x, y ) in equation (8). P8: Modify mosiac2.m to take twice as many points as you answered in problem 6. How does this affect the warp? References [] C. A. Glasbey and K. V. Mardia. A review of image-warping methods. Journal of Applied Statistics, 25(2):55 72, 998. A warp.m % load input image I = double(imread( right.jpg )); [h w d] = size(i); % show input image figure; image(i/255); axis image; title( input image ); % make transformation matrix (T) s = ; a = 5*pi/80; tx = 0; ty = 0; T = [ s*cos(a) s*sin(a) tx ; -s*sin(a) s*cos(a) ty ; 0 0 ]; % warp incoming corners to determine the size of the output image cp = T*[ w w ; h h ; ]; Xpr = min( cp(,:) ) : max( cp(,:) ); % min x : max x Ypr = min( cp(2,:) ) : max( cp(2,:) ); % min y : max y [Xp,Yp] = ndgrid(xpr,ypr); [wp hp] = size(xp); % = size(yp) % do backwards transform (from out to in) n = wp*hp; X = T \ [ Xp(:) Yp(:) ones(n,) ] ; % warp % re-sample pixel values with bilinear interpolation clear Ip; xi = reshape( X(,:),wp,hp) ; yi = reshape( X(2,:),wp,hp) ; Ip(:,:,) = interp2(i(:,:,), xi, yi, *bilinear ); % red Ip(:,:,2) = interp2(i(:,:,2), xi, yi, *bilinear ); % green Ip(:,:,3) = interp2(i(:,:,3), xi, yi, *bilinear ); % blue % show the warping result figure; image(ip/255); axis image; title( warped image ); 6

B mosaic.m % load input images I = double(imread( left.jpg )); [h w d] = size(i); I2 = double(imread( right.jpg )); [h2 w2 d2] = size(i2); % show input images and prompt for correspondences figure; subplot(,2,); image(i/255); axis image; hold on; title( first input image ); [X Y] = ginput2(2); % get two points from the user subplot(,2,2); image(i2/255); axis image; hold on; title( second input image ); [X2 Y2] = ginput2(2); % get two points from the user % estimate parameter vector (t) Z = [ X2 Y2 ; Y2 -X2 ; 0 0 ; 0 0 ] ; xp = [ X ; Y ]; t = Z \ xp; % solve the linear system a = t(); % = s cos(alpha) b = t(2); % = s sin(alpha) tx = t(3); ty = t(4); % construct transformation matrix (T) T = [a b tx ; -b a ty ; 0 0 ]; % warp incoming corners to determine the size of the output image (in to out) cp = T*[ w2 w2 ; h2 h2 ; ]; Xpr = min( [ cp(,:) 0 ] ) : max( [cp(,:) w] ); % min x : max x Ypr = min( [ cp(2,:) 0 ] ) : max( [cp(2,:) h] ); % min y : max y [Xp,Yp] = ndgrid(xpr,ypr); [wp hp] = size(xp); % = size(yp) % do backwards transform (from out to in) X = T \ [ Xp(:) Yp(:) ones(wp*hp,) ] ; % warp % re-sample pixel values with bilinear interpolation clear Ip; xi = reshape( X(,:),wp,hp) ; yi = reshape( X(2,:),wp,hp) ; Ip(:,:,) = interp2(i2(:,:,), xi, yi, *bilinear ); % red Ip(:,:,2) = interp2(i2(:,:,2), xi, yi, *bilinear ); % green Ip(:,:,3) = interp2(i2(:,:,3), xi, yi, *bilinear ); % blue % offset and copy original image into the warped image offset = -round( [ min( [ cp(,:) 0 ] ) min( [ cp(2,:) 0 ] ) ] ); Ip(+offset(2):h+offset(2),+offset():w+offset(),:) = double(i(:h,:w,:)); % show the result figure; image(ip/255); axis image; title( mosaic image ); 7