Page 1 of 1

How to write this ImageMagick command in Magick.NET?

Posted: 2017-09-26T10:34:08-07:00
by zajic
Hi,
I need to write this convert in C#, but I just can't wrap my head around it. I can't find any equivalent for +swap, minus has two options in Magick.NET (minusDst, minusSrc), etc. Can someone please help me with this?

Here is the convert command:

Code: Select all

convert pic.jpg cloneBlur.jpg +swap -compose minus -composite \( cloneComp.jpg -evaluate multiply 0.2 \) +swap -compose minus -composite -threshold 1 final.jpg
Here is my code:

Code: Select all

using (MagickImage im = new MagickImage("pic.jpg")){
   //some code
   using (MagickImage cloneBlur = (MagickImage)im.Clone()){
      //some code
      using (MagickImage cloneComp = (MagickImage)im.Clone()){
         //some code

         //Here is where the convert should take place
         cloneComp.Evaluate(Channels.All, EvaluateOperator.Multiply, 0.2); //this is the only part I think I got right          
         final.Write(final.jpg); //ends with this (or something similar)
      }
   }
}
Thanks in advance for any help!

Re: How to write this ImageMagick command in Magick.NET?

Posted: 2017-09-26T14:05:24-07:00
by dlemstra
+swap swaps the first and the last image in the list: https://www.imagemagick.org/script/comm ... s.php#swap. It makes no sense to have this as the first operation because you could just switch the order. But looking at your code it seems that you are creating those images yourself. Below are some hints to help you find the correct code to do this.

Code: Select all

// convert pic.jpg cloneBlur.jpg +swap -compose minus -composite
// +swap switches the order of the images to:
// convert cloneBlur.jpg pic.jpg  -compose minus -composite
// And translates to:
cloneBlur.Composite(im, CompositeOperator.MinusDst);
The multiplication evaluate operation looks correct.

Code: Select all

// convert pic.jpg cloneBlur.jpg +swap -compose minus -composite \( cloneComp.jpg -evaluate multiply 0.2 \) +swap -compose minus -composite
// Becomes this after the first composite:
// convert cloneBlur-pic.jpg \( cloneComp.jpg -evaluate multiply 0.2 \) +swap -compose minus -composite
// Then evaluate does this:
// convert cloneBlur-pic.jpg cloneComp-evaluate.jpg +swap -compose minus -composite
// +swap switches the order of the images to:
// convert cloneComp-evaluate.jpg cloneBlur-pic.jpg -compose minus -composite
// And translates to:
cloneComp.Composite(cloneBlur, CompositeOperator.MinusDst);

Re: How to write this ImageMagick command in Magick.NET?

Posted: 2017-10-04T08:35:04-07:00
by zajic
Thanks for the help!