在python中更改PPM文件

时间:2014-10-01 15:52:09

标签: python steganography pgm

大家好我有一个我创建的PGM,并想逐行读入python

有一种快速简便的方法可以做到这一点,因为我想改变每个说紫色像素的LSB

谢谢

修改

好的,输入图片是我们大学的PNG文件,

enter image description here

这是我到目前为止的代码:

它会隐藏文本以及图像,图像会转换为PPM,这就是我被卡住的地方

我希望能够读取PPM图像,并更改紫色的LSB,理想情况下是图像中的最后一个紫色圆圈

CODE:

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

我认为新问题是我如何才能仅定位图像中的最后一个圆圈?

0 个答案:

没有答案