Page 1 of 1

Missing black channel when using MagickCollection.Combine()

Posted: 2017-03-22T06:02:20-07:00
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

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

Posted: 2017-03-22T08:51:25-07:00
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.

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

Posted: 2017-03-22T08:56:32-07:00
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.

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

Posted: 2017-03-22T09:40:04-07:00
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.

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

Posted: 2017-03-22T09:52:53-07:00
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.

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

Posted: 2017-03-22T10:22:33-07:00
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.

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

Posted: 2017-03-22T14:04:58-07:00
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 !

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

Posted: 2017-03-22T21:52:09-07:00
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

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

Posted: 2017-04-02T07:36:56-07:00
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");
  }
}

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

Posted: 2017-04-02T07:40:46-07:00
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.

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

Posted: 2017-04-02T07:52:13-07:00
by dlemstra
Feel free to ask more questions if you need more help with the remaining 30% :)

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

Posted: 2017-04-03T14:33:15-07:00
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.

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

Posted: 2017-04-03T14:38:29-07:00
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?

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

Posted: 2017-04-03T18:40:38-07:00
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 .