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.