当前位置:网站首页>Matlab: halftone and dither conversion

Matlab: halftone and dither conversion

2022-06-12 05:20:00 Morol_

《MATLAB: Image halftone (halftone) Display and jitter (dither) Show 》
This paper addresses https://blog.csdn.net/qq_39475211/article/details/86664284

What is halftone (halftone)

Halftone (Halftone) Technology is used in traditional printing to process step and simulate continuous tone (Continue tone) Methods .
 Discontinuous and continuous tone chart : Discontinuous and continuous tone

An image printed on a printer or printer , Levels can only be expressed by inking or not , Binary images like this are called halftone images . As long as we adjust different forms 、 Ink dots of different sizes , The principle that the human eye can visually integrate the adjacent ink points in the image , Observe at a certain distance , The binary image can reproduce the feeling of continuous tone .
 Halftone
It can be intuitively understood as sacrificing space to achieve different depths , Use the number of ink points to realize the change of printing depth .

The usual classification

The halftones are amplitude modulation (Amplitude Modulation, AM) And FM (Frequency Modulation, FM), Simply speaking ,AM Is the use of dot area size to show the intensity of the image ;FM It is based on the density of dot arrangement spacing , To present the hierarchy of the image .

A little experiment 1

1. Read cameraman.tif Images , Write your own code , complete 4x4 Of halftone Convert and display ;

AM Method :
Divide the pixel gray value of the image into 16 rank ( In fact, it can also be 17 rank ), Then corresponding to the original pixel position is expanded to 4x4 grid . Different intensity of gray scale will blacken different number of grids .
 Insert picture description here
such as , stay 256 Grayscale medium , The grayscale of a pixel is 30, Because we divide the pixel gray value of the image into 16 rank ( Grayscale 0~15 by 1 rank ,16-31 by 2 rank ……), So this pixel is 4x4 Apply... To the grid 2 grid .

( Where to paint the grid ? In fact, the position of painting is not very important , The key is the number of coats .)

After this treatment , Original 30x30 The image becomes 120x120 size .
 Experimental results
Same number of colors , Different painting positions - contrast :
 Different colors

shake (dither)

shake (dither) It is also a classification of halftones , It is mainly divided into two categories: random jitter and ordered jitter . Both algorithms require a template , Also known as jitter matrix or threshold matrix , The dithering matrix not only determines the order in which the dots become black dots when the brightness or gray value decreases , It also determines the quality of halftone image , So the key of dithering algorithm is the construction of dithering matrix .

For specific principles, please refer to the article of the boss :https://blog.csdn.net/songzitea/article/details/40832565

A little experiment 2

  1. read dither.pdf file , Use after understanding matlab Self contained dither Function pair cameraman.tif Image processing dither Convert and display .
    We use it directly MATLAB Self contained dither() function :
    MATLAB Official website (https://ww2.mathworks.cn/help/matlab/ref/dither.html?s_tid=srchtitle) There is an introduction in Chinese .
     Insert picture description here

attach : Main code MATLAB

A little experiment 1( Halftonic halftone)

I=imread('cameraman.tif'); % Read images 
J=I/16; % Gray scale 16 level 
K=zeros(1024,1024); % Create a new empty matrix to save the results 
for x=1:1:256
   for y=1:1:256
       switch J(x,y) % matching 16 Different gray levels , For empty matrix 4X4 halftone preservation 
           case 1
           case 2
               K(4*x-3,4*y-3)=1;
           case 3
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;
           case 4
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;
           case 5
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
           case 6
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;
           case 7
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;
           case 8
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;
               case 9
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
           case 10
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;
           case 11
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;
           case 12
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;K(4*x-2,4*y-3)=1;
           case 13
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;K(4*x-2,4*y-3)=1;K(4*x-1,4*y-2)=1;
           case 14
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;K(4*x-2,4*y-3)=1;K(4*x-1,4*y-2)=1;
               K(4*x-1,4*y-3)=1;
                case 15
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;K(4*x-2,4*y-3)=1;K(4*x-1,4*y-2)=1;
               K(4*x-1,4*y-3)=1;K(4*x,4*y-2)=1;
           case 16
               K(4*x-3,4*y-3)=1;K(4*x-2,4*y-2)=1;K(4*x-1,4*y-1)=1;K(4*x,4*y)=1;
               K(4*x-2,4*y-1)=1;K(4*x-3,4*y-2)=1;K(4*x-1,4*y)=1;K(4*x-3,4*y-1)=1;
               K(4*x-2,4*y)=1;K(4*x-3,4*y)=1;K(4*x-2,4*y-3)=1;K(4*x-1,4*y-2)=1;
               K(4*x-1,4*y-3)=1;K(4*x,4*y-2)=1;K(4*x,4*y-1)=1;
       end
   end
end

Complete code in https://download.csdn.net/download/qq_39475211/10940207
There is no way to modify C The coin …… You can find a treasure to download it

A little experiment 2( shake dither)

I = imread('cameraman.tif');
X = dither(I);
subplot(1,2,1),imshow(I),title("sample"); 
subplot(1,2,2),imshow(X),title("dither");

by:Morol
[email protected]

原网站

版权声明
本文为[Morol_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010618251542.html