Page 1 of 1

How do I wrap an image onto a rounded cube?

Posted: 2012-06-05T23:21:36-07:00
by nb1forxp
How do I take a 2D image like this:
Image
and wrap it onto the 3 visible sides of this cube?
Image

The upper left corner of the image should be in the center top corner of the cube. The lower right edge of the cube should be the right edge of the image. The lower left edge of the cube should be the bottom edge of the image.

Since there will be a discontinuity at the front vertical edge of the cube, the front vertical rounded edge should scale the image data.

Please ignore the shadows/highlights on the cube and the rounded edges that are not visible from this perspective. I'm more interested in understanding how to apply the image to the rounded edges of the cube without significant distortions (except along the front vertical edge where there will be massive distortion).

Thanks!

Re: How do I wrap an image onto a rounded cube?

Posted: 2012-06-06T18:54:52-07:00
by anthony
The question is more, do you need to do this once or just a couple of times.
Or do you need to do this with thousands of images.

The former can be done using raytracing, projections and even just some image editing
You can use a combination of multiple affine projects in different areas (morphing), though IM does not have such features as yet.

The latter is best done by generating distortion maps. a X, Y, shading, and masking maps
the above provides the last two, so you just need a map to define what X,Y of the original image should be places in that pointing on the map.
See Distortion Mapping
http://www.imagemagick.org/Usage/mapping/#distort

These coordinate mappings can be calculated mathematically, probably using the same math used to generate the cube image you give as an example.

With maps distorting any image onto a complex object like the smoothed cube above, becomes very fast and can even be scaled to multiple sizes, for both input and output.

Re: How do I wrap an image onto a rounded cube?

Posted: 2012-06-06T19:34:05-07:00
by fmw42
Working out the distortion may will not be easy to get it accurate, in my opinion, though possible with a lot a math calculations of which I do not know how to do.

As Anthony mentioned, you might be able to use the rounded cube image with its shading to be the distortion map, possibly modified in some way and then use -displace to warp. But you will also need a mask image to cut out the parts that extend outside the cube boundary. However, this may not be the kind of warp you desire.

The best solution is getting a proper 3D texture mapping application rather than trying to make as 2D image processing application simulate a 3D projection.

Re: How do I wrap an image onto a rounded cube?

Posted: 2012-06-06T21:31:10-07:00
by nb1forxp
Thank you both for your great suggestions! I'll do some more research as you recommended.

Re: How do I wrap an image onto a rounded cube?

Posted: 2012-06-06T21:45:08-07:00
by fmw42
The upper left corner of the image should be in the center top corner of the cube. The lower right edge of the cube should be the right edge of the image. The lower left edge of the cube should be the bottom edge of the image.
If I understand what you want, your are putting the top left quadrant of the image on the top face of the cube, the top right quadrant of the image on the right face of the cube and the whole bottom half on the left face of the cube. That will be very distorted.

You could cut out the quadrants and the bottom half. Scale the bottom half to the same size as the quadrant. Then use my 3Dbox bash unix script to put the images on a non-rounded box. See my 3Dbox script at the link below. Sorry the script does not know about rounded edges.

The other way might be to do the above to prepare you image, but cut out small areas for where the rounded edges would be. Then warp the images for the 3 faces to match the flat regions using -distort bilinearforward or -distort perspective. Also warp the smaller edge pieces with my cylinderwarp script and then warp those to turn them to fit the rounded edges. My 3Drotate might help there. This would be rather complicated and require trial and error to get it lookking close, if that is even possible.

Re: How do I wrap an image onto a rounded cube?

Posted: 2012-06-07T18:28:33-07:00
by anthony
I only suggest using the given cube image as the shading component of the map!

It is the creating of the displacement/distortion (relative/absolute) map that will be a problem. Though the bulk of the map will be three affine distortions joined together.

Smoothing the join between the affine maps is the tricky part.

Also selection what parts of the image should apprear on what face is also tricky. Any way you look at it some part of the
image will need to be 'cut' to form the cube, unless you use some type of projection in 3d space. But then the faces will not look 'flat'.