Getting CMYK pixel values in 0 to 100 format.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Tripleseven
Posts: 3
Joined: 2016-04-20T07:22:35-07:00
Authentication code: 1151

Getting CMYK pixel values in 0 to 100 format.

Post by Tripleseven »

Hello.

I'm trying to create a tool to analyze an image and getting a count of pixels by color.
I'm using the following script:

convert.exe image.jpg -format %c histogram:info:

results are
50: ( 0, 0, 0,253) #000000FD cmyk(0,0,0,253)
50: ( 0, 0, 0,250) #000000FA cmyk(0,0,0,250)
50: ( 0, 0, 0,248) #000000F8 cmyk(0,0,0,248)
50: ( 0, 0, 0,245) #000000F5 cmyk(0,0,0,245)

i then use this data in an external program to build a "color map", that gives me a area percentage by color.

It returns the information i need, except that cmyk values come in a 0 to 255 format, that i'm not used to work with.
How can i modify the script so that color values come in their intervals:

rgb: 0 to 255
grayscale: 0 to 255
cmyk: 0 to 100
...

Using ImageMagick 6.9.0-6 Q16 x86, in windows

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting CMYK pixel values in 0 to 100 format.

Post by snibgo »

As far as I know, there is no mechanism for changing the %c format. Your software that reads the data can multiply the numbers by 100.0/255.0.

Annoyingly, the %c numbers are relative to Quantum, which might be 255 or 65535 or 2^32-1 or 2^64-1. If you precede the format with "-depth 16", it will always be 65535.
snibgo's IM pages: im.snibgo.com
Tripleseven
Posts: 3
Joined: 2016-04-20T07:22:35-07:00
Authentication code: 1151

Re: Getting CMYK pixel values in 0 to 100 format.

Post by Tripleseven »

snibgo wrote:As far as I know, there is no mechanism for changing the %c format. Your software that reads the data can multiply the numbers by 100.0/255.0.

Annoyingly, the %c numbers are relative to Quantum, which might be 255 or 65535 or 2^32-1 or 2^64-1. If you precede the format with "-depth 16", it will always be 65535.
Thanks for you reply.

I'd already tried to multiply the numbers by 255/100, but rounding to the nearest integer sometimes results in having the same value for different colors.
For the sake of accuracy, i would like to have exact CMYK values, but maybe there's no way to do it with IM.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting CMYK pixel values in 0 to 100 format.

Post by fmw42 »

Whatever software you are using that has 0 to 100 as integers for CMYK is giving you less accuracy than if 0 to 255. If you need to scale down to 0 to 100 integers, then you will have to scale and combine bins. That is a scripting job. I believe snibgo is correct. One has no control over the "%c" histogram format.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting CMYK pixel values in 0 to 100 format.

Post by snibgo »

Tripleseven wrote:I'd already tried to multiply the numbers by 255/100...
I hope you mean you tried multiplying by 100/255.
Tripleseven wrote:... but rounding to the nearest integer sometimes results in having the same value for different colors.
Then don't round to integers.

If there are 256 possible input values and only 100 possible output values, obviously some inputs will have the same outputs.
snibgo's IM pages: im.snibgo.com
Tripleseven
Posts: 3
Joined: 2016-04-20T07:22:35-07:00
Authentication code: 1151

Re: Getting CMYK pixel values in 0 to 100 format.

Post by Tripleseven »

snibgo wrote: I hope you mean you tried multiplying by 100/255.
Sorry, i meant 100/255
snibgo wrote: Then don't round to integers.

If there are 256 possible input values and only 100 possible output values, obviously some inputs will have the same outputs.
I know. It would just be easier to match the colors with the ones in the artwork. The drawing program we use (Corel) only allows CMYK colors in 0-100 integers range.

Thanks for all your help
Post Reply