def get_image(self): env = np.zeros((self.SIZE, self.SIZE, 3), dtype=np.uint8) # starts an rbg of our size env[self.food.x][self.food.y] = self.d[ self.FOOD_N] # sets the food location tile to green color env[self.enemy.x][self.enemy.y] = self.d[ self.ENEMY_N] # sets the enemy location to red env[self.player.x][self.player.y] = self.d[ self.PLAYER_N] # sets the player tile to blue img = Image.fromarray( env, 'RGB' ) # reading to rgb. Apparently. Even tho color definitions are bgr. ??? return img
def decrypt(): # load the image and convert it into a numpy array and display on the GUI. load = Image.open("Syngenta.jpg") load.thumbnail(image_display_size, Image.ANTIALIAS) load = np.asarray(load) load = Image.fromarray(np.uint8(load)) render = ImageTk.PhotoImage(load) img = Label(app, image=render) img.image = render img.place(x=100, y=50) # Algorithm to decrypt the data from the image img = cv2.imread("Syngenta.jpg") data = [] stop = False for index_i, i in enumerate(img): i.tolist() for index_j, j in enumerate(i): if ((index_j) % 3 == 2): # first pixel data.append(bin(j[0])[-1]) # second pixel data.append(bin(j[1])[-1]) # third pixel if (bin(j[2])[-1] == '1'): stop = True break else: # first pixel data.append(bin(j[0])[-1]) # second pixel data.append(bin(j[1])[-1]) # third pixel data.append(bin(j[2])[-1]) if (stop): break message = [] # join all the bits to form letters (ASCII Representation) for i in range(int((len(data) + 1) / 8)): message.append(data[i * 8:(i * 8 + 8)]) # join all the letters to form the message. message = [chr(int(''.join(i), 2)) for i in message] message = ''.join(message) message_label = Label(app, text=message, bg='lavender', font=("Times New Roman", 10)) message_label.place(x=30, y=400)
import os import numpy as np from pil import Image fname = 'galaga_sprite_sheet.png' image_dir = 'images' sprite_sheet = Image.open(os.path.join(image_dir, fname)) im_data = np.array(sprite_sheet) assert im_data.shape == (383, 424, 3) # Extract data for each sprite from sprite sheet sprites = [] for yi in range(12): y = 55 + yi * 24 for xi in range(8): x = 16 + xi * 24 sprite = im_data[y:y + 16, x:x + 16, :] sprites.append(sprite) # Add a border and save as individual files for i, sprite in enumerate(sprites): img_data = np.zeros((19, 19, 3), dtype='uint8') img_data[2:18, 2:18, :] = sprite img = Image.fromarray(img_data) if sprite.sum() > 0: img.save(os.path.join(image_dir, f'galaga_{i:02d}.png'))
def CenterExtend(im, width=400, height=88, radius=20): x1 = np.full((height+radius+radius, width+radius+radius), 255, dtype='uint8') x2 = np.asarray(im.convert('L')) x1[radius:radius+height,radius:radius+width] = x2 return Image.fromarray(x1, 'L')