RESOLVED: Color lookup table with FxImage method
Posted: 2009-05-26T20:40:20-07:00
I'm trying to replicate a command-line imagemagick operation utilizing an fx operator, and apparently Imagick doesn't work in quite the way I'd expected it to.
The following command essentially applies a color lookup table (clut.png, a vertical gradient image) to another image (input.png, a greyscale image) to produce a colorized output image:
I thought I could load the input and color lookup images into a sequence, then apply the fx operator like so:
However, this just outputs the last image in the sequence (the color lookup), and the fx expression doesn't seem to do anything. What am I doing wrong here?
I know there's a clutImage method specifically for this, but one of the environments I'm targeting for this has an older version of Imagemagick, so I wanted this for backward compatibility.
UPDATE: The reason fxImage seemed to be doing nothing was that I didn't realize it returns a new Imagick object rather than modifying the existing one. With that moment of stupidity realized, I grabbed the return value of the fxImage method, which seemed to be returning the expected image, but cropped to the dimensions of the color lookup table.
Curious, but progress, so I tried alternately switching the order of images in the sequence:
And switching the order of images in the expression
Doing both of the above seems to do the trick. I don't totally understand why, but it works now.
The following command essentially applies a color lookup table (clut.png, a vertical gradient image) to another image (input.png, a greyscale image) to produce a colorized output image:
Code: Select all
convert input.png clut.png -fx "v.p{0,u*v.h}" output_cmd.png
Code: Select all
<?php
# load input file and color lookup file in a sequence
$im = new Imagick(array('input.png', 'clut.png'));
# apply fx operator (can't use clutImage for backwards compatibility)
$im->fxImage("v.p{0,u*v.h}");
# write output file
$im->writeImage('output_php.png');
I know there's a clutImage method specifically for this, but one of the environments I'm targeting for this has an older version of Imagemagick, so I wanted this for backward compatibility.
UPDATE: The reason fxImage seemed to be doing nothing was that I didn't realize it returns a new Imagick object rather than modifying the existing one. With that moment of stupidity realized, I grabbed the return value of the fxImage method, which seemed to be returning the expected image, but cropped to the dimensions of the color lookup table.
Code: Select all
# apply fx operator (can't use clutImage for backwards compatibility)
$im = $im->fxImage("u.p{0,v*u.h}");
Code: Select all
# load input file and color lookup file in a sequence
$im = new Imagick(array('clut.png', 'input.png'));
Code: Select all
# apply fx operator (can't use clutImage for backwards compatibility)
$im = $im->fxImage("u.p{0,v*u.h}");