public class GraphCutMaskingOptions extends MaskingOptions
The GraphCut auto masking options.
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(); }
BACKGROUND_OBJECT_NUMBER
Constructor and Description |
---|
GraphCutMaskingOptions() |
Modifier and Type | Method and Description |
---|---|
int |
getFeatheringRadius()
Gets the feathering radius.
|
void |
setFeatheringRadius(int value)
Sets the feathering radius.
|
getArgs, getBackgroundReplacementColor, getDecompose, getExportOptions, getMaskingArea, getMethod, setArgs, setBackgroundReplacementColor, setDecompose, setExportOptions, setMaskingArea, setMethod
public final int getFeatheringRadius()
Gets the feathering radius.
public final void setFeatheringRadius(int value)
Sets the feathering radius.
value
- the feathering radius.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(); }