-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1.py
60 lines (42 loc) · 1.46 KB
/
project1.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
#Sergio Llopis Donate
#Project 1
#02/07/2017
#CST 205
#github link: https://github.com/sllopis
from PIL import Image
#GETTING THE MEDIAN + SORTING FUNCTION
def medianoper(myList):
# Store list length in the variable listLength
listLength = len(myList)
# Sort the list
sortedValues = sorted(myList)
# Location of middle value. Subtract one because of zero index
middleIndex = (listLength + 1)/2 - 1
# Return the object located at that index
return sortedValues[middleIndex]
#Array for adding images to the List + Opening the images
imgList = []
for i in range(1,10):
imgList.append(Image.open("otherimages/" + str(i) + ".png"))
pictureWidth, pictureHeight = imgList[0].size
#Creating new image blue color
newimg = Image.new("RGB", ((pictureWidth,pictureHeight)), color=None)
#Creating a list for the colors (9 colors)
redpx = []
greenpx = []
bluepx= []
for x in range(0, pictureWidth - 1):
for y in range(0, pictureHeight - 1):
for myImage in imgList:
myred, mygreen, myblue = myImage.getpixel((x,y))
redpx.append(myred)
greenpx.append(mygreen)
bluepx.append(myblue)
myred = medianoper(redpx)
mygreen = medianoper(greenpx)
myblue = medianoper(bluepx)
newimg.putpixel(((x,y)), ((myred, mygreen, myblue)))
redpx = []
greenpx = []
bluepx = []
newimg.save("canvas.png")