Packages

 

com.aspose.imaging.masking.options

Class GraphCutMaskingOptions

  • Direct Known Subclasses:
    AutoMaskingGraphCutOptions


    public class GraphCutMaskingOptions
    extends MaskingOptions

    The GraphCut auto masking options.

    Code example:

    Saving image masking result with feathering based on image size. Image masking is performed using auto calculated default strokes. The Args property of AutoMaskingGraphCutOptions can be omitted since default strokes are placed there in the end.MaskingResult[] results;


    
    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.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

      • GraphCutMaskingOptions

        public GraphCutMaskingOptions()
    • Method Detail

      • getFeatheringRadius

        public final int getFeatheringRadius()

        Gets the feathering radius.

        Returns:
        the feathering radius.
      • setFeatheringRadius

        public final void setFeatheringRadius(int value)

        Sets the feathering radius.

        Parameters:
        value - the feathering radius.
        Code example:

        Saving image masking result with feathering based on image size. Image masking is performed using auto calculated default strokes. The Args property of AutoMaskingGraphCutOptions can be omitted since default strokes are placed there in the end.MaskingResult[] results;


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