Skip to content

Commit a5a46c2

Browse files
authored
Add files via upload
1 parent 0064f53 commit a5a46c2

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

script/bayer_dithering.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import cv2
2+
3+
bayerMatrix_8X8_1 = [
4+
[0,48,12,60,3,51,15,63],
5+
[32,16,44,28,35,19,47,31],
6+
[8,56,4,52,11,59,7,55],
7+
[40,24,36,20,43,27,39,23],
8+
[2,50,14,62,1,49,13,61],
9+
[34,18,46,30,33,17,45,29],
10+
[10,58,6,54,9,57,5,53],
11+
[42,26,38,22,41,25,37,21]
12+
]
13+
14+
bayerMatrix_8X8_2 = [
15+
[ 0, 32, 8, 40, 2, 34, 10, 42], ### 8x8 Bayer ordered dithering
16+
[48, 16, 56, 24, 50, 18, 58, 26], ### pattern. Each input pixel
17+
[12, 44, 4, 36, 14, 46, 6, 38], ### is scaled to the 0..63 range
18+
[60, 28, 52, 20, 62, 30, 54, 22], ### before looking in this table
19+
[ 3, 35, 11, 43, 1, 33, 9, 41], ### to determine the action.
20+
[51, 19, 59, 27, 49, 17, 57, 25],
21+
[15, 47, 7, 39, 13, 45, 5, 37],
22+
[63, 31, 55, 23, 61, 29, 53, 21]
23+
]
24+
25+
bayerMatrix_4X4_1 = [
26+
[0, 8, 2, 10],
27+
[12, 4, 14, 6],
28+
[3, 11, 1, 9],
29+
[15, 7, 13, 5],
30+
]
31+
32+
bayerMatrix_3X3_1 = [
33+
[0, 7, 3],
34+
[6, 5, 2],
35+
[4, 1, 8],
36+
]
37+
38+
bayerMatrix_2X2_1 = [
39+
[0, 2],
40+
[3, 1],
41+
]
42+
43+
def process_dither_color(img, matrix):
44+
height = img.shape[0]
45+
width = img.shape[1]
46+
matrix_len = len(matrix) - 1
47+
for row in range(height):
48+
for col in range(width):
49+
50+
color = img[row][col]
51+
52+
if color >= (color>>2) > matrix[row&matrix_len][col&matrix_len]:
53+
v = 255
54+
else:
55+
v = 0
56+
57+
img[row][col] = v
58+
59+
def dither_color_image(image, matrix):
60+
blue=image[:,:,0] #taking the blue channel
61+
process_dither_color(blue, matrix)
62+
green=image[:,:,1]
63+
process_dither_color(green, matrix)
64+
red=image[:,:,2]
65+
process_dither_color(red, matrix)
66+
return cv2.merge((blue, green, red))

0 commit comments

Comments
 (0)