Saturday, October 26, 2013

dithering

I was converting a PNG (which represented partials sums of the Weierstrass elliptic function) to a GIF and was confused about why the PNG looked fine at low resolution but the GIF looked bad.

Then I learned that GIFs can only use 256 colors and we have to do something to map the many colors to the fewer colors. We could just use the closest available color in the new set of colors, but that results in sharp jumps and "color banding" where the colors change.
So instead we use (and ImageMagick's default is) dithering, which assigns pixels to a mixture of color values that locally average to the appropriate shade. I had a great time reading about this in ImageMagick's documentation! Here's a description of the default method:
The pixel is assigned the color closest to that pixels value, and any difference between the pixels original color and the selected color, is saved and added to the next pixels color values (which is always a neighbouring pixel) before a new color is again selected. In this way any color variations between selected colors and the images original color is distributed to the other pixels in the same area. The result is that while only specific colors will be assigned to the final image, the same basic overall color for that area will closely match the original image.
When there aren't enough dots, the picture looks blurry.
Resolution: 800x600 Resolution: 200x150
PNG (lots of colors)
no dither (GIF, 256 colors)
default dither (GIF, 256 colors)
Here's my code on Github, and here are the ImageMagick commands that produced these:
convert -resize 100% -dither None ./zoomed_in/Weierstrass001.png ./res100no_dither.gif
convert -resize 50% -dither None ./zoomed_in/Weierstrass001.png ./res50no_dither.gif
convert -resize 100%  ./zoomed_in/Weierstrass001.png ./res100default_dither.gif
convert -resize 25%  ./zoomed_in/Weierstrass001.png ./res25default_dither.gif
convert -resize 100%  ./zoomed_in/Weierstrass001.png ./res100many_colors.png
convert -resize 25%  ./zoomed_in/Weierstrass001.png ./res25many_colors.png

13 comments:

  1. Thank you for this conversion from PNG to GIF. Here the code for this conversion also included hence is useful to others who want this. If you want essay related topic you can go for custom essay writing service will get better result.

    ReplyDelete
    Replies
    1. Techniques such as dithering, color quantization, and visual enhancement are fundamental topics in Image Processing Projects For Final Year. Understanding these concepts helps students develop solutions for image enhancement, restoration, compression, and other computer vision applications where image quality plays a crucial role.

      Delete
    2. The article also highlights how image manipulation algorithms can significantly influence visual perception and rendering quality. Exploring Image Denoising Projects can provide further insight into advanced techniques for improving image clarity and reducing unwanted visual artifacts in digital imaging systems.

      Delete
  2. Avail the best Online Architecture Assignment Help in UK with the help of profound writers.Best service Guaranteed.

    ReplyDelete
  3. Students face difficulties when it comes to writing an assignment and start searching for Cross Cultural management assignment help. Now, it’s time to forget about the assignment woes as EssayCorp is here with the best Cross Cultural Management Assignment help.

    ReplyDelete
  4. Completing nursing assignments requires deep subject knowledge, clinical understanding, and academic precision — and that is exactly what you get here. Whether it is care plans, case studies, or reflective practice, our nursing assignment writers bring real expertise to every task. Each writer holds advanced qualifications in healthcare and understands UK academic standards inside out. From tight deadlines to complex medical terminology, they handle it all with professionalism and accuracy. Plus, with plagiarism-free content and personalized support, your grades are in safe hands. Stop stressing and start succeeding with expert help designed specifically for nursing students like you!

    ReplyDelete
  5. Finding reliable cybersecurity assignment help can be tough when balancing difficult lab work and complex theory. This platform connects you with experienced professionals who understand advanced cryptography, network protocols, and ethical hacking techniques. They provide tailored guidance to help you master challenging topics and deliver high-quality coursework on time. Whether you are stuck on a specific coding bug or need help structuring a deep-dive research paper, the expert assistance here clarifies concepts and improves your overall performance. Take the stress out of your technical studies and build a stronger foundation for your future IT career today.

    ReplyDelete