How do I translate this to Magick.net?

Dec 15, 2014 at 7:22 PM
I have an image with a background and object in it, I have and image of just the background and I want to extract only the object.

This works for me:
convert overlay_figure.gif overlay_bgnd.gif -compose ChangeMask -composite overlay_removed.png

but I can't translate it properly to Magick.net, i always get a white/blank image

Can someone please translate the command properly for me?

Thanks in advance!
Coordinator
Dec 15, 2014 at 10:01 PM
Can you post some links to your input files?
Dec 16, 2014 at 3:14 PM
dlemstra wrote:
Can you post some links to your input files?
Yes, sure. Here they are:

http://i.imgur.com/ZvKhFrw.png
http://i.imgur.com/7YisdlY.png

I use convert ZvKhFrw.png 7YisdlY.png -compose ChangeMask -composite overlay_removed.png

and I need it translated to Magick.net

Thanks in advance!
Coordinator
Dec 17, 2014 at 3:10 PM
This is a bug in ImageMagick 7. I will fix this before the next release of Magick.NET.
Dec 17, 2014 at 3:17 PM
dlemstra wrote:
This is a bug in ImageMagick 7. I will fix this before the next release of Magick.NET.
OK, great, thanks for you time!

However is my Magick.NET syntax, right?

I am doing like

IMG=New MagickImage("ZvKhFrw.png")

IMG.Mask=New MagickImage("7YisdlY.png")

Output=IMG.Composite(IMG, Gravity.Center, CompositeOperator.ChangeMask)
Coordinator
Dec 17, 2014 at 3:33 PM
I have not tested this but I think it should be something like this:
IMG=New MagickImage("ZvKhFrw.png")

Mask=New MagickImage("7YisdlY.png")

Output=IMG.Composite(Mask, Gravity.Center, CompositeOperator.ChangeMask)
Dec 17, 2014 at 4:16 PM
Edited Dec 17, 2014 at 4:17 PM
I am sorry, I don't think you understood me correctly and I am not sure if the bug you found relates to my issue. Let me explain again

What i need to do is get the difference between two images. The following command does exactly what I need:
convert IMG1.png IMG2.png -compose ChangeMask -composite OUTPUT.png 
Now I am trying to accomplish that in Magick.NET, but I fail.

I tried the code You proposed, but in OUTPUT.png I get exactly the same content of IMG1.png
IMG=New MagickImage("IMG1.png")

Mask=New MagickImage("IMG2.png")

IMG.Composite(Mask, Gravity.Center, CompositeOperator.ChangeMask)

IMG.Write("OUTPUT.png")
So, I am not sure if I am doing correctly the translation from the Imagemagick command to Magick.NET
Dec 17, 2014 at 6:22 PM
I don't know if this will help you or not, but there have been a lot of changes in ImageMagick version 7 that are great for making things more consistent but work a bit different than version 6. If you are comparing to output of a version 6 command line convert command you might try dropping back to an older Magick.Net version built on IM 6 since he is saying this is a bug in V7
Dec 17, 2014 at 6:31 PM
jbleach wrote:
I don't know if this will help you or not, but there have been a lot of changes in ImageMagick version 7 that are great for making things more consistent but work a bit different than version 6. If you are comparing to output of a version 6 command line convert command you might try dropping back to an older Magick.Net version built on IM 6 since he is saying this is a bug in V7
Ah, this could be it.. I just now realized my IM is ver 6, while the one in Magick.NET is 7...

Reverting back to previous Magick.NET is not a solution for me as there is difference in some of the filters I use.. will wait for Dirk to see if we can get this going with the newest version
Coordinator
Dec 18, 2014 at 9:41 AM
We are having some problems with transparency and the composite method in ImageMagick 7. We are working on fixing this and I will publish a new release after this has been fixed, this might take us a couple of days.
Dec 18, 2014 at 11:13 AM
dlemstra wrote:
We are having some problems with transparency and the composite method in ImageMagick 7. We are working on fixing this and I will publish a new release after this has been fixed, this might take us a couple of days.
Sure, no hurry!
Coordinator
Dec 22, 2014 at 10:03 PM
This problem has been fixed in my development build. I will try to publish a new release this week.
Dec 24, 2014 at 2:49 PM
dlemstra wrote:
This problem has been fixed in my development build. I will try to publish a new release this week.
This works now just fine in the new version, however I still think there's some bug in the code or is not yet implemented as for other set of images it doesn't work correctly. Something about the ColorFuzz is not working I think.

This is the following IM6 command that works just fine for me:
convert image.jpg mask.jpg -fuzz 10% -compose changemask -composite out.png
where
image.jpg is: http://i.imgur.com/MwU2Tpc.jpg
mask.jpg is: http://i.imgur.com/x6ORFGf.jpg

and resulted out.png is: http://i.imgur.com/odYWsHC.png

however, when i try this in latest Magick.NET no matter how much ColorFuzz I add to the image.jpg or mask.jpg or even both, the result is like this: http://i.imgur.com/RpDVCeR.png

This is my exact code I use:
                Dim TheImage As MagickImage=New MagickImage("image.jpg")
                Dim Mask As MagickImage = New MagickImage("mask.jpg")

                TheImage.ColorFuzz = New Percentage(10)
                TheImage.Composite(Mask, Gravity.Center, CompositeOperator.ChangeMask)
                TheImage.Write("out.png")
Coordinator
Dec 24, 2014 at 8:51 PM
Edited Dec 24, 2014 at 8:52 PM
There seems to be an issue with the fuzz calculation, we are working on it. For now you should set the ColorFuzz on both TheImage and Mask.

p.s. You should not use JPG as an intermediate file format, PNG is a better choice.
Dec 25, 2014 at 7:36 AM
dlemstra wrote:
There seems to be an issue with the fuzz calculation, we are working on it. For now you should set the ColorFuzz on both TheImage and Mask.

p.s. You should not use JPG as an intermediate file format, PNG is a better choice.
I see, i will wait then..

I tried to put fuzz on both, but result is even worse...

Yeah i know the JPG is not appropriate, but these particular images as supplied are in this format..

Happy holidays :)
Coordinator
Dec 25, 2014 at 11:14 AM
I am getting the same output as IM6 when I set the ColorFuzz to 10 on both images.
Dec 25, 2014 at 1:11 PM
dlemstra wrote:
I am getting the same output as IM6 when I set the ColorFuzz to 10 on both images.
Hmm, yes, you are right! I got it now as well

Maybe i got mixed up something as i tried many things yesterday..

Thanks!
Coordinator
Dec 25, 2014 at 9:50 PM
In the next release you only need to set the ColorFuzz on one of the images. For now you should use the workaround I gave you.