Page 1 of 1

C# Imagemagick subtraction syntax

Posted: 2017-08-06T04:18:58-07:00
by mfranquelo
Dear all,

Could anyone point me how to do a subtraction between two images? I can't seem to find good documentation in C# (or similar) for this. Is it using the method FX or composite?

This is my code:

- Simple gaussian blur and difference between the original image and the gaussian blurred image.

Code: Select all

    class Program
        static void Main(string[] args)
            // Definir variables

            byte sigma;
            short radius;
            int originalX;
            int originalY;

            //Reading the file 

            using (MagickImageCollection images = new MagickImageCollection())
                //First image
                MagickImage raw = new MagickImage(@"D:\test01.jpg");

                // Record original size
                originalX = raw.Width;
                originalY = raw.Height;

                // Gaussian Blur
                Console.WriteLine("Please enter sigma value for Gaussian blur:");
                radius = short.Parse(Console.ReadLine());
                Console.WriteLine("Please enter radius value for Gaussian blur:");
                sigma = byte.Parse(Console.ReadLine());

                    // Speed up
                    raw.Scale(new Percentage(10));

                 // Write

                 // Second image
                 MagickImage blur = new MagickImage(@"D:\test01_gaussianblur.jpg");

                 using (MagickImage flattened = images.Combine(); My doubt is here, how can i perform a subtraction?
Thank you,

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T05:02:52-07:00
by dlemstra
What do you mean by subtraction? Have you done this one the command line and are you trying to convert those commands to c#?

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T05:13:24-07:00
by mfranquelo
I am trying to convert those commands to C# syntax, yes.

For subtraction i mean that i want to output the mathematical difference between two inputs.
It works with image.Fx(u-0.5) for example. But i can't seem to figure out the structure for two images.

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T05:42:48-07:00
by mfranquelo
The question is: How does magick know which one is "second" image?

The structure is like this first image (which is the one i am declaring) and [v] for second image, that i don't know where to declare it. :(

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T05:51:36-07:00
by dlemstra
What is your ImageMagick command on the command line?

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T06:05:46-07:00
by mfranquelo
Im using so i don't really know which is this particular command on the command line. I just want to output the difference between two images :? it could be related to this i guess: ... hp?t=16279

and this:

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-06T08:11:30-07:00
by mfranquelo
according to the command line it seems i need to (compare them) raw.Compare(blur,ErrorMetric.Absolute, diffImage); and then compose them?

Re: C# Imagemagick subtraction syntax

Posted: 2017-08-11T03:08:44-07:00
by dlemstra
I think you just need to do this:

Code: Select all

raw.Composite(blur, CompositeOperator.ModulusSubtract);
This also means you don't need to MagickImageCollection.