Combine 4 grayscale images into a final CMYK image

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

Hello Everyone.

Lemme explain my scenario.
I have an old software, that takes 4 tiff images (grayscale), and combine them into a final CMYK colored image.

I already know that each one of those images, corresponds to one color channel
ex:
image 1 - foo(c).TIFF
image 2 - foo(m).TIFF

and so goes on.

I would like to know if, can MagickNET do this kind of merging to create a final file ?
There's no documentation or anything in the old source code.

Here's my tought:
Loop into each image pixel, store and later combine in a final image (something like that) ?

Thanks in advance for any input\help.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Combine 4 grayscale images into a final CMYK image

Post by dlemstra »

You could use the Combine method of the MagickImageCollection for this. Only have a phone atm so I cannot easily create an example for you.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combine 4 grayscale images into a final CMYK image

Post by snibgo »

At the command line, you can do this:

Code: Select all

convert foo(c).TIFF foo(m).TIFF foo(y).TIFF foo(k).TIFF -set colorspace CMYK -combine +write info: out.tiff
Sorry, I don't know Magick.NET.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

dlemstra wrote: 2017-03-16T06:05:19-07:00 You could use the Combine method of the MagickImageCollection for this. Only have a phone atm so I cannot easily create an example for you.
This method works for RGB output only, as i could see. It has no mentions to a CMYK combining.
The input is 4 files, output will be one file. Unless there's some way to convert from CMYK to RGB and then combine, it won't work.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Combine 4 grayscale images into a final CMYK image

Post by dlemstra »

What happens when you set the ColorSpace of the image to CMYK afterwards?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

Here's the tests i've done.

Using MagickCollection (MagickNET)

Code: Select all

using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add the first image
                MagickImage first = new MagickImage(@"C:\DI_PLOT\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
                images.Add(first);

                // Add the first image
                MagickImage second = new MagickImage(@"C:\DI_PLOT\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF");
                images.Add(second);

                // Add the first image
                MagickImage third = new MagickImage(@"C:\DI_PLOT\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF");
                images.Add(third);

                // Add the first image
                MagickImage fourth = new MagickImage(@"C:\DI_PLOT\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
                images.Add(fourth);

                images.Combine();
                images.Write(@"C:\DI_PLOT\finalmerge.png");
                /*
                // Create a mosaic from both images
                using (MagickImage result = images.Mosaic())
                {
                    // Save the result
                    result.Write(@"C:\DI_PLOT\finalmerge.png");
                }
                */
            }
Neither the combine or mosaic worked. They all created a grayscale output anyway (and i need a colored output).
Using the command-line version, gives a few errors but create a weird output. I've uploaded the correct sample and the output i got.
Correct:
http://imgur.com/fyZEMLW

My current output:
http://imgur.com/WLh4KQc

If i set the colorspace to CMYK or RGB (while doing convert), here's the output:
http://imgur.com/8qsmEJr

Any help is appreciated. Kinda lost on this, since i'm new to image processing.
Thanks in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine 4 grayscale images into a final CMYK image

Post by fmw42 »

It does not look like you changed the colorspace to CMYK per dlemstra's suggestion. I do not use Magick.NET, but as a quick test, try negating the image (command line equivalent is -negate). If that is close then you need to do what dlemstra suggests.
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

fmw42 wrote: 2017-03-21T20:22:03-07:00 It does not look like you changed the colorspace to CMYK per dlemstra's suggestion. I do not use Magick.NET, but as a quick test, try negating the image (command line equivalent is -negate). If that is close then you need to do what dlemstra suggests.
But i did
The entire command is:
convert c.tif m.tif y.tif k.tif -set colorspace CMYK -combine + write output.tif

For now i'm using command line to achieve this result. When i get command line working, i'll think on how can i implement it using MagickNET

Edit: got this version right now.
http://imgur.com/qPDXgmQ

And using negate:
http://imgur.com/vC0tFgn

Seems like the image is missing "brightness" or something (since i can see RGB colors on the left)

With negate i got really vivid colors but it still seems i'm missing some kind of brightness .
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine 4 grayscale images into a final CMYK image

Post by fmw42 »

Sorry, your code was Magick.NET. So I only thought you were asking about that. I think the proper command line would be

Code: Select all

convert c.tif m.tif y.tif k.tif -set colorspace sRGB -combine -colorspace CMYK output.tif

You do not need the +write (which should not have any spaces)
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

Got it done.
I was looking this thread:

viewtopic.php?t=21159

Then i saw an sample command:
convert imgC imgM imgY imgK -set colorspace CMYK -negate -combine output_image

Should've set the colorspace to CMYK and negate also. Output is fine now.
However, now i'll check how to add some spot colors to this CMYK image.

And later, how to convert all of this to MagickNET (if possible).
The suggestion a guy gave eariler (MagickCollection) didn't worked (produced an black output). I believe i'll try to do a few more things.

Thanks !!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine 4 grayscale images into a final CMYK image

Post by fmw42 »

IM does not support spot colors as far as I know.
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

fmw42 wrote: 2017-03-21T21:15:20-07:00 IM does not support spot colors as far as I know.
And if i add it as a new color ?
Ex: i have color X
It is composed by:
0% cyan
10% magenta
60% yellow
0% black

How would i combine an image with this color composition (and a white background) into my existant CMYK image ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combine 4 grayscale images into a final CMYK image

Post by snibgo »

A "spot color" means a colour in used in a product that isn't made by combining CMYK inks. Instead, another plate is used with an ink of that colour.

IM can't add spot colors, but I don't think you want to add a spot colour.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Combine 4 grayscale images into a final CMYK image

Post by pablobhz »

Okay. So i got it wrong.
The color i want to add, is composed by this amount on each channel.

Like i mentioned before:
0% cyan
10% magenta
60% yellow
0% black

The image color is Grayscale and when combining it to a CMYK image, this is the color the image should have.

I supposed it would be like convert the image to CMYK assigning these channels (amount of each one), and then combine with the final CMYK image ?
Post Reply