-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.py
37 lines (28 loc) · 1.08 KB
/
11.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
#!/usr/bin/python
# Problem - http://www.pythonchallenge.com/pc/return/5808.html
# Thought process -
# 1. by seeing the image itself we can say that the image is combination of two or more images
# 2. Its a classical problem of steganography
# 3. title says "odd even" means odd row consists of one image and even the other.
# 4. but image pixels are collection of two coordinate points
# 5. add both the coordinates, if the sum is divisible by 2 add pixel to even and if not add pixel to odd
# Solution - http://www.pythonchallenge.com/pc/return/evil.html
from PIL import Image
im = Image.open("cave.jpg")
pix = im.load()
newImEven = Image.new("RGB", (im.size[0]/2, im.size[1]/2))
even = newImEven.load()
newImOdd = Image.new("RGB", (im.size[0]/2, im.size[1]/2))
odd = newImOdd.load()
for x in range(0, im.size[0]):
for y in range(0, im.size[1]):
sum = x + y
if(sum % 2 == 0):
even[x/2, y/2] = pix[x, y]
else:
odd[x/2, y/2] = pix[x, y]
newImEven.save("even.jpg", "JPEG")
newImOdd.save("odd.jpg", "JPEG")
Image.open("even.jpg").show()
Image.open("odd.jpg").show()
# evil in even.jpg