Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

Example picture in which I will encode my message

I converted that image into pixels : Picture to pixels

after modifying a few pixels so I can hide my message in the last digit of pixels: Modified Pixels

I used assembly to modify very few pixels

Converting modified pixels into a picture: Converting modified pixels to 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:

Changing back to pixels so I can decode the message from 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 :(


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
181 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...