5

Is there a way to rotate an image based upon a mapping in ImageMagick? The problem is similar to displacement mapping however instead of warping & morphing the shape based upon the luma/chroma in a map I want to rotate an image based upon the map.

For instance: If I had a pattern, then applied a chroma/luma map shape to it, it would rotate the pattern and output it based upon the luma/chroma difference from the midpoint (50%).

Like so: enter image description here

My task is to create a fairly complex set of shapes and map a pattern to them at different angles respective of their chroma/luma.

Would this be some kind of custom plugin I'd have to write or is there a simple way to to this in IM 6?

Thanks very much!

Alex
  • 3,732
  • 5
  • 37
  • 59

1 Answers1

5

ImageMagick does not come with the functionality you want builtin, but thanks to the -fx argument you can write your own.
The following command will rotate the source image clockwise by the applied mask:

convert input.png rotationmap.png -fx \
'rs=-6.28318531;
p{
    cos(v*rs)*(i-w/2.0)-sin(v*rs)*(j-h/2.0)+w/2.0,
    sin(v*rs)*(i-w/2.0)+cos(v*rs)*(j-h/2.0)+h/2.0
}' output.png

Fill the rotation map with #202020 to rotate by 45 degrees for example:

hexval = (rotation_deg / 360) * 255

enter image description here

Or do sillier stuff (this is fun to play with, actually):

enter image description here

Caveats:

  • Cut off corners just repeat indefinitely.
  • Rotation map needs to be the same size as the source image.
  • No resampling, result might get blurry or edgy.
Cobra_Fast
  • 15,671
  • 8
  • 57
  • 102
  • Great suggestion! any idea how i might be able to force resampling? – Alex Aug 22 '13 at 08:51
  • 1
    @Alex Unfortunately there is no direct resampling for the `-fx` parameter, but basic interpolation is: http://www.imagemagick.org/script/command-line-options.php?#interpolate. I have tested a few and `mesh` seems to spit out okay results, although the difference between them is very marginal. Alternatively you could put your own interpolation stuff into the formula. – Cobra_Fast Aug 22 '13 at 12:24