forked from BhargavGamit/ImageManipulationAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolarisationAlgo.py
51 lines (46 loc) · 1.37 KB
/
SolarisationAlgo.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
# Author Sri Vennela Vaishnapu
# Email [email protected]
# Solarisation algorithm
# colour = GetPixelColour(x, y)
# If Red(colour) < threshold
# solariseRed = 255 - Red(colour)
# Else
# solariseRed = Red(colour)
# EndIf
# If Green(colour) < threshold
# solariseGreen = 255 - Green(colour)
# Else
# solariseGreen = Green(colour)
# EndIf
# If Blue(colour) < threshold
# solariseBlue = 255 - Blue(colour)
# Else
# solariseBlue = Blue(colour)
# EndIf
# PutPixelColour(x, y) = RGB(solariseRed, solariseGreen, solariseGreen)
from PIL import Image
i = Image.open("input.png")
#pixel data is stored in pixels in form of two dimensional array
pixels = i.load()
width, height = i.size
j=Image.new(i.mode,i.size)
threshold=128
for x in range(width):
for y in range(height):
cpixel = pixels[x, y]
#cpixel[0] contains red value cpixel[1] contains green value
#cpixel[2] contains blue value cpixel[3] contains alpha value
if(cpixel[0]<threshold):
solariseRed = 255 - cpixel[0]
else:
solariseRed = cpixel[0]
if(cpixel[1]<threshold):
solariseGreen = 255 - cpixel[1]
else:
solariseGreen = cpixel[1]
if(cpixel[2]<threshold):
solariseBlue = 255 - cpixel[2]
else:
solariseBlue = cpixel[2]
j.putpixel((x,y),(solariseRed,solariseBlue,solariseGreen))
j.save('output.png')