4x speed of 2 bottleneck lines by removing numpy

Also double the speed of one more bottleneck line by removing numpy. tuple(map()) is amazing!
This commit is contained in:
Theelgirl 2020-10-09 16:45:14 +00:00 committed by GitHub
parent b9eee98a25
commit 018c86711f
1 changed files with 4 additions and 3 deletions

View File

@ -66,13 +66,14 @@ def get_bits_from_image(image):
elif pixel == black:
pixel_bin_rep = "0"
else:
white_diff = np.absolute(np.subtract(white, pixel))
white_diff = tuple(map(abs, map(sub, white, pixel)))
# min_diff = white_diff
black_diff = np.absolute(np.subtract(black, pixel))
black_diff = tuple(map(abs, map(sub, black, pixel)))
# if the white difference is smaller, that means the pixel is closer
# to white, otherwise, the pixel must be black
if np.less(white_diff, black_diff).all():
if all(map(less, white_diff, black_diff)):
pixel_bin_rep = "1"
else:
pixel_bin_rep = "0"