ImageVectorizerConfiguration

I’m trying out the new ImageVectorizer and no matter how I change the ImageVectorizerConfiguration I still get the same result. The config seems to do nothing.

image.png (7.7 KB)

I’m using Aspose.SVG 21.10.0

void Main()
{
	var vectorizer = new ImageVectorizer(new ImageVectorizerConfiguration()
	{
		ColorsLimit = 24,
		PathBuilder = new PathBuilder() {
			Tension = 0.5f
		},
		TraceSimplifier = new ImageTraceSimplifier(1f),
		TraceSmoother = new ImageTraceSmoother(100)
	});
	
	using(var document = vectorizer.Vectorize(@"C:\Users\niels\Desktop\Vectorization\baby-panda-zwaaien-poot-cartoon_42750-612.png"))
	{
		var outputPath = @"C:\Users\niels\Desktop\vectortest.png";

		var device = new ImageDevice(new ImageRenderingOptions(ImageFormat.Png)
		{
			SmoothingMode = SmoothingMode.HighQuality,
			PageSetup = {
				Sizing = SizingType.FitContent
			}
		}, outputPath);

		document.RenderTo(device);
		
		foreach (var file in Directory.GetFiles(Path.GetDirectoryName(outputPath),
				Path.GetFileNameWithoutExtension(outputPath) + "*"))
		{
			Util.Image(file).Dump();
		}
	}
}

@nielsbosma

Have you shared the same image that you are trying to vectorize? OR is it the obtained output result? Please clarify so that we can further proceed to assist you.

baby-panda-zwaaien-poot-cartoon_42750-612.png (16.6 KB)

^ this is the image I was trying to vectorized.

The previous image was a screenshot of the result.

It seems that when I close my Linqpad script and re opens, then it works. Something is cached in a weird way?

@nielsbosma

We need to further investigate reasons behind such behavior of the API. Therefore, an investigation ticket as SVGNET-43 has been logged in our issue management system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@nielsbosma

In order to get a good vectorization result for this image, you need to decrease the number of used colors with the option ColorsLimit (=2), because if you upper-scale this image you will see that the image contains several additional colors (take a look on scale.png) affected the result SVG and we need to exclude them.

Options will look like this:

 var vectorizer = new ImageVectorizer(new ImageVectorizerConfiguration()
            {
                ColorsLimit = 2,
                PathBuilder = new PathBuilder()
                {
                    Tension = 0.3f
                },
                TraceSimplifier = new ImageTraceSimplifier(0.3f),
                TraceSmoother = new ImageTraceSmoother(3)
            });

            using (var document = vectorizer.Vectorize(@"baby-panda-zwaaien-poot-cartoon_42750-612.png"))
                document.Save(@"result.svg");

files.zip (18.2 KB)

Detailed information about using vectorization parameter was added to the documentation page

Also, common information about the image vectorization process was added here: