Removing clipping mask and apply featuring/antialiasing

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
piratexses
Posts: 3
Joined: 2018-06-19T02:08:05-07:00
Authentication code: 1152

Removing clipping mask and apply featuring/antialiasing

Post by piratexses » 2018-06-19T02:20:21-07:00

Hi all,
I am trying to use Magick.Net to remove a clipping-mask (transparent background) and ably featuring/antialiasing for smoothing of the edges.
I have install ImageMagick locally and got the following command to do what I require:

(unix syntax)

Code: Select all

magick identify -quiet -format "%[8BIM:1999,2998:#1]" image.jpg |\
magick -quiet image.jpg \( - -alpha off -negate -morphology erode diamond:1 -blur 0x1 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
result.png
(windows syntax)

Code: Select all

magick identify -quiet -format "%[8BIM:1999,2998:#1]" image.jpg |^
magick -quiet image.jpg ( - -alpha off -negate -morphology erode diamond:1 -blur 0x1 -level 50x100% ) ^
-alpha off -compose copy_opacity -composite ^
result.png
The code I have made in C# is the flowing:

Code: Select all

            using (MagickImage image = new MagickImage(bytes))
            {
                using (MagickImage image2 = new MagickImage(bytes))
                {
                    image2.Alpha(AlphaOption.Off);
                    image2.Negate();
                    image2.Morphology(MorphologyMethod.Erode, Kernel.Diamond, 1);
                    image2.Blur();
                    image2.Level(50, 100);

                    image.Composite(image2, CompositeOperator.CopyAlpha);

                    image.Write(AppDomain.CurrentDomain.BaseDirectory + "\\Image.png");
                }
            }
But the problem is that the C# code leave a white boarder around the image, can anyone see what I am doing wrong?

Images for testing is available at the following post: viewtopic.php?f=22&t=34049

Thank you all in advance!

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

Re: Removing clipping mask and apply featuring/antialiasing

Post by dlemstra » 2018-06-19T22:03:36-07:00

You are not using the correct overload for `Level`:

Code: Select all

image2.Level(50, 100);
Should be:

Code: Select all

image2.Level(new Percentage(50), new Percentage(100));
And it looks like you are not doing the -alpha off on the first image. And as a last comment I would suggest that you use the

Code: Select all

using (MagickImage image2 = image.Clone())
Instead of

Code: Select all

using (MagickImage image2 = new MagickImage(bytes))
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

piratexses
Posts: 3
Joined: 2018-06-19T02:08:05-07:00
Authentication code: 1152

Re: Removing clipping mask and apply featuring/antialiasing

Post by piratexses » 2018-06-25T01:51:40-07:00

Hi dlemstra,

Thank you for your feedback, but did not work.

This is my code now:

Code: Select all

            using (MagickImage image = new MagickImage(bytes))
            {
                using (MagickImage image2 = new MagickImage(image.Clone()))
                {
                    image2.Alpha(AlphaOption.Off);
                    image2.Negate();
                    image2.Morphology(MorphologyMethod.Erode, Kernel.Diamond, 1);
                    image2.Blur();
                    image2.Level(new Percentage(50), new Percentage(100));

                    image.Alpha(AlphaOption.Off);
                    image.Composite(image2, CompositeOperator.CopyAlpha);

                    image.Write(AppDomain.CurrentDomain.BaseDirectory + "\\Image.png");
                }
            }
It does not seem like I get the white boarder anymore, but the entire image is half transparent when using the percentage as level. https://drive.google.com/file/d/1iMH426 ... sp=sharing

Help is still needed :?

Post Reply