How to write this ImageMagick command in Magick.NET?

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
zajic
Posts: 2
Joined: 2017-09-26T10:17:00-07:00
Authentication code: 1151

How to write this ImageMagick command in Magick.NET?

Post by zajic » 2017-09-26T10:34:08-07:00

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!

User avatar
dlemstra
Posts: 1382
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post by dlemstra » 2017-09-26T14:05:24-07:00

+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);
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

zajic
Posts: 2
Joined: 2017-09-26T10:17:00-07:00
Authentication code: 1151

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

Post by zajic » 2017-10-04T08:35:04-07:00

Thanks for the help!

Post Reply