Issue when combining images

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

Issue when combining images

Post by pablobhz »

Hello everyone.
I had this thread, some months ago:
viewtopic.php?f=27&t=31621
Anyway i tought it was best to create a new one.

I'm trying to combine some images, but they're not being combined correctly - even using ImageMagick command line.
Based on the output, i've the feeling that its missing the black channel (even the image being there).

I read the old thread entirely, checked, nothing changed since then - this problem suddendly started to happen.
Neither ImageMagick version on my PC was changed.

The images are:
https://drive.google.com/drive/folders/ ... sp=sharing
(Ignore the image with name IMPOSITION).
Combining the Cyan,Magenta, Yellow and black negatives should produce an coloured image (as it always did).

The code i'm using is:

Code: Select all

        public magickCollectionBuilder(List<MagickImage> imagesToCombine, string jobName, string outputFolder)
        {
            int.TryParse(Properties.Settings.Default.maxPreviewSize_Width, out resizedImageWidth);            
            int.TryParse(Properties.Settings.Default.maxPreviewSize_Height, out resizedImageHeight);
            magickImages = new MagickImageCollection();
            foreach(MagickImage img in imagesToCombine)
            {
                
                img.Resize(resizedImageWidth, resizedImageHeight);
                img.Negate();
                magickImages.Add(img);
            }
            composedCMYKImage = new MagickImage(magickImages.Combine(ColorSpace.CMYK));            
            //composedCMYKImage.ColorSpace = ColorSpace.sRGB;
            resizedImageDPI = composedCMYKImage.Density.X;            
        }
With ImageMagick, what i tried was:
convert IMAGE_BLACK.TIF IMAGE_CYAN.TIF IMAGE_MAGENTA.TIF IMAGE_YELLOW.TIF -negate -set colorspace CMYK -combine FINALRESLUT.PNG

Any input will be highly appreciated
Thanks !

EDIT: This is my current output.
Image

Seems like there are channels missing.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue when combining images

Post by snibgo »

pablobhz wrote:convert IMAGE_BLACK.TIF IMAGE_CYAN.TIF IMAGE_MAGENTA.TIF IMAGE_YELLOW.TIF -negate -set colorspace CMYK -combine FINALRESLUT.PNG
"-combine" expects the input images to be in the order of the colorspace name, ie CMYK. But you have given them in the order BCMY.
snibgo's IM pages: im.snibgo.com
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Issue when combining images

Post by pablobhz »

snibgo wrote: 2017-08-01T14:45:29-07:00
pablobhz wrote:convert IMAGE_BLACK.TIF IMAGE_CYAN.TIF IMAGE_MAGENTA.TIF IMAGE_YELLOW.TIF -negate -set colorspace CMYK -combine FINALRESLUT.PNG
"-combine" expects the input images to be in the order of the colorspace name, ie CMYK. But you have given them in the order BCMY.
Does it apply for MagickNET also ?
ex: If the image list is in any order rather than CMYK it'll fail ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue when combining images

Post by snibgo »

I don't know MagickNET, but I expect it is the same as "-combine".

IM doesn't know which of your four grayscale images contains the cyan data. I assume it is the one called IMAGE_CYAN.TIF. But IM won't look at the file names. It expects images in the same order as the colorspace name: CMYK. "-separate" will also use that order.
snibgo's IM pages: im.snibgo.com
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Issue when combining images

Post by dlemstra »

The input order is indeed important. I get the correct output with the following code:

Code: Select all

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

    foreach (IMagickImage image in images)
    {
        image.Resize(1900, 0);
        image.Negate();
    }

    using (IMagickImage image = images.Combine(ColorSpace.CMYK))
    {
        image.Write(@"i:\CMYK\output.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: Issue when combining images

Post by pablobhz »

dlemstra wrote: 2017-08-03T12:02:47-07:00 The input order is indeed important. I get the correct output with the following code:

Code: Select all

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

    foreach (IMagickImage image in images)
    {
        image.Resize(1900, 0);
        image.Negate();
    }

    using (IMagickImage image = images.Combine(ColorSpace.CMYK))
    {
        image.Write(@"i:\CMYK\output.tif");
    }
}
I understood. Didn't knew about this detail.
I'll manually combine items under the list in order to match the order.

Again, thanks in advance !

Best Regards,
Pablo Costa
pablobhz
Posts: 69
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Re: Issue when combining images

Post by pablobhz »

dlemstra wrote: 2017-08-03T12:02:47-07:00 The input order is indeed important. I get the correct output with the following code:

Code: Select all

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

    foreach (IMagickImage image in images)
    {
        image.Resize(1900, 0);
        image.Negate();
    }

    using (IMagickImage image = images.Combine(ColorSpace.CMYK))
    {
        image.Write(@"i:\CMYK\output.tif");
    }
}

Bringing this topic back.
I did as you suggested, but the problem wasn't solved. The final output is still completely weird.

Here's how i'm doing it (following the CMYK order):

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ImageMagick;
using DI_Plot_2._0.imageManipulation;

namespace DI_Plot_2._0.fullJobMethods
{
    class CMYKMagickCollectionCreator
    {
        public MagickImageCollection CMYKImagesCollection { get; private set; }
        public CMYKMagickCollectionCreator(List<string> jobFiles)
        {
            CMYKImagesCollection = new MagickImageCollection();
            var fileExists = jobFiles.Where(x => x.Contains("CYAN") || x.Contains("(C)"));
            if (fileExists.Count() > 0)
            {
                IMagickImage currentImage = imageOperations(fileExists.ElementAt(0));
                CMYKImagesCollection.Add(currentImage);
            }
            fileExists = jobFiles.Where(x => x.Contains("MAGENTA") || x.Contains("(M)"));
            if (fileExists.Count() > 0)
            {
                IMagickImage currentImage = imageOperations(fileExists.ElementAt(0));
                CMYKImagesCollection.Add(currentImage);
            }
            fileExists = jobFiles.Where(x => x.Contains("YELLOW") || x.Contains("(Y)"));
            if (fileExists.Count() > 0)
            {
                IMagickImage currentImage = imageOperations(fileExists.ElementAt(0));                                
                CMYKImagesCollection.Add(currentImage);
            }
            fileExists = jobFiles.Where(x => x.Contains("BLACK") || x.Contains("(K)"));
            if (fileExists.Count() > 0)
            {
                IMagickImage currentImage = imageOperations(fileExists.ElementAt(0));
                CMYKImagesCollection.Add(currentImage);
            }            
        }
        private IMagickImage imageOperations(string fileName)
        {
            IMagickImage currentImage = new MagickImage(fileName);
            imageRotator rotatedImage = new imageRotator(currentImage, rotationOptionStatic.rotationOption);
            currentImage.Negate();
            return currentImage;
        }


    }
}

This receives all image files and add's them as they're available.
Note that the code works for all other files i have, but this specific one it isn't combining correctly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue when combining images

Post by fmw42 »

This is the correct command line syntax. The first is if you have positives, the second if you have negatives.

Code: Select all

convert -quiet IMAGE_CYAN.TIF IMAGE_MAGENTA.TIF IMAGE_YELLOW.TIF IMAGE_BLACK.TIF -set colorspace CMYK -combine -colorspace sRGB FINALRESLUT.PNG

Code: Select all

convert -quiet IMAGE_CYAN.TIF IMAGE_MAGENTA.TIF IMAGE_YELLOW.TIF IMAGE_BLACK.TIF -negate -set colorspace CMYK -combine -colorspace sRGB FINALRESLUT.PNG

Or you could use profiles in place of -colorspace sRGB.

The second one looks correct, so you must have had negative scans.
Post Reply