Missing black channel when using MagickCollection.Combine()

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

Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

Hello Everyone.
I'm using the Combine method from MagickCollection to combine 4 grayscale images into a final one (CMYK).
However, i'm having a weird situation:

When looking the final image from Windows Photo Viewer\Photoshop , the black channel is missing. When looking from Google Drive Preview, the black channel is there.

I believe Google Drive Previewer is compensating the black channel ; however, others don't.

Here's the code i'm using:

Code: Select all

static void Main(string[] args)
        {
            using (MagickImageCollection images = new MagickImageCollection())
            {                
                images.Add(@"C:\imgfolder\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
                images.Add(@"C:\imgfolder\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF");
                images.Add(@"C:\imgfolder\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF");
                images.Add(@"C:\imgfolder\Bitmaps\8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF");
                
                using (MagickImage image = images.Combine())
                {                                        
                    image.Write(@"C:\imgfolder\Bitmaps\combineoutput2.tif");
                }
            }

        }
Check here
Windows Image Viewer preview:
Image
Google Drive Preview:
Image

Do i have to set colorspace somehow when creating the final image ?
Thanks in advance
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Missing black channel when using MagickCollection.Combine()

Post by snibgo »

pablobhz wrote:Do i have to set colorspace somehow when creating the final image ?
Yes, I suspect that is the problem.

If you upload the 4 input images, we can show the command line to make the correct output.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

Check the google drive folder.
https://drive.google.com/drive/folders/ ... sp=sharing

Tiffs are there. Ignore the Imposition (its the spot color, i'll figure out later how to combine it).

Edit: And i tried to set the colorspace to CMYK on MagickNET

Code: Select all

                using (MagickImage image = images.Combine())
                {                        
                    image.ColorSpace = ImageMagick.ColorSpace.CMYK;                          
                    image.Write(@"C:\DI_PLOT\Bitmaps\combineoutput2.tif");
                }
Weird result still, to be honest.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Missing black channel when using MagickCollection.Combine()

Post by snibgo »

The directory contains:
17,240,150 8FILES_IMPOSED_4UP_BACK.PDF (C)00 - Copy.TIF

20,725,476 8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF
165,843 8FILES_IMPOSED_4UP_BACK.PDF (Imposition)00.TIF
15,566,357 8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF
20,748,861 8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF

There doesn't seem to be an image for Yellow.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

snibgo wrote: 2017-03-22T09:40:04-07:00 The directory contains:
17,240,150 8FILES_IMPOSED_4UP_BACK.PDF (C)00 - Copy.TIF

20,725,476 8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF
165,843 8FILES_IMPOSED_4UP_BACK.PDF (Imposition)00.TIF
15,566,357 8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF
20,748,861 8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF

There doesn't seem to be an image for Yellow.
Just uploaded the yellow image. Sorry.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Missing black channel when using MagickCollection.Combine()

Post by snibgo »

Your files named (C) (M) etc do not represent cyan, magenta, etc. That is a problem. They represent the negatives of cyan, magenta etc. So we need to negate them before we can use them.

(I'll explain. A file representing K, black ink, will have high values where we want lots of black ink, and low values where we want very little black ink. But your (K) file works the other way around. The same is true of C, M and Y.)

Windows BAT script:

Code: Select all

%IM%convert ^
  "8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF" ^
  -negate ^
  -set colorspace CMYK ^
  -combine ^
  x.tiff
The output, x.tiff, is a CMYK file. It shows correctly with Microsoft Photo Viewer.

Sorry, I don't use Magick.net, and don't know how to translate that command to Magick.net.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

I'll try as soon o get home
But I was using negate the same way you did , and I was still missing the black channel .

I'm pretty sure MagickNET has an equivalent to negate ; probably . Perhaps I have to rewrite the files negates before combining them ; it's an approach

Thanks for your attention and help . I really understood the question now .

And ... if nothing works I'll use the command line embedded in the code hehehe.

Thanks !
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

snibgo wrote: 2017-03-22T10:22:33-07:00 Your files named (C) (M) etc do not represent cyan, magenta, etc. That is a problem. They represent the negatives of cyan, magenta etc. So we need to negate them before we can use them.

(I'll explain. A file representing K, black ink, will have high values where we want lots of black ink, and low values where we want very little black ink. But your (K) file works the other way around. The same is true of C, M and Y.)

Windows BAT script:

Code: Select all

%IM%convert ^
  "8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF" ^
  "8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF" ^
  -negate ^
  -set colorspace CMYK ^
  -combine ^
  x.tiff
The output, x.tiff, is a CMYK file. It shows correctly with Microsoft Photo Viewer.

Sorry, I don't use Magick.net, and don't know how to translate that command to Magick.net.
Thanks ! Worked like a charm.
However i'm not getting the negate to work on MagickNET.

I've found its code and how to implement it - however, doesn't seem to be working.
I'll try more and if i can't get it done i'll post another thread.

THanks in advance
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Missing black channel when using MagickCollection.Combine()

Post by dlemstra »

With the latest version (7.0.5.500) I was able to get the same output as on the command line with the following code:

Code: Select all

using (MagickImageCollection images = new MagickImageCollection())
{
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF");

  foreach(MagickImage image in images)
  {
    image.Negate();
  }

  using (MagickImage image = images.Combine(ColorSpace.CMYK))
  {
    image.Write("combineoutput2.tif");
  }
}
.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: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

dlemstra wrote: 2017-04-02T07:36:56-07:00 With the latest version (7.0.5.500) I was able to get the same output as on the command line with the following code:

Code: Select all

using (MagickImageCollection images = new MagickImageCollection())
{
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF");

  foreach(MagickImage image in images)
  {
    image.Negate();
  }

  using (MagickImage image = images.Combine(ColorSpace.CMYK))
  {
    image.Write("combineoutput2.tif");
  }
}
Thanks !
I will try as soon I get back in home .
If if works , it'll be like 70% of what I have to do.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Missing black channel when using MagickCollection.Combine()

Post by dlemstra »

Feel free to ask more questions if you need more help with the remaining 30% :)
.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: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

pablobhz wrote: 2017-04-02T07:40:46-07:00
dlemstra wrote: 2017-04-02T07:36:56-07:00 With the latest version (7.0.5.500) I was able to get the same output as on the command line with the following code:

Code: Select all

using (MagickImageCollection images = new MagickImageCollection())
{
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (C)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (M)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (Y)00.TIF");
  images.Add("8FILES_IMPOSED_4UP_BACK.PDF (K)00.TIF");

  foreach(MagickImage image in images)
  {
    image.Negate();
  }

  using (MagickImage image = images.Combine(ColorSpace.CMYK))
  {
    image.Write("combineoutput2.tif");
  }
}
Thanks !
I will try as soon I get back in home .
If if works , it'll be like 70% of what I have to do.

Worked like a charm !
Thanks.

However , i've another question:
I'm also resizing the final output and changing the colorspace of combined images to CMYK.
For now, i've done all this inside the combine method ; the entire operation took 30 seconds.

Perhaps if i write the file to the disk, load it again, resize\change colorspace will it be faster ? Or thats the normal time ?
Or you think this time won't change much ?

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

Re: Missing black channel when using MagickCollection.Combine()

Post by dlemstra »

30 seconds sounds a bit long but with the images your provided me it will take a while and require quite a lot of memory. Are you using the x64 version or the x86 version of Magick.NET? If you are using the x86 one you might want to give the x64 one a try. And you really don't need to change the ColorSpace inside the combine block. Your image already has the correct ColorSpace. What happens when you remove that?

Saving to disk and loading / resizing the image again will be slower. Are you resizing the image after you have combined it?
.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: Missing black channel when using MagickCollection.Combine()

Post by pablobhz »

dlemstra wrote: 2017-04-03T14:38:29-07:00 30 seconds sounds a bit long but with the images your provided me it will take a while and require quite a lot of memory. Are you using the x64 version or the x86 version of Magick.NET? If you are using the x86 one you might want to give the x64 one a try. And you really don't need to change the ColorSpace inside the combine block. Your image already has the correct ColorSpace. What happens when you remove that?

Saving to disk and loading / resizing the image again will be slower. Are you resizing the image after you have combined it?
When I don't combine changing colorspace inside the combine block , it generates a lighter output on the correct colorspace . However , I will need an rgb output of the files . What I haven't tried is to combine using rgb as default colorspace .

And I'm using the anycpu version of MagickNET. I will try the x64

Thanks ! I will post the reply with the results .
Post Reply