warp image onto another image
Posted: 2011-03-04T19:53:54-07:00
Basically the goal is to put an arbitrary image onto a picture of a t-shirt, so that it looks as if the image is printed on the shirt. See below for an example.
An example result:
What I'm doing now, is first using shepards distortion to distort the image, then use -compose displace using a region of tshirt (grayscaled) to add some surface displacement, then add highlights/shadows by -compose multiply, finally adding this to the shirt at the same region. This kinda works, but the major problem is I have to manually supply control points to shepards distortion in order to distort the image so that it follows the flow of the shirt. Try to imagine there is a grid of control points on the shirt that are straight lines if the shirt is pictured perfectly flat and straight, then imagine where the corresponding point should land on the shirt since the shirt is distorted. This gives me a bunch of coordinates that I used to do shepards distortion. But this will not work if the shirt picture is changed. Basically I want something that works for warping arbitrary image onto arbitrary shirt pictures. I wonder if there is a way to automatically find the control point pairs using the grayscale image? For an arbitrary point on the shirt in the distorted shirt picture, maybe use its grayscale as the elevation value, and add the rotation of the shirt to compute the coordinate of the source point as if the shirt was straight? Or what other ways can I achieve the same goal?
An example result:
What I'm doing now, is first using shepards distortion to distort the image, then use -compose displace using a region of tshirt (grayscaled) to add some surface displacement, then add highlights/shadows by -compose multiply, finally adding this to the shirt at the same region. This kinda works, but the major problem is I have to manually supply control points to shepards distortion in order to distort the image so that it follows the flow of the shirt. Try to imagine there is a grid of control points on the shirt that are straight lines if the shirt is pictured perfectly flat and straight, then imagine where the corresponding point should land on the shirt since the shirt is distorted. This gives me a bunch of coordinates that I used to do shepards distortion. But this will not work if the shirt picture is changed. Basically I want something that works for warping arbitrary image onto arbitrary shirt pictures. I wonder if there is a way to automatically find the control point pairs using the grayscale image? For an arbitrary point on the shirt in the distorted shirt picture, maybe use its grayscale as the elevation value, and add the rotation of the shirt to compute the coordinate of the source point as if the shirt was straight? Or what other ways can I achieve the same goal?