Page 1 of 1

Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T03:05:24-07:00
by R4C3R
I try to combine two CMYK based images into one image. The first image serves as background, the 2nd image as overlay. However, from the second image I only want to use pixels that have a certain pre-defined colour.

image1.jpg JPEG 7121x1434 7121x1434+0+0 8-bit CMYK 918KB 0.000u 0:00.000
image2.eps EPT 6008x298 6008x298+0+0 16-bit ColorSeparation CMYK 7.162MB 0.000u 0:00.000

from image2 I only want to use pixels with CMYK colour 60 30 20 80 for the overlay.

the images should be center aligned (-gravity center)

How can this be accomplished using imagemagick?

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T06:03:47-07:00
by snibgo
I think you want to composite the second image over the first, but only after making other colours transparent, like this:

Code: Select all

magick in1.jpg ( in2.jpg -alpha set -fuzz 0.5% +transparent icc-color(cmyk,0,0,0,0) ) -composite out.jpg
The icc-color numbers are in the range 0.0 to 1.0. I'm not sure how you would specify 60 30 20 80 which I assume are out of 255.

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T07:04:58-07:00
by R4C3R
I'm also unsure about the icc-colours & CMYK relation.

The second image has only two colours, CMYK 60 30 20 80 and white. Maybe this information helps solving the problem.

What I used sofar was:

Code: Select all

composite -compose multiply image2.eps -gravity center image1.jpg output.jpg
But the colours CMYK of output.jpg seem to be slightly different from the image2.jpg, probably because it is the result of a pixel multiplication process of both images.

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T08:16:40-07:00
by snibgo
What version of IM, on what platform?

I suggest you don't use the "composite" command. Instead, use "convert" in v6 or "magick" in v7, with a "-composite" option.

Why are you multiplying pixels?

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T08:41:06-07:00
by R4C3R
I'm using

Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org

on

Ubuntu 18.10 LTS

I multiplied the pixels because optically it came close to what I was looking for. Image2 has only two colours white and CMYK 60 30 20 80 (which comes close to black)

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T09:15:13-07:00
by snibgo
If image2 has only white and some other colour, and you don't want the white copied, then...

Code: Select all

convert in1.jpg ( in2.eps -alpha set -transparent icc-color(cmyk,0,0,0,0) ) -composite out.tiff
I write to tiff instead of jpg because tiff is by default lossless.

Re: Copy a certain CMYK color from one image to another image

Posted: 2019-04-19T09:35:15-07:00
by R4C3R
This command does the trick for me, everything in image 2 that is white (cmyk,0,0,0,0) is made transparant before using image2 as an overlay on top of image1:

Code: Select all

convert image1.jpg -gravity center \( image2.eps -alpha set -transparent icc-color\(cmyk,0,0,0,0\) \) -composite output.tiff
Thank you for all your support!

PS:

Finding 1) I also found out that imagemagick reports the CMYK colours on a scale from 0 to 255. The CMYK colour I was using (60 30 20 80) translated to image magicks definition of CMYK as cmyk,153,76,51,204

To determine the colour of a certain pixel I used the following command:

convert image2.tiff -format '%[pixel:p{1,149}]' info:-;echo

with the following result: cmyk(153,76,51,204), the same pixel is reported in Photoshop as CMYK 60,30,20,80.

Finding 2) However converting the command like this (making everything transparant that has not the pre-defined cmyk colour) didn't work for some reason.

Code: Select all

convert image1.jpg -gravity center \( image2.eps -alpha set +transparent icc-color\(cmyk,153,76,51,204\) \) -composite output.tiff