def save_class(): global filename global scaling global outfile global canvas global saveas outfile.set(saveas.get()) p = Pyxelate(1, 1, color.get(), 1, 1, 0) image = io.imread(filename) height, width, _ = image.shape p.height = height // factor.get() p.width = width // factor.get() pyxelated = p.convert(image) if scaling > 1: pyxelated = transform.resize(pyxelated, ((height // factor.get()) * scaling, (width // factor.get()) * scaling), anti_aliasing=False, mode='edge', preserve_range=True, order=0) io.imsave(outfile.get(), pyxelated.astype(uint8)) fimg3 = Image.open(outfile.get()) fimg2 = fimg3.resize((300, 300), resample=0) fimg = ImageTk.PhotoImage(fimg2) canvas.create_image(20, 20, anchor=tk.NW, image=fimg) canvas.image = fimg canvas.pack(pady=3) fn = tk.Label(root, text="Saved to " + outfile.get()) fn.pack(pady=3)
def continue_processing(update): text = update.message.text chat_id = update.message.chat.id if not update.message.photo: return file_id = update.message.photo[-1].file_id image_str = bot.get_file(file_id).download_as_bytearray() nparr = np.frombuffer(image_str, np.uint8) img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR) height, width, _ = img_np.shape try: factor, backscale, colors = text.split(":") factor = int(factor) backscale = int(backscale) colors = int(colors) except: factor = max(1, max(height, width) // 320) backscale = 1 colors = 8 dither = True bot.sendMessage(chat_id=chat_id, text="got it, working... (up to 4 min)") p = Pyxelate(height // factor, width // factor, colors, dither) img_small = p.convert(img_np) # convert an image with these settings if backscale > 1: img_small = cv2.resize( img_small, (img_small.shape[1] * backscale, img_small.shape[0] * backscale) ) img_back_bytes = cv2.imencode(".jpg", img_small)[1].tostring() bot.send_photo(chat_id=chat_id, photo=BytesIO(img_back_bytes))
def get_class(): global filename global outfile img = io.imread(filename) height, width, _ = img.shape p = Pyxelate(height // factor.get(), width // factor.get(), color.get(), 0) img_small = p.convert(img) _, axes = plt.subplots(1, 2, figsize=(16, 16)) axes[0].imshow(img) axes[1].imshow(img_small) plt.show()
def main(): img = io.imread(fname_label) height, width, _ = img.shape factor = 14 colors = colors_label_format dither = True p = Pyxelate(height // factor, width // factor, colors, dither) img_small = p.convert(img) _, axes = plt.subplots(1, 2, figsize=(16, 16)) axes[0].imshow(img) axes[1].imshow(img_small) # i.savefig("res.jpg") plt.show()
def pixelArtModule(img): height, width, _ = img.shape factor = 4 colors = 32 dither = True p = Pyxelate(height // factor, width // factor, colors, dither) pyxelate_Image = p.convert(img) #resize image pyxelate_Image = cv2.resize(pyxelate_Image, (width, height), interpolation=cv2.INTER_AREA) return pyxelate_Image
print("Writing files to " + dim(o_path + '/') + o_base) else: print("Reading files from " + str(output_dir)) if "/" in str(input_dir): i_path, i_base = str(input_dir).rsplit('/', 1) print("Reading files from " + dim(i_path + '/') + i_base) else: print("Reading files from " + dim(str(Path.cwd())) + "/" + str(input_dir)) # Height and width are getting set per image, this are just placeholders p = Pyxelate(1, 1, color=args.colors, dither=args.dither, alpha=args.alpha, regenerate_palette=args.regenerate_palette, random_state=args.random_state) # Loop over all images in the directory for image_file in image_files: # Get the path, file name, and extension base = str(image_file.stem) + ".png" outfile = output_dir / base f_path, f_name, f_ext = parse_path(image_file) # Get the time of the last iteration to calculate the remaining if 'img_end' in globals(): if len(time_img) == avg_last_vals: del time_img[0]
else: print(s['red'](len(IMAGE_FILES)) + " relevant files found") sys.exit(1) # Display output path if "/" in str(OUTPUT_DIR): O_PATH, O_BASE = str(OUTPUT_DIR).rsplit('/', 1) print("Writing files to " + s['dim'](O_PATH + '/') + O_BASE) else: print("Writing files to " + str(OUTPUT_DIR)) # Setup Pyxelate with placeholder dimensions 1x1 p = Pyxelate(1, 1, color=args.colors, dither=args.dither, alpha=args.alpha, regenerate_palette=args.regenerate_palette, random_state=args.random_state) # Prepare images to convert sequence if args.sequence: SEQUENCE = [io.imread(file) for file in IMAGE_FILES] SEQ_IMAGE = p.convert_sequence(SEQUENCE) HEIGHT, WIDTH, _ = io.imread(IMAGE_FILES[0]).shape p.height = HEIGHT // args.factor p.width = WIDTH // args.factor for i, image_file in enumerate(IMAGE_FILES): # Make a time stamp to calculate remaining if i or not args.sequence: