Class AutoMaskingArgs

Class AutoMaskingArgs

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

Represents the arguments that are specified for automated masking methods

public class AutoMaskingArgs : IMaskingArgs
   {
       public string TemplateFile { get; set; }
       public int StartPage { get; set; }
       public int EndPage { get; set; }
       public bool UseHeaderFooterAsTemplate { get; set; }
       public MaskingType MaskingType { get; set; }
   }

Inheritance

object AutoMaskingArgs

Implements

IMaskingArgs

Inherited Members

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

Examples

This example shows how to decompose a raster image into multiple images using image masking and the K-means segmentation algorithm. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Blue hills.png"))
   {
       Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
       args.NumberOfObjects = 3;
       args.MaxIterationNumber = 50;
       args.Precision = 1;
       Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
       Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
       maskingOptions.Method = Masking.Options.SegmentationMethod.KMeans;
       maskingOptions.Decompose = true;
       maskingOptions.Args = args;
       maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
       maskingOptions.ExportOptions = exportOptions;
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
       {
           for (int i = 0; i < maskingResult.Length; i++)
           {
               string outputFileName = string.Format("Blue hills.Segment{0}.png", maskingResult[i].ObjectNumber);
               using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
               {
                   resultImage.Save(dir + outputFileName);
               }
           }
       }
   }

Using a segment mask to speed up the segmentation process

Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions()
   {
      ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha,
      Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream())
   };
   Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions()
   {
      Method = Masking.Options.SegmentationMethod.GraphCut,
      Decompose = false,
      Args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs(),
      BackgroundReplacementColor = Aspose.Imaging.Color.Transparent,
      ExportOptions = exportOptions
   };
   string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
   {
      Aspose.Imaging.Size imageSize = image.Size;
      image.ResizeHeightProportionally(600, Aspose.Imaging.ResizeType.HighQualityResample);
      Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
      using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
      {
         using (Aspose.Imaging.RasterImage foregroundMask = maskingResult[1].GetMask())
         {
            foregroundMask.Resize(imageSize.Width, imageSize.Height, Aspose.Imaging.ResizeType.NearestNeighbourResample);
            using (Aspose.Imaging.RasterImage originImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
            {
               Aspose.Imaging.Masking.ImageMasking.ApplyMask(originImage, foregroundMask, maskingOptions);
               originImage.Save(dir + "BigImage_foreground.png", exportOptions);
            }
         }
      }
   }

This example shows how to specify suggestions for image masking algorithm to improve precision of segmentation (clustering) method. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = Aspose.Imaging.Image.Load(dir + "Gorilla.bmp"))
   {
       Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
       args.ObjectsRectangles = new Rectangle[]
       {
           new Rectangle(86, 6, 270, 364),
       };
       args.ObjectsPoints = new Point[][]
       {
           new Point[] { new Point(103, 326) },
           new Point[] { new Point(280, 43) },
           new Point[] { new Point(319, 86) },
       };
       Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       exportOptions.Source = new System.IO.MemoryStream();
       Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
       maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
       maskingOptions.Decompose = false;
       maskingOptions.Args = args;
       maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
       maskingOptions.ExportOptions = exportOptions;
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
       {
           for (int i = 0; i < maskingResult.Length; i++)
           {
               string outputFileName = string.Format("Gorilla.Segment{0}.png", maskingResult[i].ObjectNumber);
               using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
               {
                   resultImage.Save(dir + outputFileName);
               }
           }
       }
   }

Saving the masking session to a file for long sessions, as well as for the possibility of resuming the session in another environment.

string dir = "c:\\temp\\";
   string sessionBackupFile = dir + "session.bak";
   Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
   Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
   maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
   maskingOptions.Decompose = false;
   maskingOptions.Args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
   maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
   maskingOptions.ExportOptions = exportOptions;
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Gorilla.bmp"))
   {
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.IMaskingSession session = masking.CreateSession(maskingOptions))
       {
           using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = session.Decompose())
           {
               using (Aspose.Imaging.RasterImage segmentImage = maskingResult[1].GetImage())
               {
                   segmentImage.Save(dir + "step1.png");
               }
           }
           session.Save(sessionBackupFile);
       }
   }
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Gorilla.bmp"))
   {
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.IMaskingSession session = masking.LoadSession(sessionBackupFile))
       {
           Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
           args.ObjectsPoints = new Point[][]
           {
               new Point[]
               {
                   new Point(0, 0), new Point(0, 1), new Point(1, 0),
                   new Point(1, 1), new Point(2, 0), new Point(2, 1),
                   new Point(3, 0), new Point(3, 1)
               },
           };
           using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = session.ImproveDecomposition(args))
           {
               maskingResult.MaskingOptions.ExportOptions = exportOptions;
               using (Aspose.Imaging.RasterImage segmentImage = maskingResult[1].GetImage())
               {
                   segmentImage.Save(dir + "step2.png");
               }
           }
       }
   }

Constructors

AutoMaskingArgs()

public AutoMaskingArgs()
   {
      this.Action = MaskAction.ClearText;
      this.Format = FormatType.None;
      this.IgnoreWhiteSpace = false;
      this.IgnoreMinorRevisions = false;
   }

Properties

MaxIterationNumber

Gets or sets the maximum number of iterations.

public int MaxIterationNumber
   {
      get;
      set;
   }

Property Value

int

Examples

This example shows how to decompose a raster image into multiple images using image masking and the K-means segmentation algorithm. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Blue hills.png"))
   {
       Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
       args.NumberOfObjects = 3;
       args.MaxIterationNumber = 50;
       args.Precision = 1;
       Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
       Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
       maskingOptions.Method = Masking.Options.SegmentationMethod.KMeans;
       maskingOptions.Decompose = true;
       maskingOptions.Args = args;
       maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
       maskingOptions.ExportOptions = exportOptions;
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
       {
           for (int i = 0; i < maskingResult.Length; i++)
           {
               string outputFileName = string.Format("Blue hills.Segment{0}.png", maskingResult[i].ObjectNumber);
               using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
               {
                   resultImage.Save(dir + outputFileName);
               }
           }
       }
   }

NumberOfObjects

Gets or sets the number of objectsto separate initial image to (optional), default value is 2 (object and background).

public int NumberOfObjects
   {
      get;
      set;
   }

Property Value

int

Examples

This example shows how to decompose a raster image into multiple images using image masking and the K-means segmentation algorithm. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Blue hills.png"))
   {
      Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
      args.NumberOfObjects = 3;
      args.MaxIterationNumber = 50;
      args.Precision = 1;
      Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
      exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
      exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
      Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
      maskingOptions.Method = Masking.Options.SegmentationMethod.KMeans;
      maskingOptions.Decompose = true;
      maskingOptions.Args = args;
      maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
      maskingOptions.ExportOptions = exportOptions;
      Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
      using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
      {
         for (int i = 0; i < maskingResult.Length; i++)
         {
            string outputFileName = string.Format("Blue hills.Segment{0}.png", maskingResult[i].ObjectNumber);
            using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
            {
                resultImage.Save(dir + outputFileName);
            }
         }
      }
   }

ObjectsPoints

Gets or sets the points that belong to separated objects (optional)NumberOfObjects coordinates that belong to NumberOfObjects objects of initial image.This parameter is used to increase segmentation method precision.

public Point[][] ObjectsPoints
   {
      get;
      set;
   }

Property Value

Point [][]

Examples

This example shows how to specify suggestions for image masking algorithm to improve precision of segmentation (clustering) method. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = Aspose.Imaging.Image.Load(dir + "Gorilla.bmp"))
   {
      Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
      args.ObjectsRectangles = new Rectangle[]
      {
         new Rectangle(86, 6, 270, 364),
      };
      args.ObjectsPoints = new Point[][]
      {
         new Point[] { new Point(103, 326) },
         new Point[] { new Point(280, 43) },
         new Point[] { new Point(319, 86) },
      };
      Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
      exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
      exportOptions.Source = new System.IO.MemoryStream();
      Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
      maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
      maskingOptions.Decompose = false;
      maskingOptions.Args = args;
      maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
      maskingOptions.ExportOptions = exportOptions;
      Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
      using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
      {
         for (int i = 0; i < maskingResult.Length; i++)
         {
            string outputFileName = string.Format("Gorilla.Segment{0}.png", maskingResult[i].ObjectNumber);
            using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
            {
                resultImage.Save(dir + outputFileName);
            }
         }
      }
   }

ObjectsRectangles

Gets or sets the objects rectangles that belong to separated objects (optional).This parameter is used to increase segmentation method precision.

public Rectangle[] ObjectsRectangles
   {
      get;
      set;
   }

Property Value

Rectangle []

Examples

This example shows how to specify suggestions for image masking algorithm to improve precision of segmentation (clustering) method. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Gorilla.bmp"))
   {
       Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
       args.ObjectsRectangles = new Rectangle[]
       {
           new Rectangle(86, 6, 270, 364),
       };
       args.ObjectsPoints = new Point[][]
       {
           new Point[] { new Point(103, 326) },
           new Point[] { new Point(280, 43) },
           new Point[] { new Point(319, 86) },
       };
       Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
       Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
       maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
       maskingOptions.Decompose = false;
       maskingOptions.Args = args;
       maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
       maskingOptions.ExportOptions = exportOptions;
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
       {
           for (int i = 0; i < maskingResult.Length; i++)
           {
               string outputFileName = string.Format("Gorilla.Segment{0}.png", maskingResult[i].ObjectNumber);
               using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
               {
                   resultImage.Save(dir + outputFileName);
               }
           }
       }
   }

OrphanedPoints

Gets or sets the points that no longer belong to any object (optional).This parameter is used only in case of re-segmentation.

public Point[] OrphanedPoints
   {
      get;
      set;
   }

Property Value

Point []

Precision

Gets or sets the precision of segmentation method (optional).

public double Precision
   {
      get;
      set;
   }

Property Value

double

Examples

This example shows how to decompose a raster image into multiple images using image masking and the K-means segmentation algorithm. Image masking is an image processing technique that is used to split the background from the foreground image objects.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "Blue hills.png"))
   {
       Aspose.Imaging.Masking.Options.AutoMaskingArgs args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
       args.NumberOfObjects = 3;
       args.MaxIterationNumber = 50;
       args.Precision = 1;
       Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
       Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
       maskingOptions.Method = Masking.Options.SegmentationMethod.KMeans;
       maskingOptions.Decompose = true;
       maskingOptions.Args = args;
       maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Orange;
       maskingOptions.ExportOptions = exportOptions;
       Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
       using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
       {
           for (int i = 0; i < maskingResult.Length; i++)
           {
               string outputFileName = string.Format("Blue hills.Segment{0}.png", maskingResult[i].ObjectNumber);
               using (Aspose.Imaging.Image resultImage = maskingResult[i].GetImage())
               {
                   resultImage.Save(dir + outputFileName);
               }
           }
       }
   }

See Also

IMaskingArgs

 English