You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
747 B
29 lines
747 B
4 years ago
|
import numpy as np
|
||
|
import scipy.misc as smp
|
||
4 years ago
|
from PIL import Image
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
bit_on = [191, 191, 191] # RGB value if bit is 1
|
||
|
bit_off = [17, 16, 21] # RGB value if bit is 0
|
||
4 years ago
|
|
||
|
def translate_bit_color(bit:str):
|
||
|
if( bit == "1" ):
|
||
|
return bit_on
|
||
|
else:
|
||
|
return bit_off
|
||
|
|
||
|
def data_to_matrix(data:list) -> np.array:
|
||
|
newdat = [ [translate_bit_color(bit) for bit in byte] for byte in data ]
|
||
|
col_array = np.array(newdat, dtype=np.uint8)
|
||
|
|
||
|
return col_array
|
||
|
|
||
4 years ago
|
def generate(inp:list) -> None:
|
||
4 years ago
|
print("Converting data to matrix...")
|
||
4 years ago
|
col_array = data_to_matrix(inp)
|
||
|
|
||
4 years ago
|
print("Generating image...")
|
||
4 years ago
|
img = Image.fromarray(col_array, "RGB")
|
||
|
img.save("ascii_bin-image.jpg")
|
||
4 years ago
|
print("Generated image \"ascii_bin-image.jpg\"")
|