{"id":840,"date":"2026-02-10T11:34:35","date_gmt":"2026-02-10T02:34:35","guid":{"rendered":"https:\/\/barbegenerativediary.com\/en\/?p=840"},"modified":"2026-02-10T11:42:36","modified_gmt":"2026-02-10T02:42:36","slug":"ordered-dithering-bayer-in-processing","status":"publish","type":"post","link":"https:\/\/barbegenerativediary.com\/en\/tutorials\/ordered-dithering-bayer-in-processing\/","title":{"rendered":"Ordered Dithering (Bayer) in Processing : From Basics to Levels"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This article focuses on one of the most fundamental dithering methods: <strong>Ordered Dithering<\/strong>. It provides working Processing code, explains the meaning of the Bayer matrix (the \u201corder of becoming white\u201d), and organizes how to handle the characteristic \u201cpattern look\u201d that ordered dithering produces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The complete sample code for this article is available for download on Patreon.<\/strong><br>\u2615 <strong>Support my Work:) \/ <a href=\"https:\/\/www.patreon.com\/barbe_generative_diary\/membership\" target=\"_blank\" rel=\"noopener\" title=\"\">Coffee Supplier on Patreon<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is Dithering?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dithering is a technique that uses human visual perception to represent intermediate tones even when the output device can display only a limited number of colors (or tonal levels).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, in a situation where only two values (black and white) are possible, if the image is converted with a simple threshold like \u201cbrightness &gt; 128 \u2192 white,\u201d smooth gradients become broken into step-like segments and lose their softness. This is called <strong>posterization<\/strong> or <strong>banding<\/strong>, and it becomes especially visible in areas such as skies or shadows where brightness changes slowly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In contrast, if black and white pixels are intentionally distributed, they may appear as \u201cgrain\u201d or \u201cpatterns\u201d up close, but from a slightly farther distance they visually average out and are perceived as intermediate brightness. In other words, even though no true mid-tone exists on the screen, the visual system completes the missing tone by spatial averaging. Dithering is the technique of designing this perceptual \u201cillusion.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This idea is closely related to <strong>halftoning<\/strong> used in newspapers and magazines. In print, continuous ink density is difficult to control, so tonal values are represented by dot density and dot arrangement. Dithering can be seen as transferring this halftone concept into digital images and implementing it as a pixel-level algorithm.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is also important that dithering is not merely an \u201cold low-resolution effect.\u201d Even today, dithering is used for purposes such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Low bit-depth displays (e-ink, embedded displays, LEDs, etc.)<\/li>\n\n\n\n<li>Compression or simplification (artistic black-and-white \/ limited-color looks)<\/li>\n\n\n\n<li>Avoiding banding (converting smooth gradients into controlled grain)<\/li>\n\n\n\n<li>Texture design in generative expression (patterns, noise, retro aesthetics)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, dithering is not only a way to overcome technical constraints, but also a method for designing the appearance of images themselves.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article starts with one of the most basic and easy-to-implement forms: <strong>Ordered Dithering<\/strong>, and explains it through working Processing code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. What is Ordered Dithering?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are several families of dithering, but <strong>Ordered Dithering<\/strong> has the following characteristics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Quantizes pixels into black\/white (or a small number of tones)<\/li>\n\n\n\n<li>Uses thresholds that vary by pixel position instead of being constant<\/li>\n\n\n\n<li>Produces tonal representation through a regular pattern<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In normal binary thresholding, the same threshold is applied everywhere (for example, \u201cbrightness &gt; 128 \u2192 white\u201d). In ordered dithering, the threshold changes depending on pixel position.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, the idea is:<br><strong>\u201cDecide in advance how easily each position becomes white.\u201d<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, when image brightness increases slightly, white pixels do not increase as a solid block. Instead, they increase while being spatially scattered. This is why ordered dithering can visually produce gradients even in black and white.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ordered dithering is computationally light and simple to implement, which makes it suitable for real-time use. Compared to error diffusion methods (such as Floyd\u2013Steinberg), it tends to produce more stable grain, making it easier to use for animation and video.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. What is a Bayer Matrix? (4\u00d74 Example)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A well-known representative of ordered dithering is <strong>Bayer dithering<\/strong>. Bayer dithering uses a repeating <strong>threshold matrix (threshold map)<\/strong> tiled across the image:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int&#91;]&#91;] bayer4 = {\n  { 0, 8, 2, 10},\n  {12, 4, 14, 6},\n  { 3, 11, 1, 9},\n  {15, 7, 13, 5}\n};\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The important point is that these numbers are not random. They represent the <strong>order in which pixels turn white<\/strong>. As the brightness of the image increases from 0 to 255, inside each 4\u00d74 tile, the positions with smaller numbers turn white earlier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By distributing this \u201cturning white order\u201d spatially, the algorithm prevents white pixels from clustering locally, making tones appear smoother. Because the pattern is regular, the perceived brightness tends to remain stable as an area.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Implementation in Processing (Bayer 4\u00d74)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"576\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4.webp\" alt=\"\" class=\"wp-image-848 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-300x169.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-768x432.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/576;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In Processing, implementing Bayer dithering generally follows these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Get brightness from the source image<\/li>\n\n\n\n<li>Retrieve the Bayer matrix value for that pixel position<\/li>\n\n\n\n<li>Use it as a threshold and convert to black\/white<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Below is the minimal working example:<\/p>\n\n\n\n<pre><code class=\"language-processing\">\nvoid applyBayerDithering4(PGraphics source) {\n  loadPixels();\n  source.loadPixels();\n\n  int[][] bayer4 = {\n    { 0, 8, 2, 10},\n    {12, 4, 14, 6},\n    { 3, 11, 1, 9},\n    {15, 7, 13, 5}\n  };\n\n  for (int y = 0; y < height; y++) {\n    for (int x = 0; x < width; x++) {\n      int loc = x + y * width;\n\n      float b = brightness(source.pixels[loc]); \/\/ 0..255\n\n      float t = bayer4[x % 4][y % 4];           \/\/ 0..15\n      float threshold = (t \/ 15.0) * 255.0;\n\n      pixels[loc] = (b > threshold) ? color(255) : color(0);\n    }\n  }\n\n  updatePixels();\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In Processing, <strong>pixels[]<\/strong> is a <strong>1D array<\/strong>, so the 2D coordinates <strong>(x, y) <\/strong>must be converted into an index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int loc = x + y * width;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This loc represents \u201cwhich element in pixels[] corresponds to this pixel.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following line tiles the Bayer matrix across the whole image:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float t = bayer4&#91;x % 4]&#91;y % 4];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>x % 4<\/strong> and <strong>y % 4<\/strong> fold the coordinates into the range 0..3. As a result, the 4\u00d74 Bayer matrix repeats in a tiled pattern across the screen, assigning a different threshold to each position.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next line matches the scale:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float threshold = (t \/ 15.0) * 255.0;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Bayer values <code>t<\/code> are 0..15<\/li>\n\n\n\n<li>brightness() values <code>b<\/code> are 0..255<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Without scaling, the comparison would not work properly. So:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>t \/ 15.0 normalizes 0..15 into 0..1<\/li>\n\n\n\n<li>multiplying by 255.0 converts it back to 0..255<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now threshold and b can be compared consistently, producing the ordered dithering effect:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>threshold varies by position<\/li>\n\n\n\n<li>white pixels increase in a regular scattered pattern<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5-1. Extending to 8\u00d78 \/ 16\u00d716<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bayer dithering can be extended beyond 4\u00d74 to 8\u00d78 and 16\u00d716. As the matrix size increases, the black\/white distribution becomes finer even in areas of constant brightness, and gradients appear smoother.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"576\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering8.webp\" alt=\"\" class=\"wp-image-849 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering8.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering8-300x169.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering8-768x432.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/576;\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>4\u00d74<\/strong>: the pattern is obvious (strong retro look)<\/li>\n\n\n\n<li><strong>8\u00d78<\/strong>: the pattern becomes finer and tonal steps increase<\/li>\n\n\n\n<li><strong>16\u00d716<\/strong>: even smoother, but may look blurry depending on the image<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A Bayer 8\u00d78 matrix (0..63) looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int&#91;]&#91;] bayer8 = {\n  { 0, 48, 12, 60,  3, 51, 15, 63},\n  {32, 16, 44, 28, 35, 19, 47, 31},\n  { 8, 56,  4, 52, 11, 59,  7, 55},\n  {40, 24, 36, 20, 43, 27, 39, 23},\n  { 2, 50, 14, 62,  1, 49, 13, 61},\n  {34, 18, 46, 30, 33, 17, 45, 29},\n  {10, 58,  6, 54,  9, 57,  5, 53},\n  {42, 26, 38, 22, 41, 25, 37, 21}\n};\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To handle such sizes, it is often more convenient in Processing to generate Bayer matrices automatically and switch sizes as needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below is an implementation example that handles 4\/8\/16 uniformly:<\/p>\n\n\n\n<pre><code class=\"language-processing\">\nvoid applyBayerDithering(PGraphics source, int matrixSize) {\n  if (!isPowerOfTwo(matrixSize) || matrixSize < 2) return;\n\n  int[][] bayer = makeBayerMatrix(matrixSize);\n  float maxV = matrixSize * matrixSize - 1;\n\n  loadPixels();\n  source.loadPixels();\n\n  for (int y = 0; y < height; y++) {\n    for (int x = 0; x < width; x++) {\n      int loc = x + y * width;\n\n      float b = brightness(source.pixels[loc]);\n      float t = bayer[x % matrixSize][y % matrixSize];\n      float threshold = (t \/ maxV) * 255.0;\n\n      pixels[loc] = (b > threshold) ? color(255) : color(0);\n    }\n  }\n  updatePixels();\n}\n\nint[][] makeBayerMatrix(int n) {\n  if (n == 2) {\n    return new int[][] {\n      {0, 2},\n      {3, 1}\n    };\n  }\n\n  int half = n \/ 2;\n  int[][] prev = makeBayerMatrix(half);\n  int[][] m = new int[n][n];\n\n  for (int y = 0; y < half; y++) {\n    for (int x = 0; x < half; x++) {\n      int v = prev[x][y];\n\n      m[x][y]               = 4 * v + 0;\n      m[x + half][y]        = 4 * v + 2;\n      m[x][y + half]        = 4 * v + 3;\n      m[x + half][y + half] = 4 * v + 1;\n    }\n  }\n  return m;\n}\n\nboolean isPowerOfTwo(int n) {\n  return (n &#038; (n - 1)) == 0;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5-2. Extending to <code>levels<\/code> (Number of Tones)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So far, the output has been fixed to binary black or white.<br>However, dithering can also be used not only for 2 values, but also for a small number of tones (4 tones, 8 tones, 16 tones, etc.).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"576\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-4.webp\" alt=\"\" class=\"wp-image-850 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-4.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-4-300x169.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-4-768x432.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/576;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here, levels means the <strong>number of quantization steps (the number of output brightness values)<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>levels = 2 \u2192 binary (0 \/ 255)<\/li>\n\n\n\n<li>levels = 4 \u2192 4 tones (0 \/ 85 \/ 170 \/ 255)<\/li>\n\n\n\n<li>levels = 8 \u2192 8 tones<\/li>\n\n\n\n<li>levels = 16 \u2192 16 tones<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The role of dithering is not \u201cincreasing the number of tones.\u201d<br>It is distributing banding artifacts (step-like edges) into spatial grain when reducing tones.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"576\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-8.webp\" alt=\"\" class=\"wp-image-851 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-8.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-8-300x169.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2026\/02\/Ordered-Dithering4-8-768x432.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/576;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The essence of ordered dithering is \u201cshifting the quantization boundaries by position.\u201d<br>In the binary case, the algorithm changes the threshold that decides \u201cwhite or black.\u201d<br>When increasing <code>levels<\/code>, it changes the boundaries that decide \u201cwhich quantization step to round to.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This can be generalized as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>input brightness is continuous: 0..255<\/li>\n\n\n\n<li>output is discrete: levels steps<\/li>\n\n\n\n<li>the Bayer matrix contains the \u201cpriority order\u201d of becoming brighter<\/li>\n\n\n\n<li>use that order to slightly shift the quantization boundaries<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation in Processing (levels-enabled)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Below is an implementation that allows both Bayer matrix size (4\/8\/16\u2026) and the number of tonal levels levels.<\/p>\n\n\n\n<pre><code class=\"language-processing\">\nvoid applyBayerDitheringLevels(PGraphics source, int matrixSize, int levels) {\n  if (!isPowerOfTwo(matrixSize) || matrixSize < 2) return;\n  if (levels < 2) return;\n\n  int[][] bayer = makeBayerMatrix(matrixSize);\n\n  \/\/ Bayer values are 0..(N^2-1), but for normalization we use N^2\n  float maxV = matrixSize * matrixSize;\n\n  loadPixels();\n  source.loadPixels();\n\n  for (int y = 0; y < height; y++) {\n    for (int x = 0; x < width; x++) {\n      int loc = x + y * width;\n\n      float b = brightness(source.pixels[loc]); \/\/ 0..255\n\n      \/\/ Normalize Bayer value to 0..1\n      float t = bayer[x % matrixSize][y % matrixSize];\n      float d = (t + 0.5) \/ maxV;  \/\/ 0..1 (centered)\n\n      \/\/ Normalize brightness to 0..1\n      float bn = b \/ 255.0;\n\n      \/\/ Quantize to levels (shift boundary by d)\n      float q = floor(bn * (levels - 1) + d);\n      q = constrain(q, 0, levels - 1);\n\n      \/\/ Convert quantized value back to 0..255\n      float out = (q \/ (levels - 1)) * 255.0;\n\n      pixels[loc] = color(out);\n    }\n  }\n\n  updatePixels();\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This process can be broken into three steps:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Normalize Bayer values to 0..1<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A Bayer matrix contains integers in the range 0..(N^2-1).<br>We normalize them into 0..1 and use them as a small positional offset.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float d = (t + 0.5) \/ maxV;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The +0.5 shifts each cell value toward the center of its interval.<br>This reduces bias and often makes the dithering pattern more uniform.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Quantize brightness to <code>levels<\/code>, but shift boundaries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Normal quantization would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>q = floor(bn * (levels - 1));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But this uses fixed boundaries and tends to produce banding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ordered dithering shifts the boundary by the Bayer offset d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>q = floor(bn * (levels - 1) + d);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates the effect that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>some positions become brighter slightly earlier<\/li>\n\n\n\n<li>other positions become brighter slightly later<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, the boundary is spatially scattered and the banding becomes grain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Convert quantized values back to 0..255<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The quantized index q is in 0..(levels-1), so it must be mapped back:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float out = (q \/ (levels - 1)) * 255.0;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Usage examples<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can independently control matrix size and tonal levels:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>applyBayerDitheringLevels(pg, 4, 2);   \/\/ 4x4 + binary\napplyBayerDitheringLevels(pg, 4, 4);   \/\/ 4x4 + 4 levels\napplyBayerDitheringLevels(pg, 8, 8);   \/\/ 8x8 + 8 levels\napplyBayerDitheringLevels(pg, 16, 16); \/\/ 16x16 + 16 levels<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Difference between matrixSize and levels<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A common confusion is that matrixSize and levels control different things.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>matrixSize: controls the fineness of the pattern<br>\u2192 larger makes the pattern finer<\/li>\n\n\n\n<li>levels: controls the number of output tones<br>\u2192 larger makes the tones smoother<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So if the goal is to increase smoothness of tone, increasing levels is usually more noticeable than increasing matrixSize.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Meaning of the Bayer Matrix: \u201cThe Order of Becoming White\u201d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Bayer matrix is often explained as a \u201cthreshold map,\u201d but it is easier to understand as a <strong>priority map<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>smaller values turn white earlier<\/li>\n\n\n\n<li>larger values remain black until later<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This causes white pixels to increase while being spatially distributed as brightness increases. As a result, even in binary black and white, intermediate tones appear to exist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. How to Handle the \u201cPattern Look\u201d of Ordered Dithering<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The biggest characteristic of ordered dithering is that it always produces a <strong>regular pattern<\/strong> in exchange for tonal representation. Depending on the situation, this pattern can be either a weakness or a strength.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7-1. Weakness: when the pattern becomes distracting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Regular patterns are more visible in areas such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>large flat regions<\/li>\n\n\n\n<li>slow gradients<\/li>\n\n\n\n<li>around thin lines and text<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In these cases the image may look \u201cprocessed\u201d rather than natural.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7-2. Strength: stable in motion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Error diffusion dithering (such as Floyd\u2013Steinberg) can cause grain to shift from frame to frame in animation, often producing a crawling effect moving toward the lower-right direction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ordered dithering, on the other hand, has a fixed pattern, so it tends to be visually stable for video and animation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7-3. Using it as an aesthetic element<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of hiding the pattern, ordered dithering can be used intentionally as a design element:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>retro texture<\/li>\n\n\n\n<li>halftone-like print feel<\/li>\n\n\n\n<li>generative patterns<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Especially in Processing, dithering often behaves less like \u201cimage processing\u201d and more like \u201ctexture generation.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. <strong>Ordered dithering (Bayer)<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This article covered the basics of <strong>Ordered dithering (Bayer)<\/strong> and implemented it in Processing.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>dithering is a technique to create the illusion of intermediate tones using limited tones<\/li>\n\n\n\n<li>ordered dithering changes the threshold depending on pixel position<\/li>\n\n\n\n<li>the Bayer matrix is a priority map that defines the order of becoming white<\/li>\n\n\n\n<li>4\u00d74, 8\u00d78, 16\u00d716 change both pattern and tonal characteristics<\/li>\n\n\n\n<li>the pattern of ordered dithering can be a drawback or an aesthetic strength<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the next article, the other major family\u2014<strong>Error diffusion<\/strong>\u2014will be covered by implementing Floyd\u2013Steinberg dithering in Processing and comparing it with ordered dithering.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">References<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ordered dithering \u2014 Wikipedia<br><a href=\"https:\/\/en.wikipedia.org\/wiki\/Ordered_dithering?utm_source=chatgpt.com\">https:\/\/en.wikipedia.org\/wiki\/Ordered_dithering<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. Work Example | Sound visualization<\/h2>\n\n\n\n<blockquote class=\"instagram-media\" data-instgrm-permalink=\"https:\/\/www.instagram.com\/reel\/DUibZtIE9Wu\/?utm_source=ig_embed&amp;utm_campaign=loading\" data-instgrm-version=\"14\" style=\" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);\"><div style=\"padding:16px;\"> <a href=\"https:\/\/www.instagram.com\/reel\/DUibZtIE9Wu\/?utm_source=ig_embed&amp;utm_campaign=loading\" style=\" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;\" target=\"_blank\"> <div style=\" display: flex; flex-direction: row; align-items: center;\"> <div style=\"background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;\"><\/div> <div style=\"display: flex; flex-direction: column; flex-grow: 1; justify-content: center;\"> <div style=\" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;\"><\/div> <div style=\" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;\"><\/div><\/div><\/div><div style=\"padding: 19% 0;\"><\/div> <div style=\"display:block; height:50px; margin:0 auto 12px; width:50px;\"><svg width=\"50px\" height=\"50px\" viewBox=\"0 0 60 60\" version=\"1.1\" xmlns=\"https:\/\/www.w3.org\/2000\/svg\" xmlns:xlink=\"https:\/\/www.w3.org\/1999\/xlink\"><g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"><g transform=\"translate(-511.000000, -20.000000)\" fill=\"#000000\"><g><path d=\"M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631\"><\/path><\/g><\/g><\/g><\/svg><\/div><div style=\"padding-top: 8px;\"> <div style=\" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;\">View this post on Instagram<\/div><\/div><div style=\"padding: 12.5% 0;\"><\/div> <div style=\"display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;\"><div> <div style=\"background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);\"><\/div> <div style=\"background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;\"><\/div> <div style=\"background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);\"><\/div><\/div><div style=\"margin-left: 8px;\"> <div style=\" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;\"><\/div> <div style=\" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)\"><\/div><\/div><div style=\"margin-left: auto;\"> <div style=\" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);\"><\/div> <div style=\" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);\"><\/div> <div style=\" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);\"><\/div><\/div><\/div> <div style=\"display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;\"> <div style=\" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;\"><\/div> <div style=\" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;\"><\/div><\/div><\/a><p style=\" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;\"><a href=\"https:\/\/www.instagram.com\/reel\/DUibZtIE9Wu\/?utm_source=ig_embed&amp;utm_campaign=loading\" style=\" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;\" target=\"_blank\">A post shared by bgd peco (@barbe_generative_diary)<\/a><\/p><\/div><\/blockquote>\n<script async src=\"\/\/www.instagram.com\/embed.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"MinkowskiDistance-05\"><em>Recommended Book \/ Generative art for beginner<\/em><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"576\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2023\/09\/GenerativeArtProcessing.webp\" alt=\"\" class=\"wp-image-327 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2023\/09\/GenerativeArtProcessing.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2023\/09\/GenerativeArtProcessing-300x169.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2023\/09\/GenerativeArtProcessing-768x432.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/576;\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/amzn.to\/3rBeaOZ\" target=\"_blank\" rel=\"noreferrer noopener\">Generative Art: A Practical Guide Using Processing<\/a><a href=\"https:\/\/amzn.to\/45Xzptl\" target=\"_blank\" rel=\"noreferrer noopener\">&nbsp;<\/a>\u2013 Matt Pearson<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Generative Art presents both the techniques and the beauty of algorithmic art. In it, you\u2019ll find dozens of high-quality examples of generative art, along with the specific steps the author followed to create each unique piece using the Processing programming language. The book includes concise tutorials for each of the technical components required to create the book\u2019s images, and it offers countless suggestions for how you can combine and reuse the various techniques to create your own works.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.<br>\u2014\u2013<br>\u25ba&nbsp;<strong><a href=\"https:\/\/amzn.to\/3rBeaOZ\" target=\"_blank\" rel=\"noreferrer noopener\">Generative Art: A Practical Guide Using Processing<\/a><\/strong>&nbsp;\u2013 Matt Pearson<br>Publication date: 2011. July<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;<strong>Support my Website<\/strong><br>By using our affiliate links, you\u2019re helping my content and allows me to keep creating valuable articles. I appreciate it so much:)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"BGD_SOUNDS\"><em>BGD_SOUNDS (barbe_generative_diary SOUNDS)<\/em><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">barbe_generative_diary SOUNDS will start sharing and selling a variety of field recordings collected for use in my artwork \u201cSound Visualization\u201d experiments. All sounds are royalty-free.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/barbegenerativediary.bandcamp.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Link \/ BGD_SOUNDS on bandcamp<\/strong><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"731\" data-src=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2024\/07\/240801_bandcamp-top-BGD_SOUNDS.webp\" alt=\"\" class=\"wp-image-554 lazyload\" data-srcset=\"https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2024\/07\/240801_bandcamp-top-BGD_SOUNDS.webp 1024w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2024\/07\/240801_bandcamp-top-BGD_SOUNDS-300x214.webp 300w, https:\/\/barbegenerativediary.com\/en\/wp-content\/uploads\/2024\/07\/240801_bandcamp-top-BGD_SOUNDS-768x548.webp 768w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/731;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Dithering is a classic technique that smooths images when colors are limited. While it may seem like simple black-and-white conversion, it drastically improves the appearance of gradients and textures.<\/p>\n","protected":false},"author":1,"featured_media":847,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,13],"tags":[],"class_list":["post-840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-processing-tutorials","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/posts\/840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/comments?post=840"}],"version-history":[{"count":10,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/posts\/840\/revisions\/855"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/media\/847"}],"wp:attachment":[{"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/media?parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/categories?post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barbegenerativediary.com\/en\/wp-json\/wp\/v2\/tags?post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}