Floyd-Steinberg Dithering

Trying to implement this in python grasshopper but it doesn’t seem to look like the examples in the web
My guess its the way python modify the list during the for loop doesnt allow it to accumulate the error correctly any help ?

https://en.wikipedia.org/wiki/Floyd–Steinberg_dithering<a class=“attachment”

href=“https://aws1.discourse-cdn.com/mcneel/uploads/default/original/3X/9/b/9b1a1e0d2def5ed11607cd3e8dc493847acef0cd.gh”>Floyd Stienberg.gh (686.5 KB)

image

No gh file

Seems to be a broken link. This works:
https://aws1.discourse-cdn.com/mcneel/uploads/default/original/3X/9/b/9b1a1e0d2def5ed11607cd3e8dc493847acef0cd.gh

Havent looked yet - I wonder whether its a list mutability problem …?

A few weeks ago, Daniel Shiffman published a Coding Challenge video, about Floyd-Steinberg dithering, on his YouTube channel. He explains rather well and in detail how the algorithm works and implements it in Processing (Java-based programming language).

I find his videos rather easy to follow. You could try to port his approach to GH or rhinopython. I did this with a number of Coding Challenges myself! Usually the most difficult part, besides the main algorithm, is coming up with the “animation” part, which is pretty straight forward in Processing.

1 Like

So this isn’t really helpful, sorry in advance, but I’ve coded up some dithering algorithms for GH2 image processing. Here’s a few of the test results:

Nearest with 6 colours:

Atkinson with 6 colours. If I recall correctly Atkinson error diffusion doesn’t diffuse 100% of the error, resulting in an image with more residual error but fewer dithered regions:

Floyd-Steinberg with 6 colours:

Stucki with 6 colours:

Jarvis with 6 colours:

6 Likes

Here is the GH file with what I did so far
Thanks everyone will update If I get any further.

Floyd Stienberg.gh (686.5 KB)

Hi @youssef.eskandar, @DavidRutten, @Dancergraham, @laurent_delrieu and everybody else interested,

Today, I had some time to attempt my own Floyd-Steinberg dithering algorithm in GHPython.
It opens an image from a provided path, performs the dithering and outputs points and colors for visualisation purposes. It’s by no means perfect, but it works! :yum:

dithering_rhino

And this one is for you, @youssef.eskandar! :wink:

dithering_shiffman

Everybody, please feel free to test it yourself!

floyd_steinberg_dithering_v1.gh (10.9 KB)

6 Likes

Fun! Here’s a real time ordered dither implementation in GLSL.
ordered_dither.gh (523.0 KB)

4 Likes

Very cool to discover Shaders in Grasshopper. I am far from understanding them, but seems cool. @p1r4t3b0y I use Steve shader to display points


2 Likes

Very cool! :raised_hands:

Thanks, for mentioning the shader display option. It’s rad!