IMaskingSession
All Implemented Interfaces: com.aspose.ms.System.IDisposable
public interface IMaskingSession extends System.IDisposable
The masking session
Methods
Method | Description |
---|---|
decompose() | Performs first rough decompose operation |
decomposeAsync() | Creates the asynchronous task which can perform first rough decompose operation |
improveDecomposition(IMaskingArgs maskingArguments) | Performs retraining decompose operation |
improveDecompositionAsync(IMaskingArgs maskingArguments) | Creates the asynchronous task which can perform retraining decompose operation |
save(OutputStream stream) | Save the session state to the specified stream. |
save(System.IO.Stream stream) | Save the session state to the specified stream. |
save(String filePath) | Saves the session state to the specified file. |
Example: 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";
// Masking export options
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());
com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();
// Use GraphCut clustering.
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.GraphCut);
maskingOptions.setDecompose(false);
maskingOptions.setArgs(new com.aspose.imaging.masking.options.AutoMaskingArgs());
// The background color will be orange.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getOrange());
maskingOptions.setExportOptions(exportOptions);
// Starting a session for the first time and saving to a file
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);
com.aspose.imaging.masking.IMaskingSession session = masking.createSession(maskingOptions);
try
{
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.decompose();
try
{
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step1.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
session.save(sessionBackupFile);
}
finally
{
session.dispose();
}
}
finally
{
image.close();
}
// Resuming a masking session from a file
com.aspose.imaging.RasterImage image2 = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image2);
com.aspose.imaging.masking.IMaskingSession session = masking.loadSession(sessionBackupFile);
try
{
com.aspose.imaging.masking.options.AutoMaskingArgs args = new com.aspose.imaging.masking.options.AutoMaskingArgs();
// Analyze the image visually and set the points that belong to separated objects.
args.setObjectsPoints(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)
},
});
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.improveDecomposition(args);
try
{
// Explicit transfer of export options, since it is not serializable
maskingResult.MaskingOptions.setExportOptions(exportOptions);
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step2.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
}
finally
{
session.dispose();
}
}
finally
{
image2.close();
}
decompose()
public abstract MaskingResult decompose()
Performs first rough decompose operation
Returns: MaskingResult - Result of masking operation as array of segment image providers.
Example: 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";
// Masking export options
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());
com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();
// Use GraphCut clustering.
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.GraphCut);
maskingOptions.setDecompose(false);
maskingOptions.setArgs(new com.aspose.imaging.masking.options.AutoMaskingArgs());
// The background color will be orange.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getOrange());
maskingOptions.setExportOptions(exportOptions);
// Starting a session for the first time and saving to a file
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);
com.aspose.imaging.masking.IMaskingSession session = masking.createSession(maskingOptions);
try
{
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.decompose();
try
{
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step1.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
session.save(sessionBackupFile);
}
finally
{
session.dispose();
}
}
finally
{
image.close();
}
// Resuming a masking session from a file
com.aspose.imaging.RasterImage image2 = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image2);
com.aspose.imaging.masking.IMaskingSession session = masking.loadSession(sessionBackupFile);
try
{
com.aspose.imaging.masking.options.AutoMaskingArgs args = new com.aspose.imaging.masking.options.AutoMaskingArgs();
// Analyze the image visually and set the points that belong to separated objects.
args.setObjectsPoints(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)
},
});
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.improveDecomposition(args);
try
{
// Explicit transfer of export options, since it is not serializable
maskingResult.MaskingOptions.setExportOptions(exportOptions);
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step2.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
}
finally
{
session.dispose();
}
}
finally
{
image2.close();
}
decomposeAsync()
public abstract IMaskingAsyncTask decomposeAsync()
Creates the asynchronous task which can perform first rough decompose operation
Returns: IMaskingAsyncTask - The asynchronous decompose task
improveDecomposition(IMaskingArgs maskingArguments)
public abstract MaskingResult improveDecomposition(IMaskingArgs maskingArguments)
Performs retraining decompose operation
Parameters:
Parameter | Type | Description |
---|---|---|
maskingArguments | IMaskingArgs | The masking arguments. |
Returns: MaskingResult - Result of masking operation as array of segment image providers.
Example: 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";
// Masking export options
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());
com.aspose.imaging.masking.options.MaskingOptions maskingOptions = new com.aspose.imaging.masking.options.MaskingOptions();
// Use GraphCut clustering.
maskingOptions.setMethod(com.aspose.imaging.masking.options.SegmentationMethod.GraphCut);
maskingOptions.setDecompose(false);
maskingOptions.setArgs(new com.aspose.imaging.masking.options.AutoMaskingArgs());
// The background color will be orange.
maskingOptions.setBackgroundReplacementColor(com.aspose.imaging.Color.getOrange());
maskingOptions.setExportOptions(exportOptions);
// Starting a session for the first time and saving to a file
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image);
com.aspose.imaging.masking.IMaskingSession session = masking.createSession(maskingOptions);
try
{
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.decompose();
try
{
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step1.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
session.save(sessionBackupFile);
}
finally
{
session.dispose();
}
}
finally
{
image.close();
}
// Resuming a masking session from a file
com.aspose.imaging.RasterImage image2 = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.load(dir + "Gorilla.bmp");
try
{
// Create an instance of the ImageMasking class.
com.aspose.imaging.masking.ImageMasking masking = new com.aspose.imaging.masking.ImageMasking(image2);
com.aspose.imaging.masking.IMaskingSession session = masking.loadSession(sessionBackupFile);
try
{
com.aspose.imaging.masking.options.AutoMaskingArgs args = new com.aspose.imaging.masking.options.AutoMaskingArgs();
// Analyze the image visually and set the points that belong to separated objects.
args.setObjectsPoints(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)
},
});
com.aspose.imaging.masking.result.MaskingResult maskingResult = session.improveDecomposition(args);
try
{
// Explicit transfer of export options, since it is not serializable
maskingResult.MaskingOptions.setExportOptions(exportOptions);
com.aspose.imaging.RasterImage segmentImage = maskingResult.get_Item(1).getImage();
try
{
segmentImage.save(dir + "step2.png");
}
finally
{
segmentImage.close();
}
}
finally
{
maskingResult.close();
}
}
finally
{
session.dispose();
}
}
finally
{
image2.close();
}
improveDecompositionAsync(IMaskingArgs maskingArguments)
public abstract IMaskingAsyncTask improveDecompositionAsync(IMaskingArgs maskingArguments)
Creates the asynchronous task which can perform retraining decompose operation
Parameters:
Parameter | Type | Description |
---|---|---|
maskingArguments | IMaskingArgs | The masking arguments. |
Returns: IMaskingAsyncTask - The asynchronous decompose task
save(OutputStream stream)
public abstract void save(OutputStream stream)
Save the session state to the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | The stream. |
save(System.IO.Stream stream)
public abstract void save(System.IO.Stream stream)
Save the session state to the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | com.aspose.ms.System.IO.Stream | The stream. |
save(String filePath)
public abstract void save(String filePath)
Saves the session state to the specified file.
Parameters:
Parameter | Type | Description |
---|---|---|
filePath | java.lang.String | The file path. |