Geeks With Blogs

News
Welcome to my blog.
Here's what we've got on the menu today:

Lorin Thwaits A geek says what?
When playing back content from my 3D camcorder, if you aren't wearing shutter glasses then the result is pretty blurry and bland looking.  After putting on the glasses, the scene jumps to life.  So while putting together a sample photo to promote how it works, I wanted to superimpose a better 2D image, and stretch it over the existing image of a screen in the photo.  It had been awhile since I've done anything real with math, so I took a half hour and figured out a couple equations to do the mapping, and wrote a program to do the translation for each of the pixels into the quasi-3D space of the monitor screen, ending up with this result:

(The superimposed image doesn't look that believable here, but when I resized the picture down a bit, it looked better.)

The routine works by mapping each pixel from the source image into the proper x/y coordinate for the destination space, seen above.  And it works fine *except* that where the image gets stretched a bit much, there are moiré kind of effects that pop up.  These can be seen at the right side of the image above as lines of speckles.

Here's the formulas that do the mapping to create the result seen above:

destX=((lrx - llx) * (srcX / srcWid) + llx - ((urx - ulx) * (srcX / srcWid) + ulx)) * (srcY / sHt) + (urx - ulx) * (srcX / srcWid) + ulx

destY=((lry - ury) * (srcY / srcHt) + ury - ((lly - uly) * (srcY / srcHt) + uly)) * (srcX / sWd) + (lly - uly) * (srcY / srcHt) + uly

And here's what all my crazy variable names mean:

srcWid = source image width
srcHt = source image height

srcX = source X coordinate
srcY = source Y coordinate
destX = destination X coordinate
destY = destination Y coordinate

Coordinates that define the location of the destination image:
ulx = upper left corner of the image, x coordinate
uly = upper left corner of the image, y coordinate
urx = upper right corner of the image, x coordinate
uly = upper right corner of the image, y coordinate
llx = lower left corner of the image, x coordinate
lly = lower left corner of the image, y coordinate
lrx = lower right corner of the image, x coordinate
lry = lower right corner of the image, y coordinate

So basically if you supply a source x/y, you can then find what the appropriate destination x/y should be, and plot the color from one to the other.  So the code iterates through all the source pixels and plots each one to a destination pixel.  But it would be cleaner and often faster to go the other way, iterating through all the destination pixels to find what source pixel (if any) matches up to that point.  So basically the reverse of the above equations.  The real sticky part is that each of the equations is dependant on not just the srcX, but also srcY.  And as well, each point on the destination could conceviably map to *two* source pixels (but not more since the highest power expressed here is effectively a squared term.)

Anyone out there a math whiz that can think of an easy way to "go the other way", in other words in the two equations above, solve for srcX and srcY?  I found it kinda challenging.  A fun brain challenge more than anything else.  My hotshot math whiz brother may find the answer, who knows.

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: My image got stretch marks

# re: My image got stretch marks
i like it very much
Left by ed hardy shoes on Aug 12, 2009 8:58 AM

# re: My image got stretch marks
The picture got stretch mark, but still clear image, good mobile camera.
Left by Leather Briefcases on Nov 18, 2009 9:07 PM

# re: My image got stretch marks
I think it is a little involuted, but what I want say is the information is very useful.
Left by Professional LED light on Mar 07, 2010 8:01 PM

# re: My image got stretch marks
A beautiful girl...nice post..really liked reading your post!. Quallity content. With such a valuable blog i believe you deserve to be ranking even higher in the search engines wholesale dresses mens suits
Left by cheap prom dresses on Mar 30, 2010 11:18 PM

# re: My image got stretch marks
Christian Louboutin Shoes Christian Louboutin Shoes
Christian Louboutin Boots Christian Louboutin Boots
FG JHJ
Left by jcjc762 on Apr 01, 2010 2:47 AM

# re: My image got stretch marks
The girl you pictured is so cute, I love her very much.
Left by drew brees jersey on Jun 03, 2010 12:14 AM

# re: My image got stretch marks
good mobile camera.
Left by Paul smith bags on Jun 13, 2010 10:45 PM

# re: My image got stretch marks
lly = lower left corner of the image, y coordinate
Left by polamalu jerseys on Jun 30, 2010 3:11 AM

# re: My image got stretch marks
Left by high replica handbags on Jul 31, 2010 7:34 PM

# re: My image got stretch marks
Left by Juicy Couture handbags on Aug 13, 2010 3:54 AM