From 201ca25ca47b909c67bce3c9e744befb20d2f252 Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Wed, 29 Apr 2020 11:25:50 +0200 Subject: [PATCH 01/17] Added Burkes dithering algorithm --- .../dithering/__init__.py | 0 digital_image_processing/dithering/burkes.py | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 digital_image_processing/dithering/__init__.py create mode 100644 digital_image_processing/dithering/burkes.py diff --git a/digital_image_processing/dithering/__init__.py b/digital_image_processing/dithering/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py new file mode 100644 index 000000000000..cfe3d3108591 --- /dev/null +++ b/digital_image_processing/dithering/burkes.py @@ -0,0 +1,71 @@ +""" +Implementation Burke's algorithm (dithering) +""" +from cv2 import imread, imshow, waitKey, destroyAllWindows, IMREAD_GRAYSCALE +import numpy as np + + +class Burkes: + """ + Burke's algorithm is using for converting grayscale image to black and white version + Source: Source: https://en.wikipedia.org/wiki/Dither + """ + + def __init__(self, input_img, threshold: int): + self.min_threshold = 0 + self.max_threshold = int(self.get_greyscale(255, 255, 255)) # max greyscale value for #FFFFFF + + if not self.min_threshold < threshold < self.max_threshold: + raise ValueError(f"Factor value should be from 0 to {self.max_threshold}") + + self.input_img = input_img + self.threshold = threshold + self.width, self.height = self.input_img.shape[1], self.input_img.shape[0] + + # error table size (+2 columns and +1 row) greater than input image because of lack of if statements + self.error_table = [[0 for _ in range(self.width + 4)] for __ in range(self.height + 1)] + self.output_img = np.ones((self.height, self.width, 3), np.uint8) * 255 + + @staticmethod + def get_greyscale(red, green, blue): + return 0.2126 * red + 0.587 * green + 0.114 * blue + + def process(self): + for y in range(self.height): + for x in range(self.width): + if self.threshold > self.input_img[y][x] + self.error_table[y][x]: + self.output_img[y][x] = (0, 0, 0) + current_error = self.input_img[y][x] + self.error_table[y][x] + else: + self.output_img[y][x] = (255, 255, 255) + current_error = self.input_img[y][x] + self.error_table[y][x] - 255 + + """ + Burkes error propagation (`*` is current pixel): + + * 8/32 4/32 + 2/32 4/32 8/32 4/32 2/32 + """ + self.error_table[y][x + 1] = self.error_table[y][x + 1] + 8 / 32 * current_error + self.error_table[y][x + 2] = self.error_table[y][x + 2] + 4 / 32 * current_error + self.error_table[y + 1][x] = self.error_table[y + 1][x] + 8 / 32 * current_error + self.error_table[y + 1][x + 1] = self.error_table[y + 1][x + 1] + 4 / 32 * current_error + self.error_table[y + 1][x + 2] = self.error_table[y + 1][x + 2] + 2 / 32 * current_error + self.error_table[y + 1][x - 1] = self.error_table[y + 1][x - 1] + 4 / 32 * current_error + self.error_table[y + 1][x - 2] = self.error_table[y + 1][x - 2] + 2 / 32 * current_error + + +if __name__ == '__main__': + # create Burke's instances with original images in greyscale + burkes_instances = [ + Burkes(imread("image_data/lena.jpg", IMREAD_GRAYSCALE), threshold) for threshold in (80, 100, 120, 200, 215) + ] + + for burkes in burkes_instances: + burkes.process() + + for burkes in burkes_instances: + imshow(f"Original image with dithering threshold: {burkes.threshold}", burkes.output_img) + + waitKey(0) + destroyAllWindows() From fa79687ff9418c3e16cd68ab5279916972fe36b9 Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Wed, 29 Apr 2020 11:42:24 +0200 Subject: [PATCH 02/17] Added unit tests for burkes algorithm --- digital_image_processing/dithering/burkes.py | 48 ++++++++++++++----- .../test_digital_image_processing.py | 13 ++++- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index cfe3d3108591..d45f7140d2b9 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -13,7 +13,9 @@ class Burkes: def __init__(self, input_img, threshold: int): self.min_threshold = 0 - self.max_threshold = int(self.get_greyscale(255, 255, 255)) # max greyscale value for #FFFFFF + self.max_threshold = int( + self.get_greyscale(255, 255, 255) + ) # max greyscale value for #FFFFFF if not self.min_threshold < threshold < self.max_threshold: raise ValueError(f"Factor value should be from 0 to {self.max_threshold}") @@ -23,11 +25,13 @@ def __init__(self, input_img, threshold: int): self.width, self.height = self.input_img.shape[1], self.input_img.shape[0] # error table size (+2 columns and +1 row) greater than input image because of lack of if statements - self.error_table = [[0 for _ in range(self.width + 4)] for __ in range(self.height + 1)] + self.error_table = [ + [0 for _ in range(self.width + 4)] for __ in range(self.height + 1) + ] self.output_img = np.ones((self.height, self.width, 3), np.uint8) * 255 @staticmethod - def get_greyscale(red, green, blue): + def get_greyscale(red: int, green: int, blue: int): return 0.2126 * red + 0.587 * green + 0.114 * blue def process(self): @@ -46,26 +50,44 @@ def process(self): * 8/32 4/32 2/32 4/32 8/32 4/32 2/32 """ - self.error_table[y][x + 1] = self.error_table[y][x + 1] + 8 / 32 * current_error - self.error_table[y][x + 2] = self.error_table[y][x + 2] + 4 / 32 * current_error - self.error_table[y + 1][x] = self.error_table[y + 1][x] + 8 / 32 * current_error - self.error_table[y + 1][x + 1] = self.error_table[y + 1][x + 1] + 4 / 32 * current_error - self.error_table[y + 1][x + 2] = self.error_table[y + 1][x + 2] + 2 / 32 * current_error - self.error_table[y + 1][x - 1] = self.error_table[y + 1][x - 1] + 4 / 32 * current_error - self.error_table[y + 1][x - 2] = self.error_table[y + 1][x - 2] + 2 / 32 * current_error + self.error_table[y][x + 1] = ( + self.error_table[y][x + 1] + 8 / 32 * current_error + ) + self.error_table[y][x + 2] = ( + self.error_table[y][x + 2] + 4 / 32 * current_error + ) + self.error_table[y + 1][x] = ( + self.error_table[y + 1][x] + 8 / 32 * current_error + ) + self.error_table[y + 1][x + 1] = ( + self.error_table[y + 1][x + 1] + 4 / 32 * current_error + ) + self.error_table[y + 1][x + 2] = ( + self.error_table[y + 1][x + 2] + 2 / 32 * current_error + ) + self.error_table[y + 1][x - 1] = ( + self.error_table[y + 1][x - 1] + 4 / 32 * current_error + ) + self.error_table[y + 1][x - 2] = ( + self.error_table[y + 1][x - 2] + 2 / 32 * current_error + ) -if __name__ == '__main__': +if __name__ == "__main__": # create Burke's instances with original images in greyscale burkes_instances = [ - Burkes(imread("image_data/lena.jpg", IMREAD_GRAYSCALE), threshold) for threshold in (80, 100, 120, 200, 215) + Burkes(imread("image_data/lena.jpg", IMREAD_GRAYSCALE), threshold) + for threshold in (80, 100, 120, 200, 215) ] for burkes in burkes_instances: burkes.process() for burkes in burkes_instances: - imshow(f"Original image with dithering threshold: {burkes.threshold}", burkes.output_img) + imshow( + f"Original image with dithering threshold: {burkes.threshold}", + burkes.output_img, + ) waitKey(0) destroyAllWindows() diff --git a/digital_image_processing/test_digital_image_processing.py b/digital_image_processing/test_digital_image_processing.py index 5c6127337599..dd7ef0305469 100644 --- a/digital_image_processing/test_digital_image_processing.py +++ b/digital_image_processing/test_digital_image_processing.py @@ -10,13 +10,15 @@ import digital_image_processing.change_contrast as cc import digital_image_processing.convert_to_negative as cn import digital_image_processing.sepia as sp -from cv2 import imread, cvtColor, COLOR_BGR2GRAY +import digital_image_processing.dithering.burkes as bs +from cv2 import imread, cvtColor, COLOR_BGR2GRAY, IMREAD_GRAYSCALE from numpy import array, uint8 from PIL import Image img = imread(r"digital_image_processing/image_data/lena_small.jpg") gray = cvtColor(img, COLOR_BGR2GRAY) + # Test: convert_to_negative() def test_convert_to_negative(): negative_img = cn.convert_to_negative(img) @@ -74,3 +76,12 @@ def test_sobel_filter(): def test_sepia(): sepia = sp.make_sepia(img, 20) assert sepia.all() + + +def test_burkes(): + burkes = bs.Burkes( + imread("digital_image_processing/image_data/lena_small.jpg", IMREAD_GRAYSCALE), + 120, + ) + burkes.process() + assert burkes.output_img.any() From a157b4770952bd3a5c18304f57eac19465301367 Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Wed, 29 Apr 2020 12:58:05 +0200 Subject: [PATCH 03/17] Fix burkes algorithm --- digital_image_processing/dithering/burkes.py | 21 ++++++++++--------- .../test_digital_image_processing.py | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index d45f7140d2b9..1df159ef40b0 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -1,7 +1,7 @@ """ Implementation Burke's algorithm (dithering) """ -from cv2 import imread, imshow, waitKey, destroyAllWindows, IMREAD_GRAYSCALE +from cv2 import imread, imshow, waitKey, destroyAllWindows import numpy as np @@ -24,25 +24,26 @@ def __init__(self, input_img, threshold: int): self.threshold = threshold self.width, self.height = self.input_img.shape[1], self.input_img.shape[0] - # error table size (+2 columns and +1 row) greater than input image because of lack of if statements + # error table size (+4 columns and +1 row) greater than input image because of lack of if statements self.error_table = [ - [0 for _ in range(self.width + 4)] for __ in range(self.height + 1) + [0 for _ in range(self.height + 4)] for __ in range(self.width + 1) ] - self.output_img = np.ones((self.height, self.width, 3), np.uint8) * 255 + self.output_img = np.ones((self.width, self.height, 3), np.uint8) * 255 @staticmethod - def get_greyscale(red: int, green: int, blue: int): + def get_greyscale(blue: int, green: int, red: int): return 0.2126 * red + 0.587 * green + 0.114 * blue def process(self): for y in range(self.height): for x in range(self.width): - if self.threshold > self.input_img[y][x] + self.error_table[y][x]: + greyscale = int(self.get_greyscale(*self.input_img[y][x])) + if self.threshold > greyscale + self.error_table[y][x]: self.output_img[y][x] = (0, 0, 0) - current_error = self.input_img[y][x] + self.error_table[y][x] + current_error = greyscale + self.error_table[x][y] else: self.output_img[y][x] = (255, 255, 255) - current_error = self.input_img[y][x] + self.error_table[y][x] - 255 + current_error = greyscale + self.error_table[x][y] - 255 """ Burkes error propagation (`*` is current pixel): @@ -76,8 +77,8 @@ def process(self): if __name__ == "__main__": # create Burke's instances with original images in greyscale burkes_instances = [ - Burkes(imread("image_data/lena.jpg", IMREAD_GRAYSCALE), threshold) - for threshold in (80, 100, 120, 200, 215) + Burkes(imread("image_data/lena.jpg", 1), threshold) + for threshold in (1, 126, 180, 200) ] for burkes in burkes_instances: diff --git a/digital_image_processing/test_digital_image_processing.py b/digital_image_processing/test_digital_image_processing.py index dd7ef0305469..db7af91fe6fc 100644 --- a/digital_image_processing/test_digital_image_processing.py +++ b/digital_image_processing/test_digital_image_processing.py @@ -80,8 +80,7 @@ def test_sepia(): def test_burkes(): burkes = bs.Burkes( - imread("digital_image_processing/image_data/lena_small.jpg", IMREAD_GRAYSCALE), - 120, + imread("digital_image_processing/image_data/lena_small.jpg", 1), 120, ) burkes.process() assert burkes.output_img.any() From b92ccd36f56ead81d867ee37ee1e7059d1b2545f Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Wed, 29 Apr 2020 13:02:27 +0200 Subject: [PATCH 04/17] Added some additional information --- digital_image_processing/dithering/burkes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 1df159ef40b0..d098e08e37bf 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -9,6 +9,10 @@ class Burkes: """ Burke's algorithm is using for converting grayscale image to black and white version Source: Source: https://en.wikipedia.org/wiki/Dither + + Note: + * Best results are given with threshold= ~1/2 * max greyscale value. + * This implementation get RGB image and converts it to greyscale in runtime. """ def __init__(self, input_img, threshold: int): @@ -78,7 +82,7 @@ def process(self): # create Burke's instances with original images in greyscale burkes_instances = [ Burkes(imread("image_data/lena.jpg", 1), threshold) - for threshold in (1, 126, 180, 200) + for threshold in (1, 126, 130, 140) ] for burkes in burkes_instances: From 0f2bbde219a40e488967bdfcf29a51a3978663be Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Wed, 29 Apr 2020 13:21:06 +0200 Subject: [PATCH 05/17] Fixed CI tests --- digital_image_processing/test_digital_image_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/test_digital_image_processing.py b/digital_image_processing/test_digital_image_processing.py index db7af91fe6fc..9b5c809b08a3 100644 --- a/digital_image_processing/test_digital_image_processing.py +++ b/digital_image_processing/test_digital_image_processing.py @@ -11,7 +11,7 @@ import digital_image_processing.convert_to_negative as cn import digital_image_processing.sepia as sp import digital_image_processing.dithering.burkes as bs -from cv2 import imread, cvtColor, COLOR_BGR2GRAY, IMREAD_GRAYSCALE +from cv2 import imread, cvtColor, COLOR_BGR2GRAY from numpy import array, uint8 from PIL import Image From 611e11368f9f7a07244c55530b92b19e5e790682 Mon Sep 17 00:00:00 2001 From: mateuszz0000 Date: Thu, 30 Apr 2020 08:49:00 +0200 Subject: [PATCH 06/17] Update digital_image_processing/dithering/burkes.py Co-Authored-By: Christian Clauss --- digital_image_processing/dithering/burkes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index d098e08e37bf..0ba886e4a9b5 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -55,9 +55,7 @@ def process(self): * 8/32 4/32 2/32 4/32 8/32 4/32 2/32 """ - self.error_table[y][x + 1] = ( - self.error_table[y][x + 1] + 8 / 32 * current_error - ) + self.error_table[y][x + 1] += 8 / 32 * current_error self.error_table[y][x + 2] = ( self.error_table[y][x + 2] + 4 / 32 * current_error ) From c872fc69c0ebfa1156576f25169231feac85a7e0 Mon Sep 17 00:00:00 2001 From: mateuszz0000 Date: Thu, 30 Apr 2020 08:49:08 +0200 Subject: [PATCH 07/17] Update digital_image_processing/dithering/burkes.py Co-Authored-By: Christian Clauss --- digital_image_processing/dithering/burkes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 0ba886e4a9b5..d3654df44ad3 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -28,7 +28,8 @@ def __init__(self, input_img, threshold: int): self.threshold = threshold self.width, self.height = self.input_img.shape[1], self.input_img.shape[0] - # error table size (+4 columns and +1 row) greater than input image because of lack of if statements + # error table size (+4 columns and +1 row) greater than input image because of + # lack of if statements self.error_table = [ [0 for _ in range(self.height + 4)] for __ in range(self.width + 1) ] From 8757600998966f60c1d15cf21764cd4cb87645e7 Mon Sep 17 00:00:00 2001 From: mateuszz0000 Date: Thu, 30 Apr 2020 08:49:21 +0200 Subject: [PATCH 08/17] Update digital_image_processing/dithering/burkes.py Co-Authored-By: Christian Clauss --- digital_image_processing/dithering/burkes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index d3654df44ad3..3bbf430fc57b 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -17,9 +17,8 @@ class Burkes: def __init__(self, input_img, threshold: int): self.min_threshold = 0 - self.max_threshold = int( - self.get_greyscale(255, 255, 255) - ) # max greyscale value for #FFFFFF + # max greyscale value for #FFFFFF + self.max_threshold = int(self.get_greyscale(255, 255, 255)) if not self.min_threshold < threshold < self.max_threshold: raise ValueError(f"Factor value should be from 0 to {self.max_threshold}") From 6b8e0693738447f5ef64ded7a46fa8580918a798 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 30 Apr 2020 11:10:48 +0200 Subject: [PATCH 09/17] Propogate the += and add a doctest --- digital_image_processing/dithering/burkes.py | 35 ++++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 3bbf430fc57b..57c5bf09b800 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -1,7 +1,7 @@ """ Implementation Burke's algorithm (dithering) """ -from cv2 import imread, imshow, waitKey, destroyAllWindows +from cv2 import destroyAllWindows, imread, imshow, waitKey import numpy as np @@ -35,10 +35,14 @@ def __init__(self, input_img, threshold: int): self.output_img = np.ones((self.width, self.height, 3), np.uint8) * 255 @staticmethod - def get_greyscale(blue: int, green: int, red: int): + def get_greyscale(blue: int, green: int, red: int) -> float: + """ + >>> get_greyscale(5, 4, 3) + 3.753 + """ return 0.2126 * red + 0.587 * green + 0.114 * blue - def process(self): + def process(self) -> None: for y in range(self.height): for x in range(self.width): greyscale = int(self.get_greyscale(*self.input_img[y][x])) @@ -48,7 +52,6 @@ def process(self): else: self.output_img[y][x] = (255, 255, 255) current_error = greyscale + self.error_table[x][y] - 255 - """ Burkes error propagation (`*` is current pixel): @@ -56,24 +59,12 @@ def process(self): 2/32 4/32 8/32 4/32 2/32 """ self.error_table[y][x + 1] += 8 / 32 * current_error - self.error_table[y][x + 2] = ( - self.error_table[y][x + 2] + 4 / 32 * current_error - ) - self.error_table[y + 1][x] = ( - self.error_table[y + 1][x] + 8 / 32 * current_error - ) - self.error_table[y + 1][x + 1] = ( - self.error_table[y + 1][x + 1] + 4 / 32 * current_error - ) - self.error_table[y + 1][x + 2] = ( - self.error_table[y + 1][x + 2] + 2 / 32 * current_error - ) - self.error_table[y + 1][x - 1] = ( - self.error_table[y + 1][x - 1] + 4 / 32 * current_error - ) - self.error_table[y + 1][x - 2] = ( - self.error_table[y + 1][x - 2] + 2 / 32 * current_error - ) + self.error_table[y][x + 2] += 4 / 32 * current_error + self.error_table[y + 1][x] += 8 / 32 * current_error + self.error_table[y + 1][x + 1] += 4 / 32 * current_error + self.error_table[y + 1][x + 2] += 2 / 32 * current_error + self.error_table[y + 1][x - 1] += 4 / 32 * current_error + self.error_table[y + 1][x - 2] += 2 / 32 * current_error if __name__ == "__main__": From f33f4ca764e0c198165db796a54e20605260e122 Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Thu, 30 Apr 2020 11:19:00 +0200 Subject: [PATCH 10/17] Fix doctest --- digital_image_processing/dithering/burkes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 57c5bf09b800..770f52a384b6 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -37,7 +37,7 @@ def __init__(self, input_img, threshold: int): @staticmethod def get_greyscale(blue: int, green: int, red: int) -> float: """ - >>> get_greyscale(5, 4, 3) + >>> Burkes.get_greyscale(5, 4, 3) 3.753 """ return 0.2126 * red + 0.587 * green + 0.114 * blue From 4cd6aa76290ce498d2bdc2298ce3f20a5143bd31 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 30 Apr 2020 11:20:25 +0200 Subject: [PATCH 11/17] @staticmethod --> @ classmethod to ease testing --- digital_image_processing/dithering/burkes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 770f52a384b6..8b8db0751ec1 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -34,8 +34,8 @@ def __init__(self, input_img, threshold: int): ] self.output_img = np.ones((self.width, self.height, 3), np.uint8) * 255 - @staticmethod - def get_greyscale(blue: int, green: int, red: int) -> float: + @classmethod + def get_greyscale(cls, blue: int, green: int, red: int) -> float: """ >>> Burkes.get_greyscale(5, 4, 3) 3.753 From bea2a4da9a7dff5606975977c4a4eb4cc7ab3c5d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 30 Apr 2020 11:21:57 +0200 Subject: [PATCH 12/17] def test_burkes(file_path): --- digital_image_processing/test_digital_image_processing.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/digital_image_processing/test_digital_image_processing.py b/digital_image_processing/test_digital_image_processing.py index 9b5c809b08a3..1915f17e973e 100644 --- a/digital_image_processing/test_digital_image_processing.py +++ b/digital_image_processing/test_digital_image_processing.py @@ -78,9 +78,7 @@ def test_sepia(): assert sepia.all() -def test_burkes(): - burkes = bs.Burkes( - imread("digital_image_processing/image_data/lena_small.jpg", 1), 120, - ) +def test_burkes(file_path: str="digital_image_processing/image_data/lena_small.jpg"): + burkes = bs.Burkes(imread(file_path, 1), 120) burkes.process() assert burkes.output_img.any() From 114ee8d4f6e70e1979e905c0fd7c38c1cabb3ed5 Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Thu, 30 Apr 2020 11:28:40 +0200 Subject: [PATCH 13/17] Fix for mypy checks --- digital_image_processing/dithering/burkes.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 8b8db0751ec1..0d7921f91c77 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -58,13 +58,13 @@ def process(self) -> None: * 8/32 4/32 2/32 4/32 8/32 4/32 2/32 """ - self.error_table[y][x + 1] += 8 / 32 * current_error - self.error_table[y][x + 2] += 4 / 32 * current_error - self.error_table[y + 1][x] += 8 / 32 * current_error - self.error_table[y + 1][x + 1] += 4 / 32 * current_error - self.error_table[y + 1][x + 2] += 2 / 32 * current_error - self.error_table[y + 1][x - 1] += 4 / 32 * current_error - self.error_table[y + 1][x - 2] += 2 / 32 * current_error + self.error_table[y][x + 1] += int(8 / 32 * current_error) + self.error_table[y][x + 2] += int(4 / 32 * current_error) + self.error_table[y + 1][x] += int(8 / 32 * current_error) + self.error_table[y + 1][x + 1] += int(4 / 32 * current_error) + self.error_table[y + 1][x + 2] += int(2 / 32 * current_error) + self.error_table[y + 1][x - 1] += int(4 / 32 * current_error) + self.error_table[y + 1][x - 2] += int(2 / 32 * current_error) if __name__ == "__main__": From 66190e471bb5c83170fa1080ec340dd07eff08fa Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Thu, 30 Apr 2020 11:33:51 +0200 Subject: [PATCH 14/17] Fix variable order in get_greyscale --- digital_image_processing/dithering/burkes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 0d7921f91c77..949c0313a8df 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -40,7 +40,7 @@ def get_greyscale(cls, blue: int, green: int, red: int) -> float: >>> Burkes.get_greyscale(5, 4, 3) 3.753 """ - return 0.2126 * red + 0.587 * green + 0.114 * blue + return 0.114 * blue + 0.587 * green + 0.2126 * red def process(self) -> None: for y in range(self.height): From 823a98fa6e765fca109cf833a392ab43a850775e Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Thu, 30 Apr 2020 11:42:29 +0200 Subject: [PATCH 15/17] Fix get_greyscale method --- digital_image_processing/dithering/burkes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 949c0313a8df..9a1f652009df 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -38,7 +38,7 @@ def __init__(self, input_img, threshold: int): def get_greyscale(cls, blue: int, green: int, red: int) -> float: """ >>> Burkes.get_greyscale(5, 4, 3) - 3.753 + 3.5557999999999996 """ return 0.114 * blue + 0.587 * green + 0.2126 * red From b827c5515a927e2a600ee641716a46f611c8dcbb Mon Sep 17 00:00:00 2001 From: Mateusz Zawadzki Date: Thu, 30 Apr 2020 11:51:14 +0200 Subject: [PATCH 16/17] Fix get_greyscale method --- digital_image_processing/dithering/burkes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 9a1f652009df..a3ba83f006a5 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -38,7 +38,7 @@ def __init__(self, input_img, threshold: int): def get_greyscale(cls, blue: int, green: int, red: int) -> float: """ >>> Burkes.get_greyscale(5, 4, 3) - 3.5557999999999996 + 3.5558 """ return 0.114 * blue + 0.587 * green + 0.2126 * red From 6ce1e16d2bf2dcbc91d410e01b4002b0cc50a664 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 30 Apr 2020 11:53:53 +0200 Subject: [PATCH 17/17] 3.753 --- digital_image_processing/dithering/burkes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index a3ba83f006a5..54a243bd255a 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -37,8 +37,8 @@ def __init__(self, input_img, threshold: int): @classmethod def get_greyscale(cls, blue: int, green: int, red: int) -> float: """ - >>> Burkes.get_greyscale(5, 4, 3) - 3.5558 + >>> Burkes.get_greyscale(3, 4, 5) + 3.753 """ return 0.114 * blue + 0.587 * green + 0.2126 * red