forked from bornreddy/smart-thresholds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_threshold.py
42 lines (35 loc) · 835 Bytes
/
basic_threshold.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
from PIL import Image
import sys, os
'''
try:
img = Image.open(sys.argv[1])
img.load()
img.show()
bw = img.convert('L')
except IOError:
print "Unable to open file. Please try another format."
threshold = raw_input("Choose threshold value: ")
intensity_array = []
for w in range(0,bw.size[1]):
for h in range(0,bw.size[0]):
intensity = bw.getpixel((h,w))
if (intensity <= int(threshold)):
x = 0
else:
x = 255
intensity_array.append(x)
bw.putdata(intensity_array)
bw.show()
'''
def threshold(t, image):
intensity_array = []
for w in range(0,image.size[1]):
for h in range(0,image.size[0]):
intensity = image.getpixel((h,w))
if (intensity <= t):
x = 0
else:
x = 255
intensity_array.append(x)
image.putdata(intensity_array)
image.show()