Essential insights from Hacker News discussions

Show HN: High End Color Quantizer

Relevance and Use Cases of Color Quantization

Several commenters discuss the applications of color quantization, particularly in the context of modern computing and compression. While some see it as an outdated technique, others highlight its continued relevance.

  • GIF Support: "I'm always interested in ways to increase the quality of GIF rendering. There are absolutely tons of places that still need GIF support, either because they don't allow video uploads, or because the videos don't auto-play." - qingcharles. This emphasizes the persistent need for GIF optimization due to platform limitations.
  • Low Resource Environments: "Colour quantisation is still one of the best lossy image compression formats for when you have almost no memory or CPU." - Lerc. This highlights its usefulness in embedded systems or scenarios with limited resources.
  • Lossy Compression: "Lossy compression uses color quantization all the time, doesn't it?" - vanderZwan. This directly links color quantization to broader lossy compression techniques, suggesting it's not entirely obsolete.
  • Silent Autoplaying Video: "working with GIF is valid but it is incredibly sad how it's still the only widely supported silent autoplaying video..." - porphyra. This points to the unfortunate reliance on GIFs due to the lack of universal support for alternative animated image formats.

Comparison and Evaluation of Quantization Algorithms

A significant portion of the discussion revolves around comparing the implemented Wu v2 algorithm to other quantization methods, including user requests for comparisons and concrete examples.

  • Comparison to png-quant: "Gifski uses the png-quant library, and I wonder how this compares?" - qingcharles. This highlights the need to understand the relative performance of different quantization libraries.
  • Need for Full Examples: "I'd say that showing full example results are the most important part of showcasing a 'high end' color quantizer." - dinfinity. This emphasizes the importance of demonstrating the algorithm's impact on entire images, not just salient regions.
  • Request for Specific Image Quantization: "take a look at my demo [1]. i'd love to see the same set of images quantized with your thing." - leeoniya. This promotes a direct comparison using existing benchmark images.
  • Reason for Implementing Wu v2: "Something that caught my eye is that it seemed to be a kind of "controlled" K-Means...Another thing was that the guy that wrote the paper also authored an insanely high quality method the year before and claimed this one was better. Not seeing any available implementations I wondered how good it actually was." - big-nacho

Addressing Limitations and Improving Palette Selection

Several comments focus on the shortcomings of typical palette generation and propose solutions to address them, particularly concerning color intensity and the absence of deep highlights/shadows.

  • Palette's Lack of Intense Colors: "Something that always bugged me about palette generators I've used is how they end up not picking any colors intense enough for the deepest highlights/shadows, because they use colors close to the average of various sets of pixels." - sebastianmestre. This identifies a common problem with palette generation leading to washed-out images.
  • Hacking Palette Generation with White/Black Bars: "My hack to address this has always been making a larger image with big white/black bars around the original image to push the palette generator to include a few really bright or dark colors." - sebastianmestre. This describes a workaround to force palette generators to include brighter and darker colors.

Gamma Correction and Color Space Considerations

The discussion touches on the importance of gamma correction and the need to perform operations in the correct color space.

  • Gamma Incorrectness: "This doesn't seem to be gamma correct, I just see / 255 and * 255...sRGB is a nonlinear colour space and so you can't do linear operations in that space (because a^2 + b^2 isn't (a+b)^2 in general)." - pixelpoet. This points out a potential issue with linear operations in a non-linear color space.
  • Gamma Awareness in C Code: "Gamma aware operations happen in the C code. The python code you're referencing is just changing the scale of color intensities. What you shouldn't do is liberally add up sRGB colors, take averages and generally do any math on them unless you're aware of the non-linearity of the space." - big-nacho. Clarifies that handling for nonlinear sRGB space is performed in the implementation, and that the pointed-out issue is simply scaling of color intensities.

Feature Requests and Suggestions for Improvement

Several commentators suggest additional features and improvements, including integration with other libraries, broader color space support, dithering methods, and ease of installation.

  • Integration with PyTorch: "Would not it be much easier and more productive to integrate with pytorch? Some of the functionality which you have there is already provided by kornia, torch_kmeans. You'll end up with much less code to worry about." - pk-protect-ai. Suggests leveraging existing PyTorch functionality.
  • Wider Color Space and Dither Support: "Does it also support colour spaces other than RGB, CIEDE (I think I saw that in the source), i.e CMYK for paint mixing, and similar ilk?...I have a few personal projects that would benefit from a library that is wide ranging in the colour space, dither algorithms (I only saw riezsma) and quantizations...Typically these are all usually implemented in different libraries :(" - SillyUsername. Highlights the need for broader support for color spaces and dithering algorithms.
  • Ease of Installation and Comparison with Incumbents: "Make it installable via uv tool install patolette with the optimisations taken care of automatically... Compare its results in the documentation/on the project Web site against the incumbents." - bmn__. Suggests easier installation and benchmarking against existing solutions for increased adoption.
  • Application to CUPS Printing System: "Please consider adding this and possibly other algorithms to CUPS printing system. Easiest is to add it into ghostscript." - ValdikSS

Algorithm Choice and Riemersma Dithering

  • Reasoning for Picking Riemersma Dithering: "Question out of curiousity: what made you pick Riemersma dithering?" - vanderZwan