Class that contains setting for the connected components operation.
Example #1
0
    public void Test_ConnectedComponents()
    {
      using (MagickImage image = new MagickImage(Files.ConnectedComponentsPNG))
      {
        using (MagickImage temp = image.Clone())
        {
          temp.Blur(0, 10);
          temp.Threshold((Percentage)50);

          ConnectedComponent[] components = temp.ConnectedComponents(4).OrderBy(c => c.X).ToArray();
          Assert.AreEqual(7, components.Length);
          Assert.IsNull(temp.GetArtifact("connected-components:area-threshold"));
          Assert.IsNull(temp.GetArtifact("connected-components:mean-color"));

          Test_Component(image, components[1], 94, 297, 128, 151);
          Test_Component(image, components[2], 99, 554, 128, 150);
          Test_Component(image, components[3], 267, 432, 89, 139);
          Test_Component(image, components[4], 301, 202, 148, 143);
          Test_Component(image, components[5], 341, 622, 136, 150);
          Test_Component(image, components[6], 434, 411, 88, 139);
        }

#if !Q8
        using (MagickImage temp = image.Clone())
        {
          ConnectedComponentsSettings settings = new ConnectedComponentsSettings()
          {
            Connectivity = 4,
            MeanColor = true,
            AreaThreshold = 400
          };

          ConnectedComponent[] components = temp.ConnectedComponents(settings).OrderBy(c => c.X).ToArray();
          Assert.AreEqual(13, components.Length);
          Assert.IsNotNull(temp.GetArtifact("connected-components:area-threshold"));
          Assert.IsNotNull(temp.GetArtifact("connected-components:mean-color"));

          Test_Component(image, components[1], 90, 293, 139, 162);
          Test_Component(image, components[2], 96, 550, 138, 162);
          Test_Component(image, components[3], 213, 633, 1, 2);
          Test_Component(image, components[4], 215, 637, 3, 1);
          Test_Component(image, components[5], 217, 641, 3, 1);
          Test_Component(image, components[6], 219, 645, 3, 1);
          Test_Component(image, components[7], 221, 647, 3, 1);
          Test_Component(image, components[8], 268, 433, 89, 139);
          Test_Component(image, components[9], 298, 198, 155, 151);
          Test_Component(image, components[10], 337, 618, 148, 158);
          Test_Component(image, components[11], 410, 247, 2, 1);
          Test_Component(image, components[12], 434, 411, 88, 140);
        }
#endif
      }
    }