Class GraphCutMaskingOptions

Class GraphCutMaskingOptions

名称: Aspose.Imaging.Masking.Options アセンション: Aspose.Imaging.dll (25.4.0)

GraphCut 自動マッキングオプション

public class GraphCutMaskingOptions : MaskingOptions

Inheritance

object MaskingOptions GraphCutMaskingOptions

Derived

AutoMaskingGraphCutOptions

相続人

MaskingOptions.BackgroundObjectNumber , MaskingOptions.Method , MaskingOptions.Args , MaskingOptions.ExportOptions , MaskingOptions.MaskingArea , MaskingOptions.Decompose , MaskingOptions.BackgroundReplacementColor , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

画像マッキングは自動的に計算されたデフォルトストライキを使用して行われます。AutoMaskingGraphCutOptionsのArgs属性は、デフォルトストライキが最終的にそこに置かれているため、無視することができます。

MaskingResult[] results;
                                                                                                                                                                                                                                                               using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                   AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                                                                   CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                   FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
                                                                                                                                                                                                                                                                                                                   Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                   Decompose = false,
                                                                                                                                                                                                                                                                                                                   ExportOptions =
                                                                                                                                                                                                                                                                                                                       new PngOptions()
                                                                                                                                                                                                                                                                                                                           {
                                                                                                                                                                                                                                                                                                                               ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                               Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                           },
                                                                                                                                                                                                                                                                                                                   BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                   };

                                                                                                                                                                                                                                                                   results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                               }

                                                                                                                                                                                                                                                               using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                   resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                               }

画像マッキングは自動的に計算されたデフォルトストライキを使用して行われます さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsの AssumedObjects属性にも記載されています。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                  MaskingResult[] results;
                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                      AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                      AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                      CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                      FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
                                                                                                                                                                                                                                                                                                                                      Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                      Decompose = false,
                                                                                                                                                                                                                                                                                                                                      ExportOptions =
                                                                                                                                                                                                                                                                                                                                          new PngOptions()
                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                  ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                  Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                              },
                                                                                                                                                                                                                                                                                                                                      BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                      };

                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                  }</assumedobjectdata></assumedobjectdata>

保存グラフカット画像マッキングの結果は、フェアリングに設定されます 3. 画像マッキングは、指定されたポイント順を使用して行われます。

MaskingResult[] results;
                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                  {
                                                                                                                                      GraphCutMaskingOptions options = new GraphCutMaskingOptions()
                                                                                                                                                                                  {
                                                                                                                                                                                      FeatheringRadius = 3,
                                                                                                                                                                                      Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                      Decompose = false,
                                                                                                                                                                                      ExportOptions =
                                                                                                                                                                                          new PngOptions()
                                                                                                                                                                                              {
                                                                                                                                                                                                  ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                  Source = new FileCreateSource("tempFile")
                                                                                                                                                                                              },
                                                                                                                                                                                      BackgroundReplacementColor = Color.Transparent,
                                                                                                                                                                                      Args = new AutoMaskingArgs()
                                                                                                                                                                                              {
                                                                                                                                                                                                  ObjectsPoints = new Point[][]
                                                                                                                                                                                                                      {
                                                                                                                                                                                                                          new Point[]
                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                  new Point(100, 100),
                                                                                                                                                                                                                              },
                                                                                                                                                                                                                      }
                                                                                                                                                                                              }
                                                                                                                                                                                  };

                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                  }

                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                  {
                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                  }

画像マッキングの結果を保存する画像サイズに基づいてフェアリングと再利用マッキングのオプションの新しいマッキングイーテレーション. 画像マッキングは自動的に計算されたデフォルトストライキを使用して実行されます. さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsのアサムドオブジェクトの特性にも指定されます. 最初のマッキングの結果を得た後、適用された背景/フロアグラウンドストライキが変更され、別のマッキングイーテレーションが実行されます。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  MaskingResult[] results;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  AutoMaskingGraphCutOptions options;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ExportOptions =
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      };

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  // At this point applied foreground/background strokes can be analyzed and based on it additional 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  // foreground/background strokes can be manually provided.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Point[] appliedBackgroundStrokes = options.DefaultBackgroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Point[] appliedForegroundStrokes = options.DefaultForegroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Rectangle[] appliedObjectRectangles = options.DefaultObjectsRectangles;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // Re-using AutoMaskingGraphCutOptions there is no need to perform default strokes calculations second time.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options.CalculateDefaultStrokes = false;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // When both default strokes and ObjectsPoints in the Args property of AutoMaskingArgs are provided, Point arrays are end up combined.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // The first ObjectsPoints array is considered to be a background points array and 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // the second ObjectsPoints array is considered to be a foreground points array.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // When both DefaultObjectsRectangles and ObjectsRectangles in the Args property of AutoMaskingArgs are provided, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // only the array from the Args is being used.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options.Args = new AutoMaskingArgs()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ObjectsPoints = new Point[][]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      new Point[] { new Point(100, 100), new Point(150, 100) }, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      new Point[] { new Point(500, 200) }, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ObjectsRectangles = new Rectangle[]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          new Rectangle(100, 100, 300, 300), 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          };
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }</assumedobjectdata></assumedobjectdata>

画像マッキングの結果を保存する画像サイズに基づいてフェアリングで、取得したデフォルトストライキを変更し、新しいマッキングイテレーションのために使用します。画像マッキングは自動的に計算されたデフォルトストライキを使用して実行されます。さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsのアサムドオブジェクトの特性にも指定されます。最初のマッキングの結果を得た後、適用された背景/フロアグラムストライキが変更され、別のマッキングイテレーションは新しい GraphCutMaskingOptionsの例を使用して実行されます。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                MaskingResult[] results;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                AutoMaskingGraphCutOptions options;

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ExportOptions =
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    };

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // At this point applied foreground/background strokes can be analyzed and based on it additional 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // foreground/background strokes can be manually provided.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Point[] appliedBackgroundStrokes = options.DefaultBackgroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Point[] appliedForegroundStrokes = options.DefaultForegroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Rectangle[] appliedObjectRectangles = options.DefaultObjectsRectangles;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedBackgroundStrokes[5] = new Point(100, 100);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedBackgroundStrokes[15] = new Point(150, 100);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedForegroundStrokes[1] = new Point(500, 200);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedObjectRectangles[0] = new Rectangle(100, 100, 300, 300);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    GraphCutMaskingOptions graphCutOptions = new GraphCutMaskingOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ExportOptions = new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        BackgroundReplacementColor = Color.Transparent,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Args = new AutoMaskingArgs()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ObjectsPoints = new Point[][]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            appliedBackgroundStrokes,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            appliedForegroundStrokes
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ObjectsRectangles = appliedObjectRectangles
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    };
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    results = new ImageMasking(image).Decompose(graphCutOptions);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }</assumedobjectdata></assumedobjectdata>

Constructors

GraphCutMaskingOptions()

public GraphCutMaskingOptions()

Properties

FeatheringRadius

接続または接続ラジオを設定する

public int FeatheringRadius { get; set; }

不動産価値

int

Examples

画像マッキングは自動的に計算されたデフォルトストライキを使用して行われます。AutoMaskingGraphCutOptionsのArgs属性は、デフォルトストライキが最終的にそこに置かれているため、無視することができます。

MaskingResult[] results;
                                                                                                                                                                                                                                                               using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                   AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                                                                   CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                   FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
                                                                                                                                                                                                                                                                                                                   Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                   Decompose = false,
                                                                                                                                                                                                                                                                                                                   ExportOptions =
                                                                                                                                                                                                                                                                                                                       new PngOptions()
                                                                                                                                                                                                                                                                                                                           {
                                                                                                                                                                                                                                                                                                                               ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                               Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                           },
                                                                                                                                                                                                                                                                                                                   BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                   };

                                                                                                                                                                                                                                                                   results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                               }

                                                                                                                                                                                                                                                               using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                               {
                                                                                                                                                                                                                                                                   resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                               }

画像マッキングは自動的に計算されたデフォルトストライキを使用して行われます さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsの AssumedObjects属性にも記載されています。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                  MaskingResult[] results;
                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                      AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                      AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                      CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                      FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
                                                                                                                                                                                                                                                                                                                                      Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                      Decompose = false,
                                                                                                                                                                                                                                                                                                                                      ExportOptions =
                                                                                                                                                                                                                                                                                                                                          new PngOptions()
                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                  ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                  Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                              },
                                                                                                                                                                                                                                                                                                                                      BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                      };

                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                  }</assumedobjectdata></assumedobjectdata>

保存グラフカット画像マッキングの結果は、フェアリングに設定されます 3. 画像マッキングは、指定されたポイント順を使用して行われます。

MaskingResult[] results;
                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                  {
                                                                                                                                      GraphCutMaskingOptions options = new GraphCutMaskingOptions()
                                                                                                                                                                                  {
                                                                                                                                                                                      FeatheringRadius = 3,
                                                                                                                                                                                      Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                      Decompose = false,
                                                                                                                                                                                      ExportOptions =
                                                                                                                                                                                          new PngOptions()
                                                                                                                                                                                              {
                                                                                                                                                                                                  ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                  Source = new FileCreateSource("tempFile")
                                                                                                                                                                                              },
                                                                                                                                                                                      BackgroundReplacementColor = Color.Transparent,
                                                                                                                                                                                      Args = new AutoMaskingArgs()
                                                                                                                                                                                              {
                                                                                                                                                                                                  ObjectsPoints = new Point[][]
                                                                                                                                                                                                                      {
                                                                                                                                                                                                                          new Point[]
                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                  new Point(100, 100),
                                                                                                                                                                                                                              },
                                                                                                                                                                                                                      }
                                                                                                                                                                                              }
                                                                                                                                                                                  };

                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                  }

                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                  {
                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                  }

画像マッキングの結果を保存する画像サイズに基づいてフェアリングと再利用マッキングのオプションの新しいマッキングイーテレーション. 画像マッキングは自動的に計算されたデフォルトストライキを使用して実行されます. さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsのアサムドオブジェクトの特性にも指定されます. 最初のマッキングの結果を得た後、適用された背景/フロアグラウンドストライキが変更され、別のマッキングイーテレーションが実行されます。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  MaskingResult[] results;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  AutoMaskingGraphCutOptions options;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ExportOptions =
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      };

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  // At this point applied foreground/background strokes can be analyzed and based on it additional 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  // foreground/background strokes can be manually provided.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Point[] appliedBackgroundStrokes = options.DefaultBackgroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Point[] appliedForegroundStrokes = options.DefaultForegroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Rectangle[] appliedObjectRectangles = options.DefaultObjectsRectangles;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // Re-using AutoMaskingGraphCutOptions there is no need to perform default strokes calculations second time.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options.CalculateDefaultStrokes = false;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // When both default strokes and ObjectsPoints in the Args property of AutoMaskingArgs are provided, Point arrays are end up combined.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // The first ObjectsPoints array is considered to be a background points array and 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // the second ObjectsPoints array is considered to be a foreground points array.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // When both DefaultObjectsRectangles and ObjectsRectangles in the Args property of AutoMaskingArgs are provided, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      // only the array from the Args is being used.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      options.Args = new AutoMaskingArgs()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ObjectsPoints = new Point[][]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      new Point[] { new Point(100, 100), new Point(150, 100) }, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      new Point[] { new Point(500, 200) }, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ObjectsRectangles = new Rectangle[]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          new Rectangle(100, 100, 300, 300), 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          };
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }</assumedobjectdata></assumedobjectdata>

画像マッキングの結果を保存する画像サイズに基づいてフェアリングで、取得したデフォルトストライキを変更し、新しいマッキングイテレーションのために使用します。画像マッキングは自動的に計算されたデフォルトストライキを使用して実行されます。さらに、2つの仮定オブジェクトのデータは、AutoMaskingGraphCutOptionsのアサムドオブジェクトの特性にも指定されます。最初のマッキングの結果を得た後、適用された背景/フロアグラムストライキが変更され、別のマッキングイテレーションは新しい GraphCutMaskingOptionsの例を使用して実行されます。

List<assumedobjectdata> assumedObjects = new List<assumedobjectdata>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300)));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                assumedObjects.Add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30)));

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                MaskingResult[] results;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                AutoMaskingGraphCutOptions options;

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    options = new AutoMaskingGraphCutOptions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        AssumedObjects = assumedObjects,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        CalculateDefaultStrokes = true,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ExportOptions =
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        BackgroundReplacementColor = Color.Transparent
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    };

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    results = new ImageMasking(image).Decompose(options);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // At this point applied foreground/background strokes can be analyzed and based on it additional 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // foreground/background strokes can be manually provided.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Point[] appliedBackgroundStrokes = options.DefaultBackgroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Point[] appliedForegroundStrokes = options.DefaultForegroundStrokes;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Rectangle[] appliedObjectRectangles = options.DefaultObjectsRectangles;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedBackgroundStrokes[5] = new Point(100, 100);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedBackgroundStrokes[15] = new Point(150, 100);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedForegroundStrokes[1] = new Point(500, 200);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                appliedObjectRectangles[0] = new Rectangle(100, 100, 300, 300);

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage image = (RasterImage)Image.Load("input.jpg"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    GraphCutMaskingOptions graphCutOptions = new GraphCutMaskingOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        FeatheringRadius = 3,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Method = SegmentationMethod.GraphCut,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Decompose = false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ExportOptions = new PngOptions()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ColorType = PngColorType.TruecolorWithAlpha,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Source = new FileCreateSource("tempFile")
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        BackgroundReplacementColor = Color.Transparent,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Args = new AutoMaskingArgs()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ObjectsPoints = new Point[][]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            appliedBackgroundStrokes,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            appliedForegroundStrokes
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ObjectsRectangles = appliedObjectRectangles
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    };
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    results = new ImageMasking(image).Decompose(graphCutOptions);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                using (RasterImage resultImage = (RasterImage)results[1].GetImage())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    resultImage.Save("output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                }</assumedobjectdata></assumedobjectdata>
 日本語