Page 1 of 1

Remove lines from bi-tonal images (Novice question)

Posted: 2017-08-24T12:14:40-07:00
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?
}

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

Posted: 2017-08-24T15:15:50-07:00
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);
    }