-
-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected artefacts when quantizing images #2469
Comments
What happens when you quantize without dithering? Why are you quantizing then resaving at 32bit? |
Hi there, I created the the demo program with the absolute minimum code to illustrate the problem that I came across while working with the library and thought it best to raise it. As to saving as 32 bit, it was not a conscious decision. I am happy to try with out dithering with you could point me in the right direction how I can do that. Thanks for your time with this |
Instead of using It's likely the dither as the pattern stems down and left from the widening as it does which is the direction error diffusion goes. You can set the strength of the dither (0-1) in those same options. |
Hi there I have made the change as suggested.
The artifact has now disappeared and the image is as expect. I have tested all the Dithering types and the following types create the artifacts. Burks The rest are fine and don't product any issues that I can see. Purely for my education and better understanding, why do you think the dithering would cause this issue? Thanks again for you time and help. Regards |
The dithering algorithms work by pushing error (this difference between a quantized pixel and the original) to its surrounding pixels. For example, Floyd Steinburg propagates the error to the neighboring pixels as follows:
We use a lookup table that stores up to 5 bits of pixel data per component to match the result of a quantized pixel against it's undithered equivalent. We use 5 bits as that keeps memory low (6 bits would be preferred but that uses over 30 MB compared to 2 1/4 MB). Sometimes we end up with a collision which leads to the artifacts you are seeing. This, in the case of your image pushes the artifact caused by that shadow down and to the right. This is why I suggested adjusting the strength of the dithering. Using .5F as a parameter for example would reduce the error by half. Here's the output from doing that. |
I've actually opened up #2473 which allocates more memory towards alpha component comparisons in our lookup table which fixes the issue using the default encoder settings. |
Prerequisites
DEBUG
andRELEASE
modeImageSharp version
3.0.1
Other ImageSharp packages and versions
NA
Environment (Operating system, version and so on)
Windows, Linux
.NET Framework version
6
Description
We are currently experiencing strange artifacts when quantizing images.
Steps to Reproduce
Load image.
Quantize the image using KnownQuantizers.Wu
The saved output will have unexpected artifacts.
Below is a test program I created to replicate the problem. It does not happen on all images only on some. I have attached a image that it happens on. If you compare the original to the quantized version you will note a grey triangular artifact from right of centre to the right middle of the image.
Original Image
Quantized Image
Images
The text was updated successfully, but these errors were encountered: