I am working on a program where I change the last digits(1-2 difference) of a few pixels so I can hide my bit code in the last digit. Now, the problem occurs when I try to change my modified Numpy array list into a picture and then convert it back to text file of Numpy pixels that are getting changed to its original pixels.
here is the code for converting the pixels into an image:
from PIL import Image
import numpy as np
import cv2
openFile = open('output.txt')
readingline = openFile.readlines()
w, h = int(readingline[0]), int(readingline[1])
print(w,h)
ab = readingline[2:]
realList = []
for i in range(len(ab)):
realList.append(int(ab[i].strip('
')))
ar = np.array(realList)
ab = ar.reshape(w,h,3)
print(ab)
cv2.imwrite("updated.jpg",ab)
code for converting image into pixels:
from PIL import Image
import numpy
def giveArrayOfImage(img):
empty=[]
pic = Image.open(img)
width ,height = pic.size
res=[width,height]
empty.append(res)
pixel = numpy.asarray(pic)
for i in range(len(pixel)):
for j in range(len(pixel[0])):
empty.append(pixel[i][j])
return empty
oneDArray = giveArrayOfImage("updated.jpg")
md = open('nt.txt','a')
for i in range(len(oneDArray)):
for j in range(len(oneDArray[i])):
md.write(str(oneDArray[i][j])+'
')
md.close()
here is the example:
I converted that image into pixels :
after modifying a few pixels so I can hide my message in the last digit of pixels:
I used assembly to modify very few pixels
Converting modified pixels into a picture:
Now when I am converting this image into pixels to decode the message it is not giving me the same pixels that I modified program is changing them back to original pixels:
**nt.txt is generated by modified image **
I don't know what is the problem. Sorry for the bad English, but I hope you guys get where I am stuck :(