Hi, Support:
I want to know whether the api supports extracting a shape such as portrait or product from its backgroud, and then save it as png file?
Thanks for your help.
The code is based on C+.
However, I failed to convert it into Vb.net ones.
Would you please provide me a vb.net demo?
Thanks.
@ducaisoft
There is no need to make time consuming exercises porting our .NET C# code to VB.NET. You may compile it as .NET C# dll instead, add it as a dependency to your VB.NET application along with Aspose.Imaging .NET and use then.
I try the c demo, but there are two errors,how to fix it?
111.jpg (71.6 KB)
the report of the first error is that AutoMaskingGraphCutOptions class is not found.
the report of the second error is that “cannot apply indexing with [] to an expression of type ‘MaskingResult’”.
My DEV is VS 2017, and the Dll is v20.10 and Net3.5.
How to fix this two errors?
@ducaisoft
We’ve introduced the image masking later. Please use the latest Aspose.Imaging.dll version.
Thanks!
I try the v22.4,but it still throw an exception like this:
222.jpg (81.9 KB)
333.jpg (72.8 KB)
What’s wrong?how to fix it?
DEV are VS2017, VC#, aspose.imaging.dll(v22.4),net3.5.
I try what you suggest, but the problem still there.
44.jpg (75.2 KB)
55.jpg (80.0 KB)
what’s wrong?
======================codes===================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Masking;
using Aspose.Imaging.Masking.Options;
using Aspose.Imaging.Masking.Result;
using Aspose.Imaging.Sources;
namespace YCImgCutOut
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
int i = 0;
i=args.Length;
if (true )
{
string inputFile = args[0];
string outputFile = args[1];
using (RasterImage image = (RasterImage)Aspose.Imaging.Image.Load(inputFile))
{
AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
{
CalculateDefaultStrokes = true,
FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
Method = SegmentationMethod.GraphCut,
Decompose = false,
ExportOptions =
new PngOptions()
{
ColorType = PngColorType.TruecolorWithAlpha,
Source = new FileCreateSource(outputFile)
},
BackgroundReplacementColor = Color.Transparent
};
using (MaskingResult results = new ImageMasking(image).Decompose(options))
using (RasterImage resultImage = (RasterImage)results[0].GetImage())
{
resultImage.Save(outputFile, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
}
}
Application.Exit();
}
}
}
================================================
@ducaisoft You should either
- specify
Source = new FileCreateSource(outputFile)
in ExportOptions and then perform
resultImage.Save()
without specifying image path and newImageOptionsBase
; - specify
Source = new FileCreateSource("some-temp-file-path")
in ExportOptions and then perform
resultImage.Save(outputFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha })
saving the image to a desired destination.
I suggest you to use the second option to avoid using
scope limitations.
You can see more examples here:
Thus works!
Thanks!
However, the output is out of expectation, that’s is to say, the result is useless. Whereas the remove.bg can work very fine. Is there any possible to improve the api function for removing bg?
the input is Tmp.jpg (24.7 KB)
whereas the output is tmp.jpg (25.8 KB).
By compare, the output by remove.bg is as follow: Tmp-removebg-preview.jpg (37.6 KB)
@ducaisoft Yes, you can use following methods from the mentioned article to improve the result.
This one utilizing Imaging.Cloud API:
Or one of this ones with some manual help:
Following your references, I found nothing how to work it out.
Would you please show me a full demo how the API works even better.
@ducaisoft
You may evaluate the feature at Remove background from your image, picture, photo online.
If you find it suitable to your needs - please review previous reply to see how it works.
I evaluate it at Remove background from your image, picture, photo online,
It looks ok, but it takes a long time (serval minutes) to process an image which is not tolerable, whereas the API cloud at removebg.com that is similar as yours only takes about 10 second to finish the processing. Is there any method to speed up the process? Or the api makes no use for it consume too long time!
Would you please provide me a full and fine demo to work it out? by C#?
The follow is the code I test:
It takes a long time to finish the process.
And the Output like this is totally out of expectation!
How to speed it up and improve the output?
@ducaisoft
Thank you for coming back.
Regarding the performance, comparing to other products - unlike them we do not strictly depend on AI/ML and our approach is more universal but slower.
Regarding the quality - we’ve reviewed your code sinppet and found one principle difference with out approach at Remove background application - we are using pre-identification of objects to improve the qualty, see above mentioned code snippet Remove background from images|Documentation (aspose.com).