Combining images with MagickNET seems to miss the black channel

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
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Combining images with MagickNET seems to miss the black channel

Post 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: ... 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;
            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));
User avatar
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789

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

Post 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.
.NET + ImageMagick = Magick.NET, @MagickNET, Donate
Post Reply