Packages

 

com.aspose.imaging.masking.options

Class AssumedObjectData



  • public class AssumedObjectData
    extends Object

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

    Code example:

    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 LinkedList<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;
    try (RasterImage image = (RasterImage)Image.load("input.jpg"))
    {
        try (PngOptions pngOptions = new PngOptions())
        {
            pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
            pngOptions.setSource(new FileCreateSource("tempFile"));
    
            AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions();
            options.setAssumedObjects(assumedObjects);
            options.setCalculateDefaultStrokes(true);
            options.setFeatheringRadius((Math.max(image.getWidth(), image.getHeight()) / 500) + 1);
            options.setMethod(SegmentationMethod.GraphCut);
            options.setDecompose(false);
            options.setExportOptions(pngOptions);
            options.setBackgroundReplacementColor(Color.getTransparent());
    
            results = new ImageMasking(image).decompose(options);
        }
    }
    
    try (RasterImage resultImage = (RasterImage)results[1].getImage())
    {
        PngOptions pngOptions = new PngOptions();
        pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
        resultImage.save("output.png", pngOptions);
    }
    
    // release resources
    for (MaskingResult res : results)
    {
        res.close();
    }
                
    

    • Constructor Detail

      • AssumedObjectData

        public AssumedObjectData()

        Initializes a new instance of the AssumedObjectData class.

      • AssumedObjectData

        public AssumedObjectData(int type,
                                 Rectangle bounds)

        Initializes a new instance of the AssumedObjectData class.

        Parameters:
        type - The object's type.
        bounds - The object's bounds.
        See Also:
        DetectedObjectType
      • AssumedObjectData

        public AssumedObjectData(String type,
                                 Rectangle bounds)

        Initializes a new instance of the AssumedObjectData class.

        Parameters:
        type - The object's type.
        bounds - The object's bounds.
    • Method Detail

      • getType

        public final int getType()

        Gets the object's type.

        Returns:
        the object's type.
      • setType

        public final void setType(int value)

        Sets the object's type.

        Parameters:
        value - the object's type.
      • getBounds

        public final Rectangle getBounds()

        Gets the object's bounds.

        Returns:
        the object's bounds.
      • setBounds

        public final void setBounds(Rectangle value)

        Sets the object's bounds.

        Parameters:
        value - the object's bounds.