Page 1 of 1
Single point displacement transformation
Posted: 2008-07-04T07:41:13-07:00
by dognose
I'm trying to do what seems should be a simple distortion. I want to transform an image by moving a point A to point B, with the rest of the image warping around that change, like a rubber sheet affixed at the edges.
I've looked that the perspective distortion, but, it just tends to move the entire image, requiring edge effects. I'd rather have the edge locked in, and the picture remain the same size.
I've also looked at a displacement map, but, it looks slow, and I really don't know now to automatically make one for this conversion.
The only solution I've come up with so far is to divide the image into 4 and resize each quadrant and glue it back together. I was hoping that there would be an easier way!
Does anybody have any ideas?
Re: Single point displacement transformation
Posted: 2008-07-04T08:08:16-07:00
by fmw42
displacement maps will do that, but it is broke and will not do both the x and y displacement. I am working on a script to do the same thing as you are trying using -fx, but as you say it is slow. I have not finished it, yet, though as I got sidetracked with other projects. Anthony Thyssen has plans to build a -distort displacement function at some point in the future. I am generating the displacement x and y maps using Shepards method (basically an inverse distance weighted average from each of the control points).
I was trying to do this to generate a one-point (actualy five including the fixed corners,ed) morph between two images that includes both geometry and intensity, not just the intensity morph that IM does now.
Re: Single point displacement transformation
Posted: 2008-07-05T13:06:19-07:00
by fmw42
I have been working on a UNIX bash script using IM to do something like this using one control point (nose to nose) and the four fixed corners of the image. I borrowed images for a test from
viewtopic.php?p=37503#p37503. Here is the result of my first cut at the script, not yet finalized with 20 frames including the two originals plus additional 18 frame reversal for a total of 38 frames. It took about 6min on my Mac mini 1.42GHz PPC.

Re: Single point displacement transformation
Posted: 2008-07-06T19:24:18-07:00
by fmw42
I just uploaded my script, shapemorph, to my web site. If anyone is interested, it can be downloaded at
http://www.fmwconcepts.com/imagemagick/index.html
Note that the script if very slow due to the extensive use of -fx.
Re: Single point displacement transformation
Posted: 2008-07-06T23:34:45-07:00
by anthony
This (actually multi-point warping) is planned for a single image warp using -distort. In fact I should be starting the addition of new warps as soon as I finish the 'options' documentation for the new +level and +/-level-colors additions. Say in about a week.
New distortions is the first priority. After that I will be trying to eliminate the current 'blurriness' that is present in the distortion (caused by the use of the default gaussian resampling filter that Elliptical Weighted Resampling implements).
Re: Single point displacement transformation
Posted: 2008-07-07T08:01:56-07:00
by dognose
Wow, that's great, exactly the effect I was looking for!
It's certainly a bit slow though. For these multi frame animations, there is usually an easy way to speed this up on multi processor machines.
Code: Select all
convert ... frame1.gif &
convert ... frame2.gif &
convert ... frame3.gif &
convert ... frame4.gif &
wait
# .. merge frames..
This creates a nearly 4x speed improvement on a quad core machine if the frames don't depend on each other, and if that IM function isn't already optimized for mp.
Re: Single point displacement transformation
Posted: 2008-07-07T18:52:28-07:00
by anthony
Fred Wienhaus's script is innovative and informative. And in development we came up with the great idea of using a displacement map (4 sets actually) to generate the interpolated blending from form image to the other (linear displacement and color blending of points over the frames).
This basically means that you don't have to re-distort and re-cacluate the distortion of the images you are morphing them.
However as it is limited to using -fx it has speed issues which are in two parts.
- Generation of the four image maps is a complex -fx formula. That can't be helped
- The displacement of each pair of images for each frame is also -fx driven. That is because currently two-map displacement (in "composite") is broken, and has been since the 'masked' composite was properly implemented.
The first will become fast when I would out 'multi-point' shepard's method distorts.
That last while it should be a built-in to IM (in "composite"), is currently broken, and has been since 'masked' composite was finally properly implemented, using greyscale masking methods. This will also be made a built-in as a operation that is separate to 'composite', as a proper 'distortion' function (both as absolute disortion maps, and relative displacement maps).
Things are happening.
Re: Single point displacement transformation
Posted: 2008-07-10T18:41:26-07:00
by fmw42
Thanks to Anthony Thyssen, my shapemorph script is now 10x faster without the need for multiple processors.
Re: Single point displacement transformation
Posted: 2012-03-14T19:00:03-07:00
by fmw42
I just uploaded a new shapemorph2 script that allows any number of control points. see link below.
Re: Single point displacement transformation
Posted: 2012-03-14T19:37:23-07:00
by anthony
Very good. Well done Fred. This was something I wanted to actually see from some time.
The face border is preserve more during the transtion, rather than just fading in/out.
Your original shape morph script was the reason 'Multi-point Shepards Distortion' was originally added to IM. Though techniqueally it is really more of a shepards interpolation (sparse color) fill generating displacement map for image distprtion, as a general image distortion it has great benifits.
ASIDE and FUTURE: I have wanted to add distort expert options which 'reverse source/destination control points' and 'specifify percentage of distortion from source image to destination image'. These two control controls should allow you to then use exactly the same set of control points (without change) to generate ALL the intermediate image pairs, ready for blending.
That should also make it posible to create a single command "script" that will do the same thing as your shapemorph2 script. Using techniques descriped in
Animated Distorts
http://www.imagemagick.org/Usage/anim_mods/#distort
It would also benifit other things I want to add (like bilinear grids morphs).
But these additions is a VERY low priority compared to too many other things. Shell API for IMv7 being at the top, and immeditally below that 'global percent escapes' and other improvments to percent escapes. (Slow going due to work commitments but still progressing)
Re: Single point displacement transformation
Posted: 2012-03-14T19:42:15-07:00
by fmw42
It seems to work better than I thought for a small image, but I have not tested it on a very large image. The inverse squared distance (via -distort shepards) may look strange when points are very far apart.
Re: Single point displacement transformation
Posted: 2012-03-14T19:54:19-07:00
by anthony
You also can not use it for rotations..
See Shepards and Image Rotations
http://www.imagemagick.org/Usage/distor ... s_rotation
Or you will get very wierd 'swirling' effects between the moving control points.
Soem debuging option suggestions....
- An animition of just the unblended 'morphed' source or destination
- A flicker compare of the 100% distortion against the undistorted other image
These debugging animations will let you see how close the morphing of the images is, and tell you how good your selection of control points are.
Note the 100% distortion image is itself interesting as a,
what this person looks like, with this persons shape of face!
Of course actually location good matching pairs of control points is a task in and of itself, whether it is for morphing, or for 'panorama' image stitching.