-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagrandir.py
48 lines (44 loc) · 1.65 KB
/
agrandir.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
# -*- coding: utf-8 -*-
from PIL import Image
def add_seam_image(im,seam):
'''
'''
image = im.load()
im2 = Image.new('RGB', (im.size[0]+1, im.size[1]))
image2 = im2.load()
for elm in seam:
#print (elm)
for x in range(elm[0]+1):
image2[x, elm[1]] = image[x,elm[1]]
if (elm[0] == (im.size[0]-1)):
r1, g1, b1 = image[elm[0], elm[1]]
r2, g2, b2 = image[elm[0]-1, elm[1]]
image2[elm[0]+1, elm[1]] = (r1+r2)//2, (g1+g2)//2, (b1+b2)//2
else:
r1, g1, b1 = image[elm[0], elm[1]]
r2, g2, b2 = image[elm[0]+1, elm[1]]
image2[elm[0]+1, elm[1]] = (r1+r2)//2, (g1+g2)//2, (b1+b2)//2
for x in range(elm[0]+1, im.size[0]):
image2[x+1, elm[1]] = image[x, elm[1]]
return im2 #l'image modifiée est retournée
def add_seam_gradient(im,seam):
'''
'''
image = im.load()
im2 = Image.new('L', (im.size[0]+1, im.size[1]))
image2 = im2.load()
for elm in seam:
for x in range(elm[0]):
image2[x, elm[1]] = image[x,elm[1]]
image2[elm[0], elm[1]] = 255
if (elm[0] == (im.size[0]-1)):
x1 = image[elm[0], elm[1]]
x2 = image[elm[0]-1, elm[1]]
image2[elm[0]+1, elm[1]] = ((x1+x2)//2, )
else:
x1 = image[elm[0], elm[1]]
x2 = image[elm[0]+1, elm[1]]
image2[elm[0]+1, elm[1]] = ((x1+x2)//2, )
for x in range(elm[0]+1, im.size[0]):
image2[x+1, elm[1]] = image[x, elm[1]]
return im2 #l'image modifiée est retournée