Make pixel_bin_rep a string with literals

That way we don't have to call str() on pixel_bin_rep when adding bits, as literal constructions are faster than function calls iirc.
This commit is contained in:
Theelgirl 2020-10-08 13:59:24 +00:00 committed by GitHub
parent 832effad59
commit 83084dc456
1 changed files with 6 additions and 6 deletions

View File

@ -58,13 +58,13 @@ def get_bits_from_image(image):
pixel = px[x, y] pixel = px[x, y]
pixel_bin_rep = 0 pixel_bin_rep = "0"
# for exact matches # for exact matches
if pixel == white: if pixel == white:
pixel_bin_rep = 1 pixel_bin_rep = "1"
elif pixel == black: elif pixel == black:
pixel_bin_rep = 0 pixel_bin_rep = "0"
else: else:
white_diff = tuple(np.absolute(np.subtract(white, pixel))) white_diff = tuple(np.absolute(np.subtract(white, pixel)))
# min_diff = white_diff # min_diff = white_diff
@ -73,12 +73,12 @@ def get_bits_from_image(image):
# if the white difference is smaller, that means the pixel is closer # if the white difference is smaller, that means the pixel is closer
# to white, otherwise, the pixel must be black # to white, otherwise, the pixel must be black
if np.less(white_diff, black_diff).all(): if np.less(white_diff, black_diff).all():
pixel_bin_rep = 1 pixel_bin_rep = "1"
else: else:
pixel_bin_rep = 0 pixel_bin_rep = "0"
# adding bits # adding bits
bits += str(pixel_bin_rep) bits += pixel_bin_rep
return (bits, done) return (bits, done)