Page 1 of 1

CMYK Color Conversion

Posted: 2016-08-13T09:50:34-07:00
by pti
I have a PNG image generated by a QR code generator that I want to convert to CMYK and change the color.

Code: Select all

       
        using (MagickImage image = new MagickImage(inputFile))
        {
            image.Format = MagickFormat.Jpg;

            image.AddProfile(ColorProfile.SRGB);
            image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.USWebCoatedSWOP);

            MagickColor srcColor = new ColorCMYK(74, 68, 66, 90);
            MagickColor destColor = new ColorCMYK(100, 0, 0, 0);
            
            image.ColorFuzz = new Percentage(30);
            image.Opaque(srcColor, destColor);

            // Save image 
            image.Write(outputFile);
        }
        
Photoshop tells me the RGB's black is now 74, 68, 66, 90 CMYK so I try to convert to something like 100% cyan but the code gives me CMYK of 0, 100, 100, 0. Changing the new color's CMYK values gives me completely different colors in Photoshop.
What am I doing wrong?

Re: CMYK Color Conversion

Posted: 2016-08-13T10:25:39-07:00
by fmw42
This is just a guess since I do not use any API, only the command line. But you have not changed the colorspace of the image except via profiles, so your image is still using RGB colors as pixels and IM converts your CMYK colors back to RGB. Then lets the profiles do the conversion for display. Try changing the colorspace of the data to CMYK.

Re: CMYK Color Conversion

Posted: 2016-08-13T11:03:59-07:00
by snibgo
I don't use Magick.net nor CMYK so I'm also guessing. Are you mixing units? Eg Photoshop has a scale 0 to 100 but IM has 0 to 255?

Re: CMYK Color Conversion

Posted: 2016-08-13T11:35:46-07:00
by fmw42
Just another additional guess, but your input colorspace is sRGB since PNG does not support CMYK. So why specify the input color in CMYK. Perhaps specify it as RGB. cyan is rgb(0,255,255) or rgb(0,100%,100%).

Snibgo has a good point about color ranges (units) as raw values 0-255 vs percent 0-100.

Re: CMYK Color Conversion

Posted: 2016-08-13T13:39:27-07:00
by pti
Iv'e tried

Code: Select all

image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.USWebCoatedSWOP);
image.ColorSpace = ColorSpace.CMYK;
These commands should have changed the colorspace, and Photoshop shows the colorspace of the file as CMYK/8.

If I use

Code: Select all

MagickColor destColor = new ColorCMYK(255, 0, 0, 0);
I still don't get a Cyan only color. It comes out red so I think there is something going on where colors are still being interpreted as RGB instead of CMYK but I don't know what.

I need the image to be "print-ready" using CMYK. Printers don't like RGB. RGB is for screen display only.

Re: CMYK Color Conversion

Posted: 2016-08-13T14:39:46-07:00
by snibgo
What changes do you need? Can you make them in sRGB, then convert to CMYK?

Do you have to do it in a program? Can you use the command line?

Re: CMYK Color Conversion

Posted: 2016-08-13T15:19:33-07:00
by dlemstra
ColorCMYK uses a value in the QuantumRange (0-Quantum.Max) and not a percentage. You will need to to use a value in that range.

Re: CMYK Color Conversion

Posted: 2016-08-14T07:42:57-07:00
by pti
I cannot make the change in RGB because the color space is much smaller than CMYK.

Re: CMYK Color Conversion

Posted: 2016-08-14T11:26:42-07:00
by fmw42
dlemstra just told you how to use ColorCMYK. The range of values you need to use depend upon your IM Q level for your compile. Standard compile is Q16 which means you need to use values in the range 0-65535. So just scale percent value by 65535/100 or scale values in the range 0-255 by 65536/255.

See convert -version for you Q level

Re: CMYK Color Conversion

Posted: 2016-08-15T08:35:08-07:00
by pti
Thanks for all the suggestions but there might be something wrong with the Magick.Net implementation.
Even when using Quantum values, if I use ColorCMYK(255, 0, 0, 0) my color comes out red. If I use ColorCMYK(0, 255, 0, 0) my color comes out green. So ColorCMYK() seems to be setting RGB values behind the scene. I've even tried this on files I know are CMYK already.

I haven't tried the command line version but when I get around to it, I'll report back.

Re: CMYK Color Conversion

Posted: 2016-08-15T09:51:04-07:00
by fmw42
pti wrote:Thanks for all the suggestions but there might be something wrong with the Magick.Net implementation.
Even when using Quantum values, if I use ColorCMYK(255, 0, 0, 0) my color comes out red. If I use ColorCMYK(0, 255, 0, 0) my color comes out green. So ColorCMYK() seems to be setting RGB values behind the scene. I've even tried this on files I know are CMYK already.

I haven't tried the command line version but when I get around to it, I'll report back.

Are you on Q8 IM compile? If not and for example are on Q16 compile, then quantumrange is 0-65535. Check your Q level from

Code: Select all

convert -version