Skip to main content

Bayer's Digital Halftoning - (Dispersed and Clustered Dot) (Bayers Halftone) MATLAB and Python Code

To understand digital halftoning and ordered dithering please check this page

http://imageprocessing-sankarsrin.blogspot.tw/2016/12/digital-half-toning-ordered-dithering.html


Check the code

Python:

Ref: https://github.com/SankarSrin/Digital-Halftoning


MATLAB Code:

%%%%%%%Function to generate Bayer's Halftone Patterns%%%%%%%%%%

%%   Author:
%%   Mr. Sankarasrinivasan
%%   Research Fellow, Multimedia Signal Processing Lab, NTUST, Taiwan
%%   Advisor: Prof. Jing Ming Guo
%%   Dated: Apr, 2018

%%Details
%%Bayers(im,met) im==> input image;
%% met=1; Bayers Dispersed Dot && met=2; Bayers Clustered Dot

function [HOD]=Bayers(im,met)
im=im2double(im);
[s1 s2]=size(im);

if (met==1)
%Bayers Dispersed Dot

DA=[00 48 12 60 03 51 15 63;
    32 16 44 28 35 19 47 31;
    08 56 04 52 11 59 07 55;
    40 24 36 20 43 27 39 23;
    02 50 14 62 01 49 13 61;
    34 18 46 30 33 17 45 29;
    10 58 06 54 09 57 05 53;
    42 26 38 22 41 25 37 21]/64;

else
%Bayers Clustered Dot

DA=[24 10 12 26 35 47 49 37;
    08 00 02 14 45 59 61 51;
    22 06 04 16 43 57 63 53;
    30 20 18 28 33 41 55 39;
    34 46 48 36 25 11 13 27;
    44 58 60 50 09 01 03 15;
    42 56 62 52 23 07 05 17;
    32 40 54 38 31 21 19 29;]/64;

end

mask=repmat(DA,s1/8,s2/8);
H=zeros(s1,s2);
HOD=im>mask;

end






Original Image

Clustered Dot Output


Dispersed Dot Output 


Comments

Popular posts from this blog

Digital Half Toning - Ordered Dithering - MATLAB Code Bayer/ Ulichney

Digital Half-toning is a technique to convert the gray scale / color image (in the range 0-255) to binary images (in the range 0-1)  that is useful for printing (especially black and white printers). Though at first glance dots are clearly visible, as Human Vision System is a low pass filter, when dots are printed closely and viewed from the specific distance it can be perceived as a continuous tone image (i.e. gray scale). In general, half toning techniques is widely used in newspapers, journals and magazines printing.  Halftoning algorithms aims for better #Image Quality #Low Complexity #Optimal ink usage Coming to the topic, Ordered dithering is one of the standard technique to produce halftone image from continuous (gray scale) images. Let us assume, the first block containing 'B' is an image matrix and the  'H' is the threshold matrix. And the process is simply a element wise (pixel wise) comparison; if element of B > H (g...

Direct Binary Search Halftoning (DBS) - MATLAB Code (Efficient Direct Binary Search, Halftoning)

Direct binary approach is a heuristic optimization method and is proven to be very powerful to  obtain optimized binary patterns. The approach achieves the least minimum square error between the perceived halftone and original image, though swap and toggle operation. The swap operation consists of switching the current pixel with eight of its neighborhood pixels. Toggle operation is about switching the values between 0 to 1 or vice versa (as shown in Fig. below)      With each iteration, the perceived error starts to reduce and in finally a superior halftone quality is achieved. The method is computationally very expensive and difficult to implement in hardware. The code for Efficient DBS is provided in the link: (MATLAB Code) https://github.com/SankarSrin/EDBS-Halftoning

Digital Half-toning Error Diffusion Method (Floyd-Steinberg) - MATLAB Code

Introduction to Digital Half toning is provided in the below link http://imageprocessing-sankarsrin.blogspot.tw/2016/12/digital-half-toning-ordered-dithering.html The halftones are generally obtained by thresholding each image pixel with a certain value (ex. 128). In error diffusion, the error is computed between the actual and obtained output and it is distributed to the neighborhood pixels. Floyd-Stein berg, Jarvis, Stucki kernels are widely adopted  to distribute the error. The Error Diffusion half toning is as follows 1) image(x,y) > 128  Apply thresholding (assume  the image pixel value is 157,  in that case, 255 will be assigned to output). ( as the half toning corresponds to two values 0 and 255) 2) Compute the error between actual and obtained output    E=   255-157= 98 3) In case of floyd steinberg the value 98 is distributed along the neighborhood pixels 4) This steps are performed in sequence and serpentine scan yield...