Code: Select all
import Image
def max_num(x):
for i in x:
if i != max(x):
x[x.index(i)] = 0
return x
def min_num(x):
for i in x:
if i != min(x):
x[x.index(i)] = 0
return x
im = Image.open('1.jpg')
width, height = im.size
pix = im.load()
for h in range(height):
for w in range(width):
tup_old = pix[w, h]
L = list(tup_old)
LN = max_num(L)
tup_new = tuple(LN)
pix[w, h] = tup_new
print w, h
im.save('1.jpg')
if I chose from the command line : min_num, then we would have LN = min_num(L)
if if max_num is chosen then LN = max_num(L)
any suggestion ?