Problem combining CMYK images

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
leonardord
Posts: 2
Joined: 2012-07-26T13:50:04-07:00
Authentication code: 15

Problem combining CMYK images

Post by leonardord »

Hello

I have been trying to combine 2 CMYK images and a mask using version 6.7.4 Q16 of ImageMagick (Windows), but the resulting image colors are distorted, almost always a dark gray tone.

Here is how to reproduce the problem:

1-Generate the background:

Code: Select all

convert -size 400x400 xc:black -colorspace CMYK background.miff
2-Generate the image:

Code: Select all

convert -size 400x400 xc:yellow -fill green -draw "rectangle 100,100 300,300" -colorspace CMYK color.miff
3-Generate the mask:

Code: Select all

convert -size 400x400 xc:white -fill white -stroke black -draw "rectangle 100,100 300,300" -type Bilevel mask.miff
4-Combine images:

Code: Select all

convert background.miff color.miff mask.miff -composite result.jpg
The expected result would be a yellow canvas containing a green square with a black border around it, however I get a black canvas with a dark gray square and a light gray border.
Could someone tell me if I'm doing something wrong?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem combining CMYK images

Post by fmw42 »

I am not sure how well of if -composite works with cmyk. It may be fine. I am not an expert on cmyk. But try this

convert background.miff color.miff mask.miff -set colorspace CMYK -composite result.jpg

see
http://www.imagemagick.org/Usage/color_ ... bine_other
leonardord
Posts: 2
Joined: 2012-07-26T13:50:04-07:00
Authentication code: 15

Re: Problem combining CMYK images

Post by leonardord »

I did try using the -set colorspace CMYK option, but the result was unchanged.
I think this link refers to the -combine option, which combines all channels of the image. I am trying to make an alpha composition using a mask (both images are opaque, what is really important is the mask), so from what I understand the -composite option is the one I should use.

This problem only occurs when both the background and the image are CMYK. If I convert the background to RGB, the images are merged correctly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem combining CMYK images

Post by fmw42 »

This problem only occurs when both the background and the image are CMYK. If I convert the background to RGB, the images are merged correctly.
Why don't you convert both input images to RGB, do the composite, and then you can use -colorspace CMYK at the end to convert the result if so desired.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem combining CMYK images

Post by anthony »

CMYK separates the color channels in a very strange non-linear, and discontinuious way. That is, black is subtracted from the other three of the color channels such that at least one of the color channels is always zero!!!

This makes it unsuitable for direct composition.

It is however so closely related to linear RGB (without even any floating point rounding effects!) that you may as well do the job in linear RGB.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply