applying a mask to 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
beowulf

applying a mask to cmyk images

Post by beowulf »

Hi everybody,

I'm facing a big colorspace problem for quite a while now and couldn't get any good results, so I try finding some tips here.

What I want to achieve:

I've got an image (438x438px) to which I want to apply a circle mask (b/w - 438x438px). The mask has a black circle (RGB0,0,0 representing the transparent area), the edges around the circle are white (RGB255,255,255 background color). I use the following command line options to achieve the desired result:

Code: Select all

convert mask.jpg source.jpg -compose Screen -composite result.jpg
(as described on http://www.imagemagick.org/Usage/channels/)


For RGB images everything works just fine, the mask is applied and the colors are preserved.

Now, the problem is with CMYK images (mask CMYK0,0,0,100% and source.jpg CMYK). If I just use the above listed command, I simply get the mask as result showing just the black circle.

If I add the option "-colorspace cmyk" I get the image masked with the circle as planned, but all colorinformation seems to be gone, the image is b/w.

Code: Select all

convert mask.jpg source.jpg -compose Screen -colorspace cmyk -composite result.jpg

If I try to use an icc profile instead of the colorspace option, the result gets even worse, the circle is nearly filled black, I can vaguely discern the outlines of source.jpg.

Code: Select all

convert mask.jpg source.jpg -compose Screen -profile ISOcoated(...).icc -composite result.jpg



If I then add the option "colorspace cmyk" again, the result gets a little bit better, but still the colors are not nearly the same as in the source.jpg. The image looks a little bit darker than the original and the colors are palish, showing a tendency towards black/white.

Code: Select all

convert mask.jpg source.jpg -compose Screen -profile ISOcoated(...).icc -colorspace cmyk -composite result.jpg



What can I do to get the desired result? With colorspace RGB everything works fine, with CMYK I can't find any way to achieve the masked image with original colors.
Besides: Doing the masking in RGB colorspace and converting then to CMYK would work but is not an option because the colors of the resulting image are not the same as in the original image.


Are there any other ways to apply a mask to an image which might work better with CMYK images? I read something about round thumbnails, there they are using -matte options and CopyOpacity and stuff like that, but I wasn't able to get any masked image using these commands.

Am I missing something in my way of doing it? Any option which will help to preserve the color informations?


I'm also trying to play around with an alpha channel added to one of the cmyk images. But I'm not really familiar with this matter. If I apply an alpha channel (circle shape) to the mask.jpg using photoshop 5.x I no longer can save it as jpg (nor as tif).
In addition my imagemagick version (6.1 IIRC) seems to not supporting the cmyka colorspace. If I just try to perform:

Code: Select all

convert mask.jpg source.jpg -compose Screen -colorspace cmyka -composite result.jpg


... imagemagick tells me that the colorspace cmyka is not supported.




I'm looking forward to receive any tip whatsoever. I'm really stuck here and playing around for days now. :(
I have to work with CMYK colorspace because I'm working on a print-job-project where the masked image is part of a PDF-creation. These pdfs are then printed out in some kind of book and the print office just needs CMYK images to prevent being forced to apply an icc profile as stated above (resulting in slight color changes).

Thanks in advance!

P.S. I will try to link some result images here tomorrow.
beowulf

Re: applying a mask to cmyk images

Post by beowulf »

So, I hurried up a little bit. Here are some images for demonstration:

first, the CMYK source image:

source.jpg (CMYK)

The CMYK mask:

mask.jpg (CMYK)

convert mask.jpg source.jpg -compose Screen -composite result_1.jpg

result_1.jpg (CMYK)

convert mask.jpg source.jpg -compose Screen -colorspace cmyk -composite result_2.jpg

result_2.jpg (CMYK)

convert mask.jpg source.jpg -compose Screen -colorspace cmyk -profile ISOcoated_v2_300_eci.icc -composite result_3.jpg

result_3.jpg (CMYK) (ca.2MB)

convert mask.jpg source.jpg -compose Screen -profile ISOcoated_v2_300_eci.icc -composite result_4.jpg

result_4.jpg (CMYK) (ca.2MB)



Interesting that this source.jpg shows a slightly different color "behaviour" than the one I described above in the first post.
But it is also clear that the colors are not in any way similar to the ones of the original image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: applying a mask to cmyk images

Post by anthony »

Your request is rather verbose. Try re-sumbiting it with a short and consise query
with images, and you may get a better response.

Also when applying alpha composition it is important that images have the same color space representation in memory or unexpected results can happen.

It is probably the case that IM should look for colorspace mismatches like this, but currently it makes the assumtion that you know what you are doing.
... imagemagick tells me that the colorspace cmyka is not supported.
That is probably a bug and should be reported to bugs forum.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply