0

Hi guys i have a PGM i have created, and would like to read in to python line by line

is there a quick and easy way to do this, as i want to alter the LSB for each say purple pixel there is

Thanks

Edit

Ok guys the input image is a PNG file, of our university,

enter image description here

This is the code i have so far:

it takes the text to be hidden and also the image, the image gets converted to PPM and this is where i get stuck at

i want to be able to read in the PPM image, and change the LSB of the purple, ideally the last purple circle in the image

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")

EDIT 2

i have now read in the data :

# 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

i suppose the new question is how can i target only the last circle in the image to alter ?

user4017041
  • 113
  • 1
  • 1
  • 8
  • PGM is for Grey scale images. Did you mean PPM? Can you provide a link of a sample to download? – kums Oct 01 '14 at 16:22
  • Yes sorry i did mean PPM, i will update the question with what i have done so far – user4017041 Oct 01 '14 at 16:25
  • Added more detail above – user4017041 Oct 01 '14 at 16:28
  • Try not to change the question too much after posting, because it's unfair to those who have invested in answering an obsolete-by-now question. Considering the format has values for each individual pixel, you want to either manually define the area, or use a pattern recognition algorithm. This is very straightforward manually if this is the only example you're interested in and the colour is the same everywhere in the circle: just define a square around the circle of interest and only choose the pixels with a purple colour. – Reti43 Oct 01 '14 at 16:41
  • Ok sorry, will open a new question up next time :), yes this is the only example i want to encode, how do i select the square around the last (largest) cicle ? – user4017041 Oct 01 '14 at 16:47
  • You can load the image on Paint and get the pixel coordinates (top left and bottom right) of a square encompassing your region of interest. – Reti43 Oct 01 '14 at 16:56
  • Thanks thats a really good idea, will do that – user4017041 Oct 01 '14 at 16:59
  • Is the image initially to loaded from a png or ppm format? I assume you convert it to ppm because that's the output you want to save? If not, why does the conversion take place? – Reti43 Oct 02 '14 at 19:22

0 Answers0