Solved

HomographyWarp -> Processing

Posted on 2011-03-12
12
360 Views
Last Modified: 2012-05-11
Right, I am trying to create a method for a homography warp. Problem is, I suck at linear algebra (actually, didn't do so bad, but it's been several years since I've taken it). And there's no book for this course.

Could anyone out there give me the idiot's version of how to implement this?

Thanks,
Ryan


/// Creates a new image that is width x height pixels.
/// The pixels of this image are set by applying the inverse homography (provided can be either
///
/// @param source       Image to inverse warp
/// @param H            Homography matrix
/// @param width        Width of image to create
/// @param height       Height of image to create
/// @returns            A width x height sub-region of warped source image
///
PImage homographyWarp(PImage source, Matrix H, int width, int height) {
  //
  // @todo
  //    Inverse warp source to get the pixel values for the new image
  //    Don't forget to divide the image coordinates with w (the 3rd coordinate) when you convert
  //    the homogeneous coordinates back to image coordinates
  //    Also, be sure to use bilinear (or some other) interpolation to get a smooth result.
  //
  // @note
  //    Remember that accessing a negative index'd pixel, or a pixel outside of the image will
  //    return a black pixel. This means you do not have to worry about the size of the image.
  //
  
  
  
  
  
  
  
  PImage result = createImage(width, height, RGB);
  return result;
}

Open in new window

0
Comment
Question by:rossryan
  • 7
  • 5
12 Comments
 

Author Comment

by:rossryan
ID: 35119399
Actually, I'd settle for a proper explanation of image warping and homography. Wikipedia isn't looking so hot.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35123955
Let's say you have an image taken by a camera at a certain point. Now you want to move everything so that it looks like it was taken from a different location. You can't just shift everything evenly - some things will be closer together in the second image and some will be farther apart. The process of 'changing camera angles' after the fact is what is being called homography. If you look really closely past all the technical mumbo-jumbo you can see that wikipedia is saying the same thing, just in a longer winded way.
In the general case, you would need the 3D coordinates of the objects in the image so that you know where to put them all. The homography matrix is the transformation matrix that specifies how everything must rotate.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35123990
http://opencv.willowgarage.com/documentation/camera_calibration_and_3d_reconstruction.html#findhomography
OpenCV (which I use) has a routine to find the homography matrix between two images, but it appears you are trying to find the second image given the matrix.
Note: there are several known methods for doing this. I assume (from the way the comments make it look like an academic assignment) that you were given methods in your book or in class that you should use.
If you remember anything from linear algebra, try to remember transformation matrices. That's all this is really.
The simplest (but somewhat technical) definition is that homographic warping is just changing the coordinates of a 3D space and projecting it onto a 2D space.
0
 

Author Comment

by:rossryan
ID: 35123999
I feel ya, but my brain isn't cooperating.

I'm trying to find an equation with focal length and vanishing points to get some planes, and help convert it into a 3D box, but I am coming up short.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35124063
I think your problem is that you are trying to make the problem harder than it really is. You already have the homography matrix, so you shouldn't need to explicitly mess with a 3D space at all. I don't know what you are expected to know at this point, but if you step back and review your lecture notes and book if you have them, you should see the answer fall out. It's just going to be a good deal of matrix algebra.
Work on it for a bit, but if you get stuck, give some more detail and context and I'll see if I can shed some light on the darker areas.
0
 

Author Comment

by:rossryan
ID: 35124106
Well, yeah. It's for another part, which I am working on, and just not getting.

I am just not understanding how we can calculate 3D points from a 2D image + focal length and a vanishing point.

I've browsed around looking for information at other universities, and they are all using the same slides as my instructor. I can't find a single rephrasing of the equations I am supposed to use, or the knowledge I am supposed to be sporting, because they are quite literally reusing the same exact slides.

It's incredibly frustrating, and my usual solution is to read someone else's take on an algorithm if the primary instructor is unclear, but of the few dozen university that I've found on Google, the slides are the same, and there is zero elaboration of the algorithms they use.
///
/// Sets the 4 points of each of the 5 'Rectangle3D' objects.
///
/// @todo Set nw, ne, se, sw for each retangle
///
/// @param focalLength      Focal length for image
/// @param vanishingPoint   2D image location of vanishing point
/// @param Quadrilaterals   5 quadrilaterals, one for each visible wall in the image
/// @param Rectangle3Ds     5 3D rectangle objects
///
/// @post  The 5 Rectangle3D objects have had their points updated
///
void get3DPlanes(float focalLength, Point vanishingPoint,
  Quadrilateral back, Quadrilateral left, Quadrilateral top, Quadrilateral right, Quadrilateral bottom,
  Rectangle3D back3D, Rectangle3D left3D, Rectangle3D top3D, Rectangle3D right3D, Rectangle3D bottom3D) {

  //
  // @todo
  //    1. The width and height ratio of the back plane directly tells you the aspect
  //       ratio of the box, so specifying the 3D height gives you the 3D width.
  //    2. The back plane's height is related to the depth of the box
  //       (see lecture slide: Depth of Box), so specifying the 3D height gives you the 3D depth
  //    3. Once you compute the 3D width, height, and depth of the box, you can compute the 3D
  //       coordinates of all corners points of the 5 surfaces (you may set the origin to be the
  //       top left corner of the wall surface, 3D X axis aligned to the horizontal axis of the
  //       image, the 3D Y axis aligned to the vertical axis, and the 3D Z axis aligned to the
  //       depth axis of the box).
  //    4. Store the 3D coordinates for each surface in the corresponding Rectangle object
  //
  // @note When you compute these 3D coordinates, don't forget to account for the fact that the
  //       surfaces are not exactly aligned with the box (see the image displayed before calculation
  //       and notice that the front end of the surfaces are not aligned).
  //       You need to adjust the depth coordinates of front points of each surface accordingly
  //       using the 2D image coordinates to get proper results.
  //
  //       Also, first compute the 3D coordinates for the back plane since those can be reused in
  //       other surfaces.
  //
  
  
  Point3D Backplane_NW = new Point3D();
  Point3D Backplane_NE = new Point3D();
  Point3D Backplane_SE = new Point3D();
  Point3D Backplane_SW = new Point3D();
  

}

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35124234
The focal length and vanishing point should translate to a third dimension easily with some basic trig (assuming you have a simple enough image, hot air balloons of varying sizes in the middle of a blue sky would be basically impossible to get a depth on).

Can you link to the slides you mention? I am usually able to find better ways of explaining things.
0
 

Author Comment

by:rossryan
ID: 35124257
0
 

Author Comment

by:rossryan
ID: 35124305
I need only understand these two pieces.

And, if at all possible, I'd like to understand this stuff tonight (project comes due at midnight, so the sooner, the better). No pressure ^_^.

Normally, this stuff isn't an issue, but like I said, it's been several years since I've done any linear algebra, and I am unlikely to relearn everything in the next three hours.

-Ryan
0
 

Author Comment

by:rossryan
ID: 35124444
0
 

Author Comment

by:rossryan
ID: 35124503
Can't figure it out either?
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 35125693
The slides from 59-73 really seem to give all the needed information. Which parts are you stuck on specifically? Slide 73 gives all the equations you need to get the 3D coordinates (with trig too, not linear algebra).
My guess is that you hit a brain block because you were trying to figure it out too fast since it was due last night (assuming you are in eastern time as it says in the original post).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now