public class AutoMaskingArgs extends Object implements IMaskingArgs
Represents the arguments that are specified for automated masking methods
IMaskingArgsThis 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\\";
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load(dir + "Blue hills.png");
try {
com.aspose.imaging.masking.options.AutoMaskingArgs args = new com.aspose.imaging.masking.options.AutoMaskingArgs();
// Set the number of clusters (separated objects). The default value is 2, the foreground object and the background.
args.setNumberOfObjects(3);
// Set the maximum number of iterations.
args.setMaxIterationNumber(50);
// Set the precision of segmentation method (optional)
args.setPrecision(1);
// Each cluster (segment) will be stored to a separate PNG file.
com.aspose.imaging.imageoptions.PngOptions exportOptions = new com.aspose.imaging.imageoptions.PngOptions();
exportOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha);
exportOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0])));
com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();
// Use K-means clustering.
// K-means clustering allows to split image into several independent clusters (segments).
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.KMeans);
maskingOptions.setDecompose(true);
maskingOptions.setArgs(args);
// The backgroung color will be orange.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getOrange());
maskingOptions.setExportOptions(exportOptions);
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);
// Divide the source image into several clusters (segments).
com.aspose.imaging.masking.result.MaskingResult maskingResults = masking.decompose(maskingOptions);
try
{
// Obtain images from masking result and save them to PNG.
for (int i = 0; i < maskingResults.getLength(); i++) {
final IMaskingLayer resultsItem = maskingResults.get_Item(i);
String outputFileName = String.format("Blue hills.Segment%s.png", resultsItem.getObjectNumber());
Image resultImage = resultsItem.getImage();
try {
resultImage.save(dir + outputFileName);
} finally {
resultImage.close();
}
}
}
finally
{
maskingResults.close();
}
} finally {
image.close();
}
| Constructor and Description |
|---|
AutoMaskingArgs() |
| Modifier and Type | Method and Description |
|---|---|
int |
getMaxIterationNumber()
Gets the maximum number of iterations.
|
int |
getNumberOfObjects()
Gets the number of objects
to separate initial image to (optional), default value is 2 (object and background).
|
Point[][] |
getObjectsPoints()
Gets the points that belong to separated objects (optional)
NumberOfObjects coordinates that belong to NumberOfObjects objects of initial image.
|
Rectangle[] |
getObjectsRectangles()
Gets the objects rectangles that belong to separated objects (optional).
|
Point[] |
getOrphanedPoints()
Gets the points that no longer belong to any object (optional).
|
double |
getPrecision()
Gets the precision of segmentation method (optional).
|
void |
setMaxIterationNumber(int value)
Sets the maximum number of iterations.
|
void |
setNumberOfObjects(int value)
Sets the number of objects
to separate initial image to (optional), default value is 2 (object and background).
|
void |
setObjectsPoints(Point[][] value)
Sets the points that belong to separated objects (optional)
NumberOfObjects coordinates that belong to NumberOfObjects objects of initial image.
|
void |
setObjectsRectangles(Rectangle[] value)
Sets the objects rectangles that belong to separated objects (optional).
|
void |
setOrphanedPoints(Point[] value)
Sets the points that no longer belong to any object (optional).
|
void |
setPrecision(double value)
Sets the precision of segmentation method (optional).
|
public final int getNumberOfObjects()
Gets the number of objects to separate initial image to (optional), default value is 2 (object and background).
Value: The number of objects.public final void setNumberOfObjects(int value)
Sets the number of objects to separate initial image to (optional), default value is 2 (object and background).
Value: The number of objects.value - the number of objects
to separate initial image to (optional), default value is 2 (object and background).public final Rectangle[] getObjectsRectangles()
Gets the objects rectangles that belong to separated objects (optional). This parameter is used to increase segmentation method precision.
Value: The objects rectangles.public final void setObjectsRectangles(Rectangle[] value)
Sets the objects rectangles that belong to separated objects (optional). This parameter is used to increase segmentation method precision.
Value: The objects rectangles.value - the objects rectangles that belong to separated objects (optional).public final Point[][] getObjectsPoints()
Gets 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.
Value: The objects points.public final void setObjectsPoints(Point[][] value)
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.
Value: The objects points.value - the points that belong to separated objects (optional)
NumberOfObjects coordinates that belong to NumberOfObjects objects of initial image.public final Point[] getOrphanedPoints()
Gets the points that no longer belong to any object (optional). This parameter is used only in case of re-segmentation.
Value: The orphaned points.public final void setOrphanedPoints(Point[] value)
Sets the points that no longer belong to any object (optional). This parameter is used only in case of re-segmentation.
Value: The orphaned points.value - the points that no longer belong to any object (optional).public final double getPrecision()
Gets the precision of segmentation method (optional).
Value: The precision of segmentation method (optional).public final void setPrecision(double value)
Sets the precision of segmentation method (optional).
Value: The precision of segmentation method (optional).value - the precision of segmentation method (optional).public final int getMaxIterationNumber()
Gets the maximum number of iterations.
Value: The maximum maximum number of iterations.public final void setMaxIterationNumber(int value)
Sets the maximum number of iterations.
Value: The maximum maximum number of iterations.value - the maximum number of iterations.Copyright (c) 2008-2022 Aspose Pty Ltd. All Rights Reserved.