在打 VNCTF2022 的时候遇到这样一道题,图片直接放在文章肯能看不清,各位可以点开来仔细观看
放大来看
又是点阵图,这不就是妥妥的点阵提取嘛,打开画图,量出来点之间的距离,然后开造!
结果,出来很意外,每个点之间的距离都是不一样的,都在 49~51 之间浮动,这就导致直接提取不能提取出有效的信息
好在,每一行每一列的点都在同一条直线上,只要求出最左上角的点,然后跑出每一行每一列的坐标,再拼接即可
拼接的话可以使用 OpenCV 库,但是 Python 的 PIL(Pillow)好像更胜一筹,于是学了一下写了个脚本
from PIL import Image,ImageDraw image = Image.open("misc-img-pixel-1.png") Line=[] Row=[] black=image.getpixel((0,0)) for i in range(image.height-1): if(image.getpixel((24,i))!=black): Row.append(i) for i in range(image.width-1): if(image.getpixel((i,15))!=black): Line.append(i) ret = Image.new('RGB', (len(Line), len(Row)) ) draw = ImageDraw.Draw(ret) for x in range(len(Line)-1): for y in range(len(Row)-1): draw.point((x, y), fill=image.getpixel((Line[x],Row[y]))) ret.show() ret.save('result.png')
果然太久没写 python 脚本已经生疏了,php 味 Python 都出来了,得找个时间练一下了
对于 getpixel
效率不高的问题,曹佬给出了他的脚本,用 load 先把图片数组化再进行比较
weight, height = image.size png = image.load() for i in range(height): for j in range(weight): png[i, j] = (0, 0, 0, 0);