It is possible to use IM for this, but with limitations (see below). This Windows script specifies a curve from two segments. The curve looks like one that might be created in Gimp or Photoshop, but my own interest is in programmatic generation of curves. The script uses IM to make a visualisation of the curve, and then to make a one-dimensional file for CLUTting against an image.
Code: Select all
set seg1=-draw "stroke White fill None bezier 0,4000 0,0 400,2800 800,3200"
set seg2=-draw "stroke White fill None bezier 800,3200 1600,4000 3999,1600 3999,0"
set curve=%seg1% %seg2%
set SQDIM=4000
rem Create curveL.tiff, just so we can see the curve.
rem
"%IMG%convert" ^
-size %SQDIM%x%SQDIM% xc:Black ^
+antialias ^
%curve% ^
curveL.tiff
rem Create one-dimensional curveClut.tiff, to be used as a clut file.
rem
"%IMG%convert" ^
-size %SQDIM%x%SQDIM% gradient: ^
( -size %SQDIM%x%SQDIM% xc:Black ^
+antialias ^
%curve% ^
-alpha off ^
) ^
-compose CopyOpacity -composite ^
-resize "%SQDIM%x1^!" ^
-alpha off ^
curveClut.tiff
"%IMG%identify" curveClut.tiff
"%IMG%convert" ^
rose: ^
curveClut.tiff ^
-clut ^
roseClutted.tiff
1. I would like 16-bit precision, but my computer is too small to handle images of 64k x 64k pixels.
2. The generated curve sometimes has two pixels in the vertical dimension, so the resize will take an average of the two values. This is reasonable behaviour, but raises the question of how to get the maximum precision from the process. I don't know enough about how IM resizes with transparency. Perhaps "-antialias" would give a more correct result.
3. For the example, I specify the curves with Bezier control points. These can of course be generated from more user-friendly parameters, while ensuring the curve doesn't contain multiple y-values for any x-value.
If IM contained this as a built-in facility, it could have full 16-bit precision without needing to generate 64k x 64k files. It would be nice to see this, perhaps in V7.