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

Image RGB to CMYK : Image Conversion - MATLAB Code (RGB to CMYK, CMYK to RGB)

MATAB use makecform and applycform functions to perform this color model conversion  Ref: makecform:  https://www.mathworks.com/help/images/ref/makecform.html Ref: applycform:  https://www.mathworks.com/help/images/ref/applycform.html RGB to CMYK: I_rgb = imread('lena_color.jpg'); %Read the color image  C = makecform('srgb2cmyk');     %srgb (standard rgb) to cmyk  I_CMYK= applycform(I_rgb,C); TO SAVE IN CMYK Format imwrite(I_CMYK, 'test.tiff'); USE IMFINFO to confirm the conversion imfinfo('test.tiff') the command gives the output ... Width: 512 Height: 512 BitDepth: 32 ColorType: 'CMYK' ... CMYK to RGB: I_CMYK = imread('lena_color.jpg'); %Read the color image  C = makecform('cmyk2srgb');     %srgb (standard rgb) to cmyk  I_rgb= applycform(I_CMYK, C);

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