Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/EE/pixelQR/ImageDecoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ def resize_and_colour_correct(img):
# return output_msg.decode("utf-8")


def photo_to_str(img_path):
def photo_to_str(im):
"""Converts photo to string

Parameters
----------
img_path : str
Input image path of Datastamp you wish to decode
img : Image
Input image of Datastamp you wish to decode
(NOTE, code must have a white background).

Returns
Expand All @@ -391,11 +391,10 @@ def photo_to_str(img_path):
Outputs data decoded from Datastamp.

"""
with Image.open(img_path) as im:
imgsize = im.size
imgsize = im.size

img = im.resize(
(math.floor(0.25*imgsize[0]), math.floor(0.25*imgsize[1])), 1)
img = im.resize(
(math.floor(0.25*imgsize[0]), math.floor(0.25*imgsize[1])), 1)

img = centre_and_crop_img(img)
img = resize_and_colour_correct(img)
Expand Down
37 changes: 18 additions & 19 deletions src/EE/pixelQR/ImageEncoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image, ImageOps


def str_to_image(secret_str: str, out_path: str, img_size: tuple = (32, 32)):
def str_to_image(secret_str: str, img_size: tuple = (32, 32)):
"""Converts input string to Datastamp

Parameters
Expand All @@ -30,21 +30,20 @@ def str_to_image(secret_str: str, out_path: str, img_size: tuple = (32, 32)):

"""
collist = str_to_colour_list2(secret_str)
colour_list_to_image(collist, img_size, out_path)
with Image.open(out_path) as im:
new_image = Image.new("RGB", (33, 34))
new_image.paste(im, (1, 1))
# The "new_image" variable is used to form the black C shape
# The black C shape is used for orientation purposes
w_background = Image.new("L", (35, 36))
w_background = ImageOps.colorize(
w_background, (255, 255, 255), (255, 255, 255))
w_background.paste(new_image, (1, 1))
# The white background is necessary for the datastamp to successfully
# be scanned
new_image = w_background.resize((1000, 1000), 0)
new_image.save(out_path)
return out_path
im = colour_list_to_image(collist, img_size)
new_image = Image.new("RGB", (33, 34))
new_image.paste(im, (1, 1))
# The "new_image" variable is used to form the black C shape
# The black C shape is used for orientation purposes
w_background = Image.new("L", (35, 36))
w_background = ImageOps.colorize(
w_background, (255, 255, 255), (255, 255, 255))
w_background.paste(new_image, (1, 1))
# The white background is necessary for the datastamp to successfully
# be scanned
new_image = w_background.resize((1000, 1000), 0)
# new_image.save(out_path)
return new_image


def baseconvert2(num: int, base: int) -> str:
Expand Down Expand Up @@ -134,7 +133,7 @@ def str_to_colour_list2(SecretMsg: str):
return colour_list


def colour_list_to_image(colour_list: list, image_size: tuple, out_path: str):
def colour_list_to_image(colour_list: list, image_size: tuple):
"""Converts list of colours into the encoding portion of Datastamp

Parameters
Expand Down Expand Up @@ -201,12 +200,12 @@ def colour_list_to_image(colour_list: list, image_size: tuple, out_path: str):
pixel_num = pixel_num + 1
background2.alpha_composite(background, (0, 0))
background2.alpha_composite(new_image, (0, 0))
background2.save(out_path)
return background2


if __name__ == "__main__":
input_str = input(
"Please input the message you would like to encode in image \n")
output_path = input("Please input the output path of the encoded file \n")
str_to_image(input_str, output_path)
print("done!")
print(output_path)