Page 1 of 1
Apply cubic bezier curve to image
Posted: 2013-02-04T08:13:25-07:00
by shirkavand
Hi,
Is possible to apply a quadratic(or cubic)bezier curve to an image, so the resulting image will be modified to have a curve transformation in it? Something similar to barrel transformation, so for example i can give a (x,y) and imageMagick based on that ending pont creates and modifies the image with a bezier curve... i' ven using PHP's Imagick shared library, and i've been playing with functions like "pathCurveToQuadraticBezierSmoothAbsolute", "bezier" etc with no luck.
Any idea will be very appreciated,
Warm Regards
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T08:39:06-07:00
by snibgo
Can you be more specific about what you are trying to do? Ideally with before/after images.
For example: an image could be distorted so that every horizontal line in the original followed a given bezier curve in the output. I would do this with a displacement map. See
http://www.imagemagick.org/Usage/mappin ... ement_maps
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T09:31:37-07:00
by shirkavand
Thank you for your fast reply. Please hek these links:
http://s3.postimage.org/qrzp73osv/Original.png
http://s3.postimage.org/tjiyxpnbj/Curved_down.png
http://s3.postimage.org/njv7u22j3/Curved_up.png
As you can see is something similar to a barrel transformation, but the left and right side of the image are not curved only the top and bottom sides.
Any ideas?
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T09:49:14-07:00
by snibgo
A similar effect can be achieved with a simple Shepards distortion. Windows script:
Code: Select all
convert original.png -distort Shepards ^" ^
0,0 0,0 ^
179,0 179,0 ^
0,155 0,135 ^
179,155 179,135 ^
72,0 72,20 ^
72,155 72,155 ^" ^
orig_down.png
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T10:06:21-07:00
by shirkavand
i already used Shepards before, but it does worked for me. I have just tested your script(using linux) and it does not work either(maybe i am doing something wrong...)
convert original.jpg -distort Shepards \ '0,0 0,0 179,0 179,0 0,155 0,135 179,155 179,135 72,0 72,20 72,155 72,155' down.jpg
Which result in this image:
http://s3.postimage.org/y0e34mv6b/down.jpg
and not something like:
http://s3.postimage.org/tjiyxpnbj/Curved_down.png
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T10:16:35-07:00
by snibgo
What version IM are you using? I get a better result than you in 6.7.9. More recent versions, eg 6.8.2, allow me to tweak the power factor of the shepards distortion:
Code: Select all
"%IMG682%convert" original.png ^
-define shepards:power=4 ^
-distort Shepards ^" ^
0,0 0,0 ^
179,0 179,0 ^
0,155 0,135 ^
179,155 179,135 ^
72,0 72,20 ^
72,155 72,155 ^" ^
orig_down.png
However, shepards isn't identical to bezier. I think the only way to get an exact bezier distortion is by constructing a displacement map.
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T10:28:01-07:00
by shirkavand
I'm using: Version: ImageMagick 6.7.9-0, and sadly "-define shepards:power=4" did not make any difference. Are you sure that using a " displacement map" is not a too difficult solution for this problem?
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T11:01:43-07:00
by fmw42
If on LInux or Mac or Windows w/Cygwin, see my script, curves at the link below. Is that what you are trying to do?
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T11:04:44-07:00
by snibgo
As I said, shepards:power is only for more recent IM versions.
Displacement maps aren't too difficult. See the page I cited. As an example:
Code: Select all
"%IMG%convert" ^
-size 180x156 xc:White -fill Black -stroke Black ^
-draw "path 'M 0,78 C 30,88 60,88 90,88 S 150,88 179,78 L 179,0 0,0 0,78'" ^
-resize "180x1^!" ^
-resize "180x156^!" ^
omap.png
"%IMG%composite" ^
omap.png ^
original.png ^
-displace 0x100 ^
orig_down2.png
This gives roughly the result you want. The coordinates need tweaking, and the canvas needs expanding so parts of the image aren't lost.
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T11:11:15-07:00
by shirkavand
This script is exactly what i need:
http://www.fmwconcepts.com/imagemagick/cylinderize/
I need to create a cilinder effect in the images. But i an not use your script because i need to use imagick shared library... so maybe i will need to tweak the example here:
http://www.imagemagick.org/Usage/mappin ... ement_maps under Cylindrical Displacement
Re: Apply cubic bezier curve to image
Posted: 2013-02-04T14:26:20-07:00
by fmw42
I need to create a cilinder effect in the images. But i an not use your script because i need to use imagick shared library... so maybe i will need to tweak the example here:
Why? You can just call the script from PHP exec(). Note that Imagick has not kept up with many of the Imagemagick improvements.