Brady Moritz
Brady Moritz

Reputation: 8899

Image rendering technique - for adding realistic text to existing photos

Curious if there are general tools out there for creating images that contain text (or possibly other elements) which are distorted to appear as an original part of the image. These "real" billboard photos that let you put your own image or text on the billboard is one example. Another example is how zazzle lets your preview your tshirt design by distorting the text or graphic to make it appear as if it deforms slightly to the curves of the fabric.

I'm a .Net guy but am interested in seeing any general solutions for this kind of project, or even just some pointers to other discussions on the topic would be helpful.

Clarification- desriptions of techniques is good, but ultimately I'm curious if there are toolkits out there that help automate some of this, and which could be potentially used in a dynamic environment for on-demand image generation.

Upvotes: 2

Views: 484

Answers (2)

KeithS
KeithS

Reputation: 71591

The "right" way to do it is to determine the angle of the surface on which the text should be displayed, and what, if any, texture the surface has. You then recreate a virtual surface in the computer at that same angle and relative distance to the camera, then apply a texture containing your text on that, and "bump-map" it to make your text appear to be drawn directly on the brick wall or the. Adjust lighting of the texture to match the scene (possibly using a "shader" to control refraction of the light based on the angle of each point on the surface/bump-map), then just overlay your mapped texture with the original image. The math behind this is the cornerstone of the entire computer graphics industry, and new tools are still being developed to do it better and faster; you may find tools in the System.Windows.Media.3D namespace (or the XNA Framework add-in to .NET) that will help you here.

This is the basic process behind multi-million-dollar movie effects; shoot the real scene without CG elements (or with stand-ins that can be painted or rotoscoped out), create a "virtual set" in cyberspace, then "track" the movements of a virtual camera moving through that set to match the movement of the real camera through the real set. Then, you can render whatever you want in that shot, wherever you want it.

The "cheap" way to do it is to not bother with "tracking" (a very time-consuming process especially in a moving picture), and to instead just make a "best guess" about the location, angle etc of the elements, and simply draw your text over the top of it. PhotoShop has tools that can render text in this way, but since you're asking this question in a programming site I would assume you want to code your own solution.

Upvotes: 2

user1118321
user1118321

Reputation: 26395

For the billboarding, where you want to distort a 2D image to look like it lies on the plane of a sign, you can use a 4-corner pin technique. You give it the coordinates of the 4 corners of your image, and the coordinates you want those corners to map to, then solve a system of linear equations to produce a perspective transformation matrix. It's described here.

As for the shirt distortion, it's probably a general warping method with a fixed input mesh. General warping is a very large topic as you can see from this Google search.

Upvotes: 1

Related Questions