Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Apply Floyd–Steinberg dithering to an image
ResourceFunction["FloydSteinbergDithering"][image] applies Floyd–Steinberg dithering to image. | |
ResourceFunction["FloydSteinbergDithering"][image,col] use col colors per channel. | |
ResourceFunction["FloydSteinbergDithering"][image,col,err] scales the quantization error by err to control overall noise. |
"ColorsPerChannel" | 8 | the default number of colors to use in each channel of the image |
"PreserveSize" | False | whether to preserve the original image dimensions |
Apply dithering to an image:
In[1]:= | ![]() |
Out[1]= | ![]() |
Specify the number of colors per channel:
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
Specify a different number of colors per channel for each channel:
In[4]:= | ![]() |
Out[4]= | ![]() |
See each channel separately:
In[5]:= | ![]() |
Out[5]= | ![]() |
Specify the quantization error parameter to control how "noisy" the image appears:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Apply directly to an array of data:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
By default, the size of the image will be reduced by 1 on each side:
In[11]:= | ![]() |
Out[12]= | ![]() |
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
Set "PreserveSize" to True to ensure the output has the same dimensions:
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
For very small images, using "PreserveSize"→False can yield better image quality:
In[17]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
In[20]:= | ![]() |
Out[20]= | ![]() |
The value of the "ColorsPerChannel" option is equivalent to using the two-argument form:
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
In[23]:= | ![]() |
Out[23]= | ![]() |
If the second argument is provided, the option specification is ignored:
In[24]:= | ![]() |
Out[24]= | ![]() |
Use Rasterize to dither arbitrary expressions:
In[25]:= | ![]() |
Out[25]= | ![]() |
In[26]:= | ![]() |
Out[26]= | ![]() |
When giving a list as the second argument, it must have the same length as the number of image channels:
In[27]:= | ![]() |
Out[27]= | ![]() |
In[28]:= | ![]() |
Out[28]= | ![]() |
The colorspace of an image can significantly affect the output:
In[29]:= | ![]() |
Out[29]= | ![]() |
In[30]:= | ![]() |
Out[30]= | ![]() |
When applying to an array, all values must be numeric:
In[31]:= | ![]() |
Out[31]= | ![]() |
In[32]:= | ![]() |
Out[32]= | ![]() |
Start by applying dithering to the grayscale version of an image:
In[33]:= | ![]() |
Out[34]= | ![]() |
Extract the set of coordinates corresponding to dark pixels with PixelValuePositions and add some slight noise:
In[35]:= | ![]() |
Out[37]= | ![]() |
Use FindShortestTour to generate a single line that visits very point:
In[38]:= | ![]() |
Out[39]= | ![]() |
Use the original image to add some color:
In[40]:= | ![]() |
Out[40]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License