Page 1 of 1

Combining Channel Images with custom colors

Posted: 2015-08-04T10:30:40-07:00
by mogadanez
I have set of grayscale ( negated?? see command bellow ) images, img_0 .... img_7
where first 4 is CMYK channels, and rest is custom spot colors channels.

I can combine CMYK channels with

Code: Select all

convert img_?.png  -set colorspace CMYK  -negate -combine  -colorspace RGB  result.png
it requires -negate option, without it result is very black.

I need 2 things:
1. Somehow split this command to separate CMYK channels to able combine them in different combinations

i'm trying follow command

Code: Select all

convert img_0.png -negate -colorspace CMYK img_0.png -compose CopyCyan  -composite img_1.png -compose CopyMagenta  -composite empty.png -compose CopyYellow   -negate  -composite -colorspace RGB   _result.png
it is more or less works, but there is 2 problems:
* need specify empty.png for skipped channel
* cant add black channel in such manner, result becomes black.
maybe more elegant solution present?

2. add to compose rest of channels with custom colors where colors defined as cmyk or rgb values.
here I have no ideas at all.

Re: Combining Channel Images with custom colors

Posted: 2015-08-04T10:40:01-07:00
by snibgo
A sample set of input images would help. Also say what the spot colours are. Preferably also an sRGB version of what the complete image should look like.

EDIT: In your commands, "-colorspace sRGB" would be better than "-colorspace RGB".

Re: Combining Channel Images with custom colors

Posted: 2015-08-04T11:47:49-07:00
by mogadanez
image set: https://www.dropbox.com/sh/984qvm7z2qrw ... iDxza?dl=0
img_x.png - sources
spotcolors - result I want to achieve when all channels is enabled, or combination of boxes when only part of channels used.

last example, worked more or less fine with basic CMYK boxes:

Code: Select all

convert img_3.png -negate -colorspace CMYK \  
img_0.png -compose CopyCyan  -composite \
img_1.png -compose CopyMagenta  -composite \
empty.png -compose CopyYellow  -composite \
-negate -colorspace sRGB   _result.png
I put black layer as first image, and use empty( white image ) to toggle out layers

spot colors can be any, initially it is usually PANTONE colors, but I have CMYK or RGB analogs for each one, that is fine for me.
I understand that it not exact as original, but in my case it is fine.
so lets say that
img_4 => rgb(0, 94, 79)
img_4 => rgb(97, 96, 167);
img_4 => rgb(229, 76, 60)

Re: Combining Channel Images with custom colors

Posted: 2015-08-04T12:36:26-07:00
by snibgo
Okay, good. The file "spotcolors.png" doesn't contain pure cyan, magenta, yellow or even black. It doesn't even have pure white. So I suppose you want those colours in the output, instead of the pure colours. Is that correct? If it is correct then a simple sRGB->CMYK conversion won't work. You really have seven spot colours, four being roughly (but not exactly) cyan, magenta, yellow and black. A script would need to build the output using values from spotcolors.png.

The input files img_*.png contain only black and white, with no grays. Will this always be true?
img_4 => rgb(0, 94, 79)
img_4 => rgb(97, 96, 167);
img_4 => rgb(229, 76, 60)
I don't understand this. I suppose you mean images 4, 5 and 6, but the rgb values are not in the file (as reported by Gimp).

Re: Combining Channel Images with custom colors

Posted: 2015-08-04T15:01:15-07:00
by mogadanez
https://www.dropbox.com/s/ll43uiikkmf34 ... 1.pdf?dl=0
this is source pdf. I can export separations as gray-scales.
now I need to make preview like in acrobat preview based on this grayscales

Re: Combining Channel Images with custom colors

Posted: 2015-08-04T15:47:28-07:00
by snibgo
Okay. I'll assume you want pure white, cyan, magenta, yellow and black, but the bottom three should be spotcolours I've taken from "convert spotcolors.pdf sc.png":

rgb(100%,12%,9%)
rgb(7% 27% 11%)
rgb(15% 20% 100%)

I assume the inputs are black where you want the colour, white otherwise, with no gray. Windows BAT syntax:

Code: Select all

%IM%convert ^
  img_0.png img_1.png img_2.png  ^
  -combine ^
  img_3.png ^
  ( img_6.png -fill rgb(100%%,12%%,9%%) -opaque Black ) ^
  ( img_4.png -fill rgb(7%%,27%%,11%%) -opaque Black ) ^
  ( img_5.png -fill rgb(15%%,20%%,100%%) -opaque Black ) ^
  -compose Darken -layers merge ^
  spotcolors_out.png
Image

Re: Combining Channel Images with custom colors

Posted: 2015-08-05T02:02:06-07:00
by mogadanez
Nice, thank you,
last question - how to turn out single layers?
with spot colors its pretty easy - just removing it's line.
but how to turn out single color from base CMYK ?

Re: Combining Channel Images with custom colors

Posted: 2015-08-05T03:39:08-07:00
by snibgo
At each pixel, when colors overlap, only the darker color is used, so spot colors lighter than magenta won't overwrite magenta. If you want to ensure that later colors in the command overwrite earlier colors, use " -transparent White -compose Over -layers merge" instead of "-compose Darken -layers merge".

In my command, black acts like a spot color, overwriting any C M or Y values in the pixel.

If you don't want black, just remove img_3.png from the command.

If you don't want C or M or Y, you need to replace it with a white image of the same size. For example, this removes the magenta layer:

Code: Select all

%IM%convert ^
  img_0.png ^
  ( img_1.png -fill White -colorize 100 ) ^
  img_2.png  ^
  -combine ^
  img_3.png ^
  ( img_6.png -fill rgb(100%%,12%%,9%%) -opaque Black ) ^
  ( img_4.png -fill rgb(7%%,27%%,11%%) -opaque Black ) ^
  ( img_5.png -fill rgb(15%%,20%%,100%%) -opaque Black ) ^
  -transparent White ^
  -compose Over -layers merge ^
  spotcolors_out.png

Re: Combining Channel Images with custom colors

Posted: 2015-08-06T04:21:44-07:00
by mogadanez
It works on previous sample but not for more complex images.
see:
https://www.dropbox.com/sh/fh2i1vu4604l ... SBkia?dl=0

i use command

Code: Select all

convert ^
  -size 512x512 xc:white ^
  -size 512x512 xc:white ^
  -size 512x512 xc:white ^
  -combine ^
( img1.png -fill rgb(0,175,235) -opaque Black ) ^
( img2.png -fill rgb(236,40,144) -opaque Black ) ^
-compose Darken -layers merge ^
out.png
and get
Image

but i'm expect( aprox, another crop, see on colors only ):
Image


any suggestions?

Re: Combining Channel Images with custom colors

Posted: 2015-08-06T05:19:05-07:00
by snibgo
Upthread I said:
snibgo wrote:The input files img_*.png contain only black and white, with no grays. Will this always be true?

I assume the inputs are black where you want the colour, white otherwise, with no gray.
But your inputs have gray, so we need "+level-colors". As you have no pure cyan, yellow or magenta, the first few lines are not needed.

Code: Select all

convert ^
  ( img1.png +level-colors rgb(0,175,235),White ) ^
  ( img2.png +level-colors rgb(236,40,144),White ) ^
  -compose Darken -layers merge ^
  im2_out.png
Image

Re: Combining Channel Images with custom colors

Posted: 2016-06-24T14:33:04-07:00
by peter01242
I am trying to combine CMYK and a Pantone(TM) spot color into a composite PNG image as part of a project I am working on for my employers.

I am using the following command-line script although I intend to port it to Magick++ in a standalone utility once I have the behavior sorted:

Code: Select all

convert -set colorspace CMYK "spot(Cyan).png" "spot(Magenta).png" "spot(Yellow).png" "spot(Black).png" -negate -combine ^
-colorspace CMYK ^
-compose add ^
( "spot(PANTONE 282 U).png" -negate -opaque cmyk(255,173,0,138) -transparent cmyk(0,0,0,0) ) -composite ^
-layers merge ^
"composite.png"
This is pretty close to what I need, but the spot color is always appearing as black instead of the color I specify (a royal blue) for the -opaque command.
I have tried using the -level-colors and +level-colors options but have yet to find a combination that produces the correct color in the final image.

Here is a link to a DB folder containing the source PNG images. These were resampled from the original 800 dpi TIFF images at 300 dpi.

https://www.dropbox.com/sh/oi5x2kidlzvj ... EhM7a?dl=0

Any suggestions greatfully received.
Thanks,

Pete Y
Xitron LLC

Re: Combining Channel Images with custom colors

Posted: 2016-06-24T15:41:17-07:00
by snibgo
If I format your command like this:

Code: Select all

%IM%convert ^
  -set colorspace CMYK ^
  "spot(Cyan).png" "spot(Magenta).png" "spot(Yellow).png" "spot(Black).png" ^
  -negate -combine ^
  -colorspace CMYK ^
+write x.tiff ^
  -compose add ^
  ( "spot(PANTONE 282 U).png" -negate -opaque cmyk(255,173,0,138) -transparent cmyk(0,0,0,0) ^
+write x2.tiff ^
  ) ^
  -composite ^
  -layers merge ^
  "composite.png"
x.tiff is a CMYK file, and it looks fine. I don't understand what you want to do with "spot(PANTONE 282 U).png". This image is mostly white, with some black at bottom-left. It doesn't contain any colour "cmyk(255,173,0,138)". The result, x2.tiff, is sRGB (not CMYK), with some opaque white but mostly transparent black.

You then composite this sRGB image on the CMYK image, with the "add" method.

Composing images of different colourspaces is a bad idea. I suggest you make them both sRGB or both CMYK.

Note the output is type .PNG. This can't store CMYK, so IM will convert the image to sRGB.

Re: Combining Channel Images with custom colors

Posted: 2016-06-24T16:59:30-07:00
by peter01242
Thanks for the quick response.
The 5 source PNGs are the individual colors for the final image (there are actually 6) but I decided to get 1 working then add the other after.
The source PDF is now in the DB folder as well for reference.
The original source files are 1-bit TIFF and I subsampled them to PNG using:

Code: Select all

mogrify -format png -resample 300 -depth 8 spot*.tif
None of the PNGs contain any 'color' - they are all 8-bit grayscale.
The effect I am trying to achieve is that the CMYK combine to form the base 32-bit image and then I composite on top of that the spot color replacing 255 across the CMYK planes with cmyk(255,173,0,138) and 0 with cmyk(0,0,0,0) or even better Transparent or None.

Code: Select all

convert -set colorspace CMYK "spot(Cyan).png" "spot(Magenta).png" "spot(Yellow).png" "spot(Black).png" -negate -depth 8 -combine ^
-colorspace CMYK ^
-compose add ^
( "spot(PANTONE 282 U).png" -negate +level-colors Transparent,cmyk(255,173,0,138) ) -composite ^
( "spot(PANTONE 429 U).png" -negate -level-colors Transparent,cmyk(8,0,0,82) ) -composite ^
-layers flatten ^
"composite.png"
This gives me a result closer to that required but the spot colors are not correct.
In the DB folder is a Color Comparison.PNG: http://www.dropbox.com/s/6o20g36uu6rouz ... n.PNG?dl=0

On the left is the source PDF as seen in Acrobat Reader - note the light grey and dark blue colors at the bottom.
On the right is the result of the above code - note the black and bright blue colors at the bottom.
The light grey equates to the Pantone 429 and the dark blue is the Pantone 282.
The CMYK values (255,173,0,138) and (8,0,0,82) when viewed in a Color Tool show the appropriate colors (light gray and dark blue), so I can only assume that there is some 'magic' formula I am missing in the code above that is causing IM to generate incorrect colors.

Pete Y

Re: Combining Channel Images with custom colors

Posted: 2016-06-24T18:05:17-07:00
by snibgo
So, where "spot(PANTONE 282 U).png" is black you want the output to be over-written with blue, is that correct?

"-compose Add" adds pixels values, but you want to replace them, so "-compose Over". Your "-layers flatten" does nothing.

I think this does what I think you want:

Code: Select all

%IM%convert ^
  -set colorspace CMYK ^
  "spot(Cyan).png" "spot(Magenta).png" "spot(Yellow).png" "spot(Black).png" ^
  -negate -combine ^
  -colorspace CMYK ^
+write x.tiff ^
  ( "spot(PANTONE 282 U).png" ^
    -transparent White ^
    -set colorspace CMYK ^
    -fill cmyk(255,173,0,138) -opaque cmyk(0,0,0,0) ^
+write x2.tiff ^
  ) ^
  -compose Over -composite ^
  "c2.png"
When this does what you want, the two "+write" commands can be removed.

Re: Combining Channel Images with custom colors

Posted: 2016-06-24T19:15:06-07:00
by peter01242
Thanks for all the help, I think I have a handle on it now.
Here is what I am using:

Code: Select all

%IM%convert ^
  -set colorspace CMYK ^
  "spot(Cyan).png" "spot(Magenta).png" "spot(Yellow).png" "spot(Black).png" ^
  -negate -combine ^
  -colorspace CMYK ^
  -compose Add ^
  ( "spot(PANTONE 282 U).png" -transparent White -set colorspace CMYK -fill cmyk(255,173,0,138) -opaque cmyk(0,0,0,0) ) -composite ^
  ( "spot(PANTONE 429 U).png" -transparent White -set colorspace CMYK -fill cmyk(8,0,0,82) -opaque cmyk(0,0,0,0)  ) -composite ^
  "composite.png"
  
There is a Color Comparison 2.PNG in the DB folder that shows how close I can get.
http://www.dropbox.com/s/0a2k7szgmx4ec ... .PNG?dl=0
This is for thumbnail generation so exact matching is not a required.

Thanks again,
Pete Y