Class AssumedObjectData

Class AssumedObjectData

Namespace: Aspose.Imaging.Masking.Options
Assembly: Aspose.Imaging.dll (25.7.0)

The assumed object’s data. Includes object’s type and area.

public class AssumedObjectData
   {
       private string _property1;
       private int _property2;
       public string Property1
       {
           get { return _property1; }
           set { _property1 = value; }
       }
       public int Property2
       {
           get { return _property2; }
           set { _property2 = value; }
       }
   }

Inheritance

object AssumedObjectData

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Saving image masking result with feathering based on image size. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the 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;
    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 });
    }

Saving image masking result with feathering based on image size and re-using masking options for the new masking iteration. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the AutoMaskingGraphCutOptions. After getting initial masking result, applied background/foreground strokes are modified and another masking iteration is performed.

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);
    }
    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"))
    {
        options.CalculateDefaultStrokes = false;
        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 });
    }

Saving image masking result with feathering based on image size, modifying obtained default strokes and using it for the new masking iteration. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the AutoMaskingGraphCutOptions. After getting initial masking result, applied background/foreground strokes are modified and another masking iteration is performed using new GraphCutMaskingOptions instance.

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);
   }
   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 });
   }

Constructors

AssumedObjectData()

Initializes a new instance of the Aspose.Imaging.Masking.Options.AssumedObjectData class.

public AssumedObjectData()
   {
   }

AssumedObjectData(DetectedObjectType, Rectangle)

Initializes a new instance of the Aspose.Imaging.Masking.Options.AssumedObjectData class.

public AssumedObjectData(DetectedObjectType type, Rectangle bounds)
   {
   }

Parameters

type DetectedObjectType

The object’s type.

bounds Rectangle

The object’s bounds.

Examples

Saving image masking result with feathering based on image size. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the 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;
    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 });
    }

Saving image masking result with feathering based on image size and re-using masking options for the new masking iteration. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the AutoMaskingGraphCutOptions. After getting initial masking result, applied background/foreground strokes are modified and another masking iteration is performed.

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);
    }
    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"))
    {
        options.CalculateDefaultStrokes = false;
        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 });
    }

Saving image masking result with feathering based on image size, modifying obtained default strokes and using it for the new masking iteration. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the AutoMaskingGraphCutOptions. After getting initial masking result, applied background/foreground strokes are modified and another masking iteration is performed using new GraphCutMaskingOptions instance.

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);
   }
   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(string, Rectangle)

Initializes a new instance of the Aspose.Imaging.Masking.Options.AssumedObjectData class.

public AssumedObjectData(string type, Rectangle bounds)
   {
       this.Type = type;
       this.Bounds = bounds;
   }

Parameters

type string

The object’s type.

bounds Rectangle

The object’s bounds.

Properties

Bounds

Gets or sets the object’s bounds.

public Rectangle Bounds
    {
        get;
        set;
    }

Property Value

Rectangle

Type

Gets or sets the object’s type.

public DetectedObjectType Type
   {
      get;
      set;
   }

Property Value

DetectedObjectType

 English