Apply cubic bezier curve to image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
shirkavand
Posts: 8
Joined: 2013-02-04T08:06:40-07:00
Authentication code: 6789

Apply cubic bezier curve to image

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Apply cubic bezier curve to image

Post 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
snibgo's IM pages: im.snibgo.com
shirkavand
Posts: 8
Joined: 2013-02-04T08:06:40-07:00
Authentication code: 6789

Re: Apply cubic bezier curve to image

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Apply cubic bezier curve to image

Post 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
snibgo's IM pages: im.snibgo.com
shirkavand
Posts: 8
Joined: 2013-02-04T08:06:40-07:00
Authentication code: 6789

Re: Apply cubic bezier curve to image

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Apply cubic bezier curve to image

Post 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.
snibgo's IM pages: im.snibgo.com
shirkavand
Posts: 8
Joined: 2013-02-04T08:06:40-07:00
Authentication code: 6789

Re: Apply cubic bezier curve to image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply cubic bezier curve to image

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Apply cubic bezier curve to image

Post 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.
snibgo's IM pages: im.snibgo.com
shirkavand
Posts: 8
Joined: 2013-02-04T08:06:40-07:00
Authentication code: 6789

Re: Apply cubic bezier curve to image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply cubic bezier curve to image

Post 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.
Post Reply