大家好,我有一个我创建的 PGM,并且想逐行读入 python
有没有一种快速简便的方法来做到这一点,因为我想改变每个说紫色像素的 LSB
谢谢
编辑
好的,输入图像是我们大学的PNG文件,
这是我到目前为止的代码:
它需要隐藏文本和图像,图像被转换为 PPM,这就是我陷入困境的地方
我希望能够读取 PPM 图像,并更改紫色的 LSB,最好是图像中的最后一个紫色圆圈
代码:
import Image
import os
import re
import numpy #sudo apt-get install python-numpy #Also need matplotlib
#Text to be hidden within the image
text_to_be_hidden = "test"
#Converts text to binary (NO spaces)
text_to_be_hidden_binary = ''.join(format(ord(x), 'b') for x in text_to_be_hidden)
#User info
print "text to be hidden:", text_to_be_hidden
print "text to be hidden in binary:", text_to_be_hidden_binary
#Converts a png image to pgm
print "Taking image to be inputted, and converting it to ppm"
im = Image.open('Portsmouth.png')
im = im.convert('RGB')
im.save('Portsmouth.ppm')
file_size_of_pgm = os.stat('Portsmouth.ppm').st_size #Gets the file size of the image in byte
#Make sure we have enough space to add the data, if under 5mb ? then close
if file_size_of_pgm < 5000000:
print "PGM file size is too small exiting now"
sys.exit("System exiting")
编辑 2
我现在已经读入数据:
# Open the PPM file and process the 3 first lines (HEADER)
f = open("Portsmouth.ppm")
color = f.readline().splitlines()
size_x, size_y = f.readline().split()
max = f.readline().splitlines()
print color
print size_x
print size_y
print max
data = f.read().split()
print data
我想新的问题是我怎样才能只针对图像中的最后一个圆圈来改变?