image - jpeg同心像素块的解扰旋转
问题描述
作为“夺旗”挑战的一部分,附加的 jpg 被打乱以掩盖内容。图像(“flagpoles.jpg”)为 1600 x 1600 像素。同心线似乎具有 10 像素宽的块大小。(它类似于弗兰克斯特拉的画作)。看起来原始图像已被分成四个部分,围绕中心对称排列。我一直在尝试编写一个 python 脚本来处理像素并解读同心方块。我的努力导致了两种无用的反复出现的情况,要么没有变化,要么更加混乱。我认为这可能是因为我正在处理整个图像,并且尝试解读其中的一部分可能会更好。这是我的代码。目前它只处理一半的像素,因为我试图将图片的各个部分相互匹配。我尝试将块发送到图像的另一侧以尝试匹配它们,但没有任何改进。我们将不胜感激地收到任何有助于获得清晰图片的帮助。
from PIL import Image
import math
im = Image.open("flagpoles.jpg", "r")
pic = im.load()
def rot(A, r, x1, y1):
myArray = []
for i in range(r):
myArray.append([])
for j in range(r):
myArray[i].append(pic[x1+i, y1+j])
for i in range(r):
for j in range(r):
pic[x1+i,y1+j] = myArray[r-1-i][r-1-j]
xres = 800
yres = 800
blocksize = 10
for i in range(blocksize, blocksize+1):
for j in range(int(math.floor(float(xres)/float(blocksize+2+i)))):
for k in range(int(math.floor(float(yres)/float(blocksize+2+i)))):
rot(pic, blocksize+2+i, j*(blocksize+2+i), k*(blocksize+2+i))
im.save("hopeful.png")
print("Finished!")
解决方案
该图像似乎由宽度为 10 像素的同心方形框组成,每个框都相对于前一个旋转了 90°。每四次旋转后,像素再次以相同方向定向。
您可以通过制作图像副本并重复旋转 270°,同时裁剪掉 10 px 边框来轻松撤消此操作。将这些旋转的图像粘贴回相应的位置以检索原始图像。
from PIL import Image
step_size = 10
angle_step = 270
img = Image.open("flagpoles.jpg", "r")
img.load()
w = img.width
assert img.height == w
img_tmp = img.copy() # Copy of the image that we're going to rotate
offset = 0 # Coordinate where the rotated images should be pasted
cropmax = w - step_size # Maximum coordinate of cropping region
while cropmax > step_size:
# Rotate the copy of the image
img_tmp = img_tmp.rotate(angle_step)
# Paste it into the original image
img.paste(img_tmp, (offset,offset))
# Crop a 10 px border away from the copy
img_tmp = img_tmp.crop((step_size, step_size, cropmax, cropmax))
# Update the crop position and width for the next iteration
cropmax -= step_size * 2
offset += step_size
img.save("fixed.jpg")
推荐阅读
- javascript - 我们如何使用javascript根据表格中的第一行元素动态添加行?
- java - 如何从 Web 中提取 Microsoft Power BI 数据
- database - 为什么 SERM (ERM) 建模中关系类型的主键 (PK) 需要继承类型?
- python - pytest - 模拟配置[
] 通过 configparser.ConfigParser() / config.read() - mysql - 为什么 NOT NULL DEFAULT current_timestamp() 在创建此表时会给出错误 Invalid default value?
- api - 如何在 laravel 8 api 中使用外键获取、插入和更新数据
- c# - 比较一系列两个变量的最简洁方法?
- javascript - Object.defineProperty 不更改键顺序
- c# - 在 .NET 5 中,有没有办法提前将代码编译成二进制文件并仅剥离 IL(而不是反射数据)?
- javascript - Javascript:如何通过触摸选择文本并防止拖动屏幕