An Idiot, a digital camera, and a PC +

My name is Seung Chan Lim, a clueless noob trying to make sense of the subject of computational photography by re-teaching the material learned in class....

Entering Warp Zone!

posted by dJsLiM on Saturday, October 01, 2005 ::
click for class reference material ::

In the previous entry we looked at image processing, which involved changing the brightness values of the pixels. This time let's look at image warping, which entails moving a pixel from one position to another.

Simply put, warping is the process taken to warp (DUH!) a pixel from its original x, y position to a new x, y position. In math talk, this is referred to as changing the domain of an image. The domain

basically denotes the range in which the values of x and y for the pixels inside an image reside within. For example, let's say the domain in which the pixels were laid out in the original image ranged from 0 to 10 in the x axis and 0 to 20 in the y. If we were to move this image by +5 pixels in the x-axis and +10 pixels in the y, then x in the warped image will end up spanning 5 to 15 and y, 10 to 20.

While we're in math land, let's venture in a lil further and visit some linear algebra concepts. Don't worry, it's nothing terribly complicated. =) it's just that warping can be represented quite nicely using a simple series of matrix operations since we're dealing with numbers in a discrete domain (remember that digital images are brightness values sampled at discrete intervals in space). I'll tell ya, math geeks definitely get off on the elegance of simple matrix operations. ;)

There are a few different types of image warps. Most common ones include translation, rotation, aspect, affine, and perspective. These are called parametric or global warping. I'll define that term in just a second, but first let's talk matrix.

The act of warping an image is also referred to as a transformation, and we call the function that takes an image to produce a new image, the transformation function. Given that, we can now represent this relationship as follows.


p' = T(p)

where p represents points on the original image and p' represents points on the transformed image.

If we were to dig one level deeper and break out the point into the x and y components and depict it as a 2 x 1 matrix, we'd get the following:

[x

 y]

We can then define the previous relationship again as a matrix equation:

[x'       [x
     =  M
 y']       y]

where M is the matrix that defines the transformation function T.

What this equation means is that for each and every pixel at x and y that resides within the original image p, we'll multiply it by the transformation matrix M to get new values of x and y, x' and y', that are on the new image. The fact that the transformation gets applied uniformly across all pixels is why this type of warping is called parametric/global warping

You're dying for some more matrices, right?! Soooo... Let's start with scaling. Scaling is an operation that resizes an image to make it bigger or smaller. What this really means is that the x and y components are multiplied by a scalar value so that the distance between two

neighboring x values and two neighboring y values are increased, ending up with an image that has an onverall dimension that is either bigger or smaller. In a uniform scaling operation you multiply the x and the y component by the same scalar, and in a non-uniform scaling operation you multiply them independently with different scalars. This simple multiplication can be expressed in matrix form as follows:

[x'    [a 0    [x
     =       *
 y']    0 b]    y]

where a and b are the scalars to be used to multiply x and y by respectively.

Let's quickly refresh our memories on how we multiply matrices together. You take the first row and match it up with the first column to get

x' = a × x + 0 × y then you take the second row and match it up with the first column to get

y' = 0 × x + b × y

Next we have 2D Rotation which entails moving a pixel at position x and y to point x', y' so that the vectors from the origin to the two points make a certain angle, say θ. I won't go into the good ol' highschool trig you had painfully memorized only to quickly forget after that dreaded IB exam, but the matrix equation comes out to take the following form.

[x'    [cos(θ) - sin(θ)   [x
     =
 y']    sin(θ)   cos(θ)]   y]

Then we have 2D shear which is represnted as follows:

[x'    [1  shx [x
     =
 y']    shy 1]  y]

And 2D mirroring about the Y axis

[x'    [-1  0  [x
     =
 y']     0  1]  y]

and about (0, 0)

[x'    [-1  0 [x
     =
 y']     0 -1]  y]

Well, I think that's enough matrices for you to chew on for the night. In the next entry things get more interesting as we look at some of the more combinatorial warping. ;) Stay tuned!

0 Comments:

Post a Comment

<< Home