Single point displacement transformation
Single point displacement transformation
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
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.


- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
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.
http://www.fmwconcepts.com/imagemagick/index.html
Note that the script if very slow due to the extensive use of -fx.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Single point displacement transformation
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).
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).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Single point displacement transformation
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.
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.
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..
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Single point displacement transformation
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.
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.
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
Thanks to Anthony Thyssen, my shapemorph script is now 10x faster without the need for multiple processors.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
I just uploaded a new shapemorph2 script that allows any number of control points. see link below.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Single point displacement transformation
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)
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)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Single point displacement transformation
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Single point displacement transformation
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....
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.
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
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/