Page 1 of 1

Combining images with MagickNET seems to miss the black channel

Posted: 2019-02-28T10:15:58-07:00
by pablobhz
Hello Everyone.
I am having a strange issue when combining images with MagickNET.

Once before i used the same code to combine 4 negative images (each one representating an channel, CMYK) into a final colored image.
However, now it seems to be missing the black channel on the final result.

I've uploaded the sample images to Google Drive, and i'm posting the code i'm using here. The code currently seems "huge" but its because i've been doing many tests.

Also, when i debug trough Visual Studio Debugger, looking the image Channels, it always shows Cyan only. No matter what image i load, it just shows Cyan. Is this an expected behaviour or there's something wrong with my data ?

I've ran the same files trough another software and it produced the correct result. The data from the image comes from RAW CMYK Data.
PS: Using magick convert (command line) produces an weird output also.
Files: https://drive.google.com/drive/folders/ ... sp=sharing
ANy input is appreciated.
Thanks in advance.
PS2: Image WidthxHeight: 1497 x 1216

Code: Select all

public ImageCombiner(Dictionary<string, MagickImage> InputImages, bool negate)
        {
            List<MagickImage> aaa = new List<MagickImage>();
            foreach(var img in InputImages)
            {
                var tmpImg = new MagickImage(img.Key);
                tmpImg.Negate(true, Channels.All);
                tmpImg.ColorSpace = ColorSpace.Gray;
                aaa.Add(tmpImg);
            }
            using (MagickImageCollection col = new MagickImageCollection())
            {
                col.Add(aaa.Where(x => x.FileName.ToUpper().Contains("CYAN")).FirstOrDefault());
                col.Add(aaa.Where(x => x.FileName.ToUpper().Contains("MAGENTA")).FirstOrDefault());
                col.Add(aaa.Where(x => x.FileName.ToUpper().Contains("YELLOW")).FirstOrDefault());
                col.Add(aaa.Where(x => x.FileName.ToUpper().Contains("BLACK")).FirstOrDefault());
                MagickImage finalImg = new MagickImage(col.Combine(ColorSpace.RGB));
                finalImg.Write(@"C:\test\final2.png");
           }                       
        }

Re: Combining images with MagickNET seems to miss the black channel

Posted: 2019-02-28T20:28:26-07:00
by dlemstra
The colorspace should be CMYK in the Combine call. And that result is already an image so don't pass that to the MagickImage constructor again. And don't forget to Dispose it.