Imagesharp: Default PNG quantizer introduces jaggedness

Created on 29 Mar 2019  路  4Comments  路  Source: SixLabors/ImageSharp

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am running the latest version of ImageSharp
  • [x] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description

When saving png using default settings visible jaggedness is introduced.

Steps to Reproduce

sample

void Main()
{
    using (var image = Image.Load(File.ReadAllBytes("sample.png")))
    using(var stream = File.Open("output.png", FileMode.Create))
        image.SaveAsPng(stream);
}

output

System Configuration

Windows 10 and in Azure

  • ImageSharp version: 1.0.0-dev002459
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on):
  • .NET Framework version: .NET Core 2.2 & .NET Core 3.0 (preview)
  • Additional information:
quantizers bug png

All 4 comments

This appears to be happening due to the fact that the number of colors in the pallette are being reduced from 83 to 2:

I:\issues\imagesharp\866>identify *.png
55246806-4cbaa700-5246-11e9-9f0f-4e21acab9a97.png PNG 1003x376 1003x376+0+0 8-bit sRGB 83c 7844B 0.000u 0:00.001
55246926-9e633180-5246-11e9-9e53-56faea37decb.png PNG 1003x376 1003x376+0+0 8-bit sRGB 2c 5047B 0.000u 0:00.000

@dlemstra Had a very quick look at the quantizer. Algorithmically it seems ok just a shade aggressive. It would be really useful if someone could compare the color count to the implementation we based ours on here to ensure we haven't made any mistakes.

https://github.com/JeremyAnsel/JeremyAnsel.ColorQuant/blob/master/JeremyAnsel.ColorQuant/JeremyAnsel.ColorQuant/WuAlphaColorQuantizer.cs

Figured it out. We're not using enough accuracy when calculating variance. Will have 69 colors once I submit a fix.

jagged.png PNG 1003x376 1003x376+0+0 8-bit sRGB 69c 9487B 0.000u 0:00.000

jagged

We can actually get by with slightly less accuracy (by using far less memory) and produce a good image at 48 colors.

jagged

Was this page helpful?
0 / 5 - 0 ratings