Page 1 of 1

clut convert question

Posted: 2011-04-14T08:03:44-07:00
by papoola
Hello everyone!

I would like to use -clut parameter to adjust color correction for pictures using a gradient image of 256x1.

For making a standard gradient image without correction I use:

Code: Select all

convert -size 1x256  gradient: -rotate 90  gradient.png
Since there are variation of different color correction I would like to make gradient.png using user defined RGB values. So pixel y:1 should have R:23 G:12 B:43 for example and pixel y:2 should have R:10 G:34 B:100 ... until y:256.

Is there a way to call convert from my software to make this gradient?

Re: clut convert question

Posted: 2011-04-14T09:46:31-07:00
by fmw42
Since there are variation of different color correction I would like to make gradient.png using user defined RGB values. So pixel y:1 should have R:23 G:12 B:43 for example and pixel y:2 should have R:10 G:34 B:100 ... until y:256.
Can you explain the algorithm you use to increment each R,G,B color along the 256 pixels? Or is it specially chosen for each pixel?

You could create a table of R,G,B color values as 3 arrays, then use one of the NetPBM formats to create three grayscale images from the arrays, combine them into one color image of length 256 and then convert to png.

See Anthony's Examples on NetPBM at http://www.imagemagick.org/Usage/formats/#netpbm

Re: clut convert question

Posted: 2011-04-14T15:19:16-07:00
by papoola
hi fmw42,

Thank you for your quick response!

There is no special algorithm, I would like to specify each RGB values for all 256 pixels of gradient.png and then clut. NetPBM looks like exactly the right solution I was looking for. Could you just tell me how to enter RGB values as 3 arrays and combine? Is it possible to have creation of gradient.png and applying clut all in one convert call? That would be fantastic.

Re: clut convert question

Posted: 2011-04-14T16:56:31-07:00
by fmw42
I am not all that expert with NetPBM and don't see a way to create the clut image and apply it all in one command. You will need to create a list of 256 red values, a list of 256 green values and a list of 256 blue values. Or create a list of rgb values that can then be parsed via unix commands to separate into 3 lists (or arrays). Then use the example from Anthony's page http://www.imagemagick.org/Usage/formats/#netpbm to create a grayscale 256x1 image for each of red, green, then blue. Then combine them together into one colored 256x1 image (-combine). Then use that image with your original image and -clut to process it.

For example, suppose you have only 10 values (rather than 256) in the range 0 to 255.

redlist="0 4 10 50 90 30 140 240 200 255"
echo "P2 10 1 255 $redlist" | convert - redlut.gif

NOTE: P2 10 1 255 represents PGM Code (P2), width of lutimage (i.e. number of values) (10), height of lutimage (1), maximum graylevel (255).
see http://netpbm.sourceforge.net/doc/pgm.html


similar for greenlist and greenlut.gif and for bluelist and bluelut.gif

then

convert image \( redlut.gif greenlut.gif bluelut.gif -combine \) -clut resultimage


Alternately, you can make a list or file of r,g,b values (one set per row). Then read the file and process it into 3 lists (or arrays) and do as above.

For example, you create a file called colortable.txt that looks as follows:

10,50,100
25,90,30
200,50,75

where each row is r,g,b values

Then to convert to lists for use as above:

redlist=`cat colortable.txt | cut -d, -f1`
greenlist=`cat colortable.txt | cut -d, -f2`
bluelist=`cat colortable.txt | cut -d, -f3`
echo "P2 10 1 255 $redlist" | convert - redlut.gif
echo "P2 10 1 255 $greenlist" | convert - greenlut.gif
echo "P2 10 1 255 $bluelist" | convert - bluelut.gif
convert image \( redlut.gif greenlut.gif bluelut.gif -combine \) -clut resultimage


Anthony may have a more compact and more elegant solution, if he sees this post as he is the NetPBM expert.

Re: clut convert question

Posted: 2011-04-14T21:21:56-07:00
by anthony
That seems to be a fine solution.

The clut lookup use purely by value (except when handling alpha, and no alpha channel is present in one of the images) As such the input red value looks up the replacement red value in the CLUT image.

That is it.

Re: clut convert question

Posted: 2011-04-15T01:13:15-07:00
by papoola
Thank you very much guys, I am gonna give it a try and let you know!

Re: clut convert question

Posted: 2011-04-15T07:10:52-07:00
by anthony
Note if you have a grayscale CLUT image, you can specify what channels it will be applied to using the -channel setting. Grayscale images remember have the same red, green, and blue RGB values.

That assumes the RGB is used for both images, really the same colorspace should always be used for both images.