public interface IMaskingSession
extends com.aspose.ms.System.IDisposable
The masking session
IDisposable
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(); }
Modifier and Type | Method and Description |
---|---|
MaskingResult |
decompose()
Performs first rough decompose operation
|
IAsyncTask |
decomposeAsync()
Creates the asynchronous task which can perform first rough decompose operation
|
MaskingResult |
improveDecomposition(IMaskingArgs maskingArguments)
Performs retraining decompose operation
|
IAsyncTask |
improveDecompositionAsync(IMaskingArgs maskingArguments)
Creates the asynchronous task which can perform retraining decompose operation
|
void |
save(OutputStream stream)
Save the session state to the specified stream.
|
void |
save(com.aspose.ms.System.IO.Stream stream)
Save the session state to the specified stream.
|
void |
save(String filePath)
Saves the session state to the specified file.
|
MaskingResult decompose()
Performs first rough decompose operation
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(); }
IAsyncTask decomposeAsync()
Creates the asynchronous task which can perform first rough decompose operation
MaskingResult improveDecomposition(IMaskingArgs maskingArguments)
Performs retraining decompose operation
maskingArguments
- The masking arguments.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(); }
IAsyncTask improveDecompositionAsync(IMaskingArgs maskingArguments)
Creates the asynchronous task which can perform retraining decompose operation
maskingArguments
- The masking arguments.void save(OutputStream stream)
Save the session state to the specified stream.
stream
- The stream.void save(com.aspose.ms.System.IO.Stream stream)
Save the session state to the specified stream.
stream
- The stream.void save(String filePath)
Saves the session state to the specified file.
filePath
- The file path.