不嘻嘻,没见过这种题,需要把这个红线还原重组成二维码,搜索一个是这个Peano曲线
from PIL import Image from tqdm import tqdm def peano(n): if n == 0: return [[0, 0]] else: in_lst = peano(n - 1) lst = in_lst.copy() px, py = lst[-1] lst.extend([px - i[0], py + 1 + i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px + i[0], py + 1 + i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px + 1 + i[0], py - i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px - i[0], py - 1 - i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px + i[0], py - 1 - i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px + 1 + i[0], py + i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px - i[0], py + 1 + i[1]] for i in in_lst) px, py = lst[-1] lst.extend([px + i[0], py + 1 + i[1]] for i in in_lst) return lst order = peano(6) img = Image.open(r"F:\WeChat Files\wxid_zzy3l6ymu9oh22\FileStorage\File\2024-10\网鼎杯\misc4\1.png") width, height = img.size block_width = width # // 3 block_height = height # // 3 new_image = Image.new("RGB", (width, height)) for i, (x, y) in tqdm(enumerate(order)): # 根据列表顺序获取新的坐标 new_x, new_y = i % width, i // width # 获取原图像素 pixel = img.getpixel((x, height - 1 - y)) # 在新图像中放置像素 new_image.putpixel((new_x, new_y), pixel) new_image.save("rearranged_image.jpg")
以后多积累点图片的脚本吧,不嘻嘻