Page 1 of 1

specify rgb values

Posted: 2010-11-08T22:12:16-07:00
by kelvin
Hello,

we have scenario that we need to convert the images into 16 bits. we used the command -depth 16. what we understood is it is converting 16 bits per channel. what we need is total 16 bits. like 5,6,5 format. is there any way to specify rgb values like 5,6,5 for the image?


I have already posted in the fourm regarding 16 bit conversion colour reduce.
viewtopic.php?f=2&t=17395

I tried the following option.

convert rose.png[1x1+10+10] -format "%[fx:int(255*r)],%[fx:int(255*g)],%[fx:int(255*b)]"

But i am getting some error like

convert: option requires an argument `-format' @ error/convert.c/ConvertImageCom
mand/1488.


Thanks
Kelvin.

Re: specify rgb values

Posted: 2010-11-08T23:57:38-07:00
by jpiquemal
Hi

Try with ', not "

Re: specify rgb values

Posted: 2010-11-09T00:47:21-07:00
by kelvin
Hi thanks for the reply.. I tried by removing' [,]. Still the same error producing.

I tried in the following two ways.

convert rose.png[1x1+10+10] -format "%[fx:int(255*r)]%[fx:int(255*g)]%[fx:int(255*b)]"


convert rose.png[1x1+10+10] -format %[fx:int(255*r)]%[fx:int(255*g)]%[fx:int(255*b)]

Re: specify rgb values

Posted: 2010-11-09T02:01:23-07:00
by kelvin
I got the answer.
I missed the filename..

Re: specify rgb values

Posted: 2010-11-09T11:52:47-07:00
by fmw42
you need to add "info:" at the end of such a command when you have used -format

convert image -format "%[fx:...]" info:

If you want -fx to process an image and make an output, then the syntax is

convert image -fx "...." result

see

http://www.imagemagick.org/Usage/transform/#fx_escapes
http://www.imagemagick.org/script/fx.php

Re: specify rgb values

Posted: 2010-11-09T18:05:54-07:00
by anthony
Getting back to your original problem...

For a 5,6,5 format what you want is to 'posterize' the image to a specific number of 'levels'. But -posterize will not do the job.

However the -ordered-dither option has a special minimal threshold pattern actually known as 'threshold', whcih can be combined with its 'levels' capability.

First a test image (three channel gradients)

Code: Select all

    convert -size 20x640 gradient:red-black gradient:lime-black \
                                             gradient:blue-black gradient: \
                +append -rotate 90 color_gradients.png
Image

Now apply ordered dither threshold with the number of color levels wanted,
For example a 2,3,2 (7 bit) image, where 2^2 => 4 and 2^3 => 8

Code: Select all

  convert color_gradients.png -ordered-dither threshold,4,8,4  color_232.png
Image

Of course this gradient image does not show ALL the posible colors that could be generated.

But it also shows the biggest drawback of this technique... you do not get any pure gray colors, other than black and white!

For your 5,6,5 16 bit image you would use 2^5 => 32 and 2^6 => 64

Code: Select all

 convert color_gradients.png -ordered-dither threshold,32,64,32  color_565.png
Image

For more information see
Ordered Dither using Uniform Color Levels
http://www.imagemagick.org/Usage/quantize/#od_posterize


If you are just wanting to list the colors use the power of 2 values in your info.

Code: Select all

convert rose.png[1x1+10+10] -format "%[fx:int(32*r)],%[fx:int(64*g)],%[fx:int(32*b)]"  info:
9,16,7
Note the multiplier. It seems FX color values are not actually 0.0 to 1.0 inclusive. It will not actually use a value of exactly 1.0 for maximum intensity. Probably as that makes the conversions from floats to scaled integers, VERY VERY hard to get right. If you want to discuss this make it a separate topic.

IM currently does not provide a number formatter for FX escape output, so if you want these values as a 16 bit hexadecimal number you need to output it as a decimal value and convert to hex. For example using the "printf" command...

Code: Select all

printf 0x'%04X\n'  `convert rose.png[1x1+10+10] \
         -format "%[fx:(int(32*r)<<11)|(int(64*g)<<6)|int(32*b)]"  info: `
0x4C07

Re: specify rgb values

Posted: 2010-11-09T18:30:27-07:00
by anthony
Aside. Why are you using a 5,6,5 color map? Normally such colormaps assign the odd color to the blue channel as it is the color our eyes has the least amount of distinction. As such the odd colors (yellow and blueish colors) seem to blend together more than the purple/green colors you get using the green channel for the extra colors.

As such I would have expected you to use a 5,5,6 colormap for 16 bit 'direct color' color mapping.