DIGITAL HALFTONE Wayne Weiyi Chen
Total Page:16
File Type:pdf, Size:1020Kb
DIGITAL HALFTONE Wayne Weiyi Chen 1.1. INTRODUCTION The final workflow of any digital photography is to print out the image. This procedure is actually very similar to what the digital display doing: both of them distribute small dots into the space with different size and density to create illusions that there is different color or luminance. Digital Halftone is the method that we use to create a ready-to-print image. The basic idea behind is using different threshold to windowing the image so that the density of dots can be distinguished according to the intensity of grayscale images. In this problem, we will investigate this procedure and implement two categories of different methods. We will briefly introduce these two categories of algorithm and then show their results, compare their performance and give a discussion on that. Figure 1. man.raw Page 1 of 16 1.2. METHODOLOGY 1.2.1. Dithering Matrix The idea of dithering matrix is that instead of introducing noise to the image for thresholding out different density of dots, we generate the threshold matrix with its element fluctuating in a certain range. By doing this, we are able to halftone grayscale images into binary images with different distributions of dots without adding noise. A 2nd order Bayer index matrix is defined as éù02 (8) I2 = êú ëû31 The higher order Bayer index matrix is recursively defined as éù442´´IInn+ I2n = êú (9) ëû4341´IInn+´+ After a Bayer index matrix is generated, we can use it to form a threshold matrix using the formula: Ixy( ,) + 0.5 Txy( ,) =2n ´ 255 N 2 (10) xy,Î-{ 0,1,2,...,2 n 1} where N is the size of the image. Then the grayscale image can be transferred into a binary image using ì1 Fij( ,mod,mod) > Ti( Nj N) Gij( , ) = í (11) î0 otherwise In this problem, we also need to generate several index matrixes with the form being similar to éù14 10 11 15 êú9304 A = êú (12) 4 êú8215 êú ëû13 7 6 12 This form can be illustrated as a set of increasing number spiraling out from the center of the matrix. We will discuss the performance using these different matrixes. 1.2.2. Error Diffusion Another method we want to explore is error diffusion. The basic idea of error diffusion is that we slide a window through the image with thresholding the pixels into binary output and spread out Page 2 of 16 the error introducing by this thresholding, adding to the current pixel’s future neighbors’ pixel value before thresholding them. To be specific, firstly we normalize the pixel value from range [0, 255] to[0,1], then threshold the pixel value into either 0 or 1, calculate the error between the generated binary value and the original value: Eij( ,,,) = Fij( ) - Gij( ) (13) And spread this error into the neighborhood according to the error diffusion matrix, such as Floyd- Steinberg’s, Jarvis, Judice and Ninke’s (JJN) and Stucki’s error diffusion matrix showing below respectively: éù00000 éù00000 éù000 êú00000 êú00000 1 1 êú1 êú êú007 êú00075 êú00084 (14) 16 êú 48 êú42 êú ëûêú351 êú35753 êú24842 ëûêú13531 ëûêú12421 We use a serpentine scheme when diffusing the error, that is, with even lines (i=0, 2, 4…) we use above matrixes sliding from left to right, while with odd lines (i=1, 3, 5…) we use matrixes in (15) sliding from right to left. éù00000 éù00000 éù000 êú00000 êú00000 1 1 êú1 êú êú700 êú57000 êú48000 (15) 16 êú 48 êú42 êú ëûêú153 êú35753 êú24842 ëûêú13531 ëûêú12421 1.3. RESULTS 1.3.1. Dithering Matrix In the first part of this problem, several matrixes are created. The Bayer index matrix can be generated recursively. The 2nd, 4th and 8th order Bayer index matrix is showing below Page 3 of 16 éù0 32 8 40 2 34 10 42 êú êú48 16 56 24 50 18 58 26 éù0 8 2 10 êú12 44 4 36 14 46 6 38 êú 02 êú éùêú12 4 14 6 êú60 28 52 20 62 30 54 22 I2 = êúI4 = I8 = (16) ëû31 êú3 11 1 9 êú3 35 11 43 1 33 9 41 êúêú ëû15 7 13 5 êú51 19 59 27 49 17 57 25 êú15 47 7 39 13 45 5 37 êú ëûêú63 31 55 23 61 29 53 21 With the scanning method mentioned above, we firstly show the result from I2 and I8 in Fig.24 and Fig.25. Due to the reason that I8 having more threshold value than I2 , its result has more delicate distribution variation and therefore a slightly better look. Figure 2. Halftone Using Dithering Matrix I2 Page 4 of 16 Figure 3. Halftone Using Dithering Matrix I8 Besides the Bayer index matrixes, we can also employ other designs, such as A4 mentioned in the (12). Also, we can generate a higher order matrix with similar structure with A4 : éù60 42 43 44 45 46 47 61 êú êú41 33 24 25 26 27 34 48 êú40 23 14 10 11 15 28 49 êú 39 22 9 3 0 4 29 50 A = êú (17) 8 êú38 21 8 2 1 5 30 51 êú êú37 20 13 7 6 12 31 52 êú36 32 19 18 17 16 35 53 êú ëûêú63 59 58 57 56 55 54 62 Page 5 of 16 The results from I4 , A4 and A8 is showing below in Fig.26, Fig.27 and Fig.28 respectively. We will discuss the rationale of differences among these results with comparing the property of these two categories of dithering matrix in the discussion part. Figure 4. Result of Dithering Matrix I4 Page 6 of 16 Figure 5. Result of Dithering Matrix A4 Page 7 of 16 Figure 6. Result of Dithering Matrix A8 Page 8 of 16 As a final part of the dithering matrix method, we want to take a look into the case where the printer is able to output FOUR levels of intensity. We still use Bayer index matrix I4 to generate dithering matrix for comparison. We will discuss our design in detail in the discussion part; here we only show the result in the Fig.29. The output result is significantly improved comparing to the ones with binary values. Figure 7. 4-Color Printing-Ready Output Using Bayer Dithering Matrix I4 Page 9 of 16 1.3.2. Error Diffusion As the second part of the problem, we utilize three different error diffusion schemes on the original grayscale image: Floyd-Steinberg’s, JJN’s and Stucki’s; we show their output results in Fig.30, Fig.31 and Fig.32 respectively. Figure 8. Error Diffusion Using Floyd-Stein's Scheme Page 10 of 16 Figure 9. Error Diffusion Using JJN's Scheme Page 11 of 16 Figure 10. Error Diffusion Using Stucki's Scheme Page 12 of 16 1.4. DISCUSSION 1.4.1. The Differences between Bayer Index Matrixes and A Matrixes As we can see from formulas (12), (16) and (17), Bayer index matrix I2n has different form comparing to the A2n : I2n has a higher level of disorderly distributed indices, while A2n has its indices spiral out from small number to large number. This difference introduces a very obvious performance disparity between them: the Bayer index matrix deliver a better result. The reason for this is because with small thresholds concentrated in the center of each window, it is easier to generate “white-inside-and-black-outside” sub-graphs through all of the pixels in the image, results in an image obviously filled with many small black frames, shown in Fig.27 and Fig.28. And the situation is further exacerbated when we have a higher order, as comparing A8 (Fig.28) to A4 (Fig.27). Also we may notice that both I4 and I8 have a more delicate (therefore better) output result than I2 do because they have a more meticulous structure of threshold; however, this difference become insignificant among the ones with higher order such as I4 , I8 , I16 and so on. 1.4.2. The Algorithms Using in the Dithering Matrix Method Generate Bayer Index Matrix The Bayer index matrix is recursively generated in our program. The recursive function can be illustrated as following: • Loop on index of the matrix, for each element, return its value according to its position • If the order of the matrix is larger than 2, than divide the matrix into four sub-matrixes, and calculate the new position of the element in the sub-matrix, recursively send them to the function with matrix in half of current order. • The recursion ends where the order of the matrix is 2, for the 4 elements, successively return 0, 3, 2 and 1. Using this mechanism, we can easily generate a Bayer index matrix providing any given order. 4-Color Printing-Ready Output Method As we have seen in the Fig.29, the 4-color output of dithering matrix method is much better than the binary output. This is reasonable because more level of grayscale means we can have more delicate results. To generate a 4-color output, we need to setup not only 1 threshold, but also another 2 of them to further distinguish which one of the 4 values the grayscale intensity should become. And also we may need to note that we should still use the dithering matrix method instead of simply establish 4 different threshold. As a result, we keep using Bayer index matrix to generate the thresholds; however, we change the scheme that transfer them to the threshold matrixes: Page 13 of 16 Ixy( ,) + 0.5 Txy( ,) =2n ´ 127 1 N 2 Ixy( ,) + 0.5 Txy( ,) =2n ´ 127+ 64 2 N 2 Ixy( ,) + 0.5 Txy( ,) =2n ´ 127+ 128 (18) 3 N 2 xy,Î-{ 0,1,2,...,2 n 1} Therefore we re-arrange the thresholds into new range: T1 Î[0,127] T2 Î[64,191] (19) T3 Î[128,255] Note that although there are overlaps between these ranges, for each pixel in the image we need not to worry the overlapping or interlacing of corresponding three thresholds because they are transferred from the same one Bayer index.