Skip to content

Commit 2cfef09

Browse files
colinleroyColin Leroy-Mira
and
Colin Leroy-Mira
authored
Fix greyscale computation and inverted coords (TheAlgorithms#8905)
* Fix greyscale computation and inverted coords * Fix test * Add test cases * Add reference to the greyscaling formula --------- Co-authored-by: Colin Leroy-Mira <[email protected]>
1 parent 0ef9306 commit 2cfef09

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Diff for: digital_image_processing/dithering/burkes.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,29 @@ def __init__(self, input_img, threshold: int):
3939
def get_greyscale(cls, blue: int, green: int, red: int) -> float:
4040
"""
4141
>>> Burkes.get_greyscale(3, 4, 5)
42-
3.753
42+
4.185
43+
>>> Burkes.get_greyscale(0, 0, 0)
44+
0.0
45+
>>> Burkes.get_greyscale(255, 255, 255)
46+
255.0
4347
"""
44-
return 0.114 * blue + 0.587 * green + 0.2126 * red
48+
"""
49+
Formula from https://en.wikipedia.org/wiki/HSL_and_HSV
50+
cf Lightness section, and Fig 13c.
51+
We use the first of four possible.
52+
"""
53+
return 0.114 * blue + 0.587 * green + 0.299 * red
4554

4655
def process(self) -> None:
4756
for y in range(self.height):
4857
for x in range(self.width):
4958
greyscale = int(self.get_greyscale(*self.input_img[y][x]))
5059
if self.threshold > greyscale + self.error_table[y][x]:
5160
self.output_img[y][x] = (0, 0, 0)
52-
current_error = greyscale + self.error_table[x][y]
61+
current_error = greyscale + self.error_table[y][x]
5362
else:
5463
self.output_img[y][x] = (255, 255, 255)
55-
current_error = greyscale + self.error_table[x][y] - 255
64+
current_error = greyscale + self.error_table[y][x] - 255
5665
"""
5766
Burkes error propagation (`*` is current pixel):
5867

0 commit comments

Comments
 (0)