-
Notifications
You must be signed in to change notification settings - Fork 0
/
code2.py
69 lines (61 loc) · 2.42 KB
/
code2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#im1 = Image.open('some.jpg') #The image before encoding
#originalImg1 = im1
def encodeImage(im1,im2): #im1 is larger than im2, so store in im1
im1 = im1.convert('RGB')
im2 = im2.convert('RGB')
width1, height1 = im1.size[0], im1.size[1]
width2, height2 = im2.size[0], im2.size[1]
if (width1>=width2) and (height1>=height2):
for y in range(height1):
for x in range(width1):
[r1,g1,b1]=im1.getpixel((x, y))
# print(x,y)
if x<width2 and y<height2:
[r2,g2,b2]=im2.getpixel((x, y))
r = (r1>>4<<4) + (r2>>4)
g = (g1>>4<<4) + (g2>>4)
b = (b1>>4<<4) + (b2>>4)
else:
r = (r1>>4<<4)
g = (g1>>4<<4)
b = (b1>>4<<4)
value = (r,g,b)
im1.putpixel((x, y), value)
# im1.show()
im1.save("decode.jpg")
print("decode.jpg")
return im1
else:
print("Choose a larger first image")
return im1
#im2 = Image.open('download (5).jpg') #loading the smaller img
#im1 = Image.open('drewRobert.png') #Loading the larger img
#encodedImage = encodeImage(im1,im2)
def decodeImage(im,key=0):
im = im.convert('RGB')
width, height = im.size[0], im.size[1]
img1 = Image.new('RGB', (width, height), color = 'white') #THe smaller Image
img2 = Image.new('RGB', (width, height), color = 'white') #THe larger Image
for y in range(height):
for x in range(width):
[r,g,b]=im.getpixel((x, y))
r1,g1,b1 = ((r&15)<<4, (g&15)<<4, (b&15)<<4)
r2,g2,b2 = (r>>4<<4, g>>4<<4, b>>4<<4)
img1.putpixel((x, y), (r1,g1,b1))
img2.putpixel((x, y), (r2,g2,b2))
# if key!=0:
# img2.resize()
# img1.show("The larger Image after decoding")
# img2.show("The smaller Image after decoding")
img2.save("Doggy.png")
return img1,img2
#imma1 = Image.open('decode.jpg')
#im2.show("The smaller image")
#originalImg1.show("Original Image before Encoding")
#encodedImage.show("Encoded Image")
#print(im1.getpixel((100,100)))
#print(im2.getpixel((100,100)))
#print(encodedImage.getpixel((100,100)))
#first,second=decodeImage(encodedImage)
#first.show("The original Image 1 after decoding")
#second.show("The original Image 2 after decoding")