Remove lines from bi-tonal images (Novice question)

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
tdhintz
Posts: 2
Joined: 2017-08-24T11:56:32-07:00
Authentication code: 1151

Remove lines from bi-tonal images (Novice question)

Post by tdhintz »

I'm trying to replicate something like the following windows BAT command using C#. viewtopic.php?t=22338

Code: Select all

convert Test2image.png -strip -write mpr:ORG ^
  ( +clone ^
    -negate ^
    -morphology Erode rectangle:50x1 ^
    -mask mpr:ORG -morphology Dilate rectangle:50x1 ^
    +mask ^
  ) ^
  -compose Lighten -composite ^
  ( +clone ^
    -morphology HMT "1x4:1,0,0,1" ^
  ) ^
  -compose Lighten -composite ^
  ( +clone ^
    -morphology HMT "1x3:1,0,1" ^
  ) ^
  -compose Lighten -composite ^
  ( +clone ^
    -morphology HMT "3x1:1,0,1" ^
  ) ^
  -compose Lighten -composite ^
  out.png
The first part seems easy but the rest is lost in translation. What is the C# equiv to this command?

Code: Select all

myimage.Strip();
using (var mask = myimage.Clone())
{
    mask.Negate();
    mask.Morphology(MorphologyMethod.Erode, "rectangle:50x1");
    // What is -mask and +mask?
}
tdhintz
Posts: 2
Joined: 2017-08-24T11:56:32-07:00
Authentication code: 1151

Re: Remove lines from bi-tonal images (Novice question)

Post by tdhintz »

-/+ mask appear to be missing from the on-line docs I read. Is the following a faithful reproduction of the command line version? I'm just wanting to know if I understand the principals.

Code: Select all

    mi.Strip();
    using (var hlines = mi.Clone())
    {            
        hlines.Negate();
        hlines.Morphology(MorphologyMethod.Erode, "rectangle:50x1");
        hlines.WriteMask = mi;
        hlines.Morphology(MorphologyMethod.Dilate, "rectangle:50x1");
        hlines.WriteMask = null;

        mi.Composite(hlines, CompositeOperator.Lighten);
    }

    using (var b = mi.Clone())
    {
        b.Morphology(MorphologyMethod.HitAndMiss, "1x4:1,0,0,1");

        mi.Composite(b, CompositeOperator.Lighten);
    }

    using (var b2 = mi.Clone())
    {
        b2.Morphology(MorphologyMethod.HitAndMiss, "1x3:1,0,1");

        mi.Composite(b2, CompositeOperator.Lighten);
    }

    using (var b2 = mi.Clone())
    {
        b2.Morphology(MorphologyMethod.HitAndMiss, "3x1:1,0,1");

        mi.Composite(b2, CompositeOperator.Lighten);
    }
Post Reply