import sys

if 1 < len(sys.argv) < 4:
    pass
else:
    print("ERROR: Invalid number of arguments.")

import scipy
import scipy.misc 
import matplotlib.pyplot as plot

inFile = sys.argv[1]
pos = inFile.index('/')+1
outFile = inFile[:pos]+'i'+inFile[pos:]
print(outFile)

img = scipy.misc.imread(inFile)

print(img.shape, img.dtype)

def contrast(x):
    y = 127 - x
    if not abs(y) > 60:
        x -= y
    return x

def strange(x):
    b = 127-x
    if b < 0:
        return -b
    else:
        return 255-b
    

fn = scipy.vectorize(strange)

scipy.misc.imsave(outFile, fn(img))


@@ -187,33 +187,142 @@
 %5B1%5D%0A
-pos = inFile.index('/')+1
+done = False%0Apos = 0%0A%0Awhile not done:%0A    try:%0A        pos += inFile%5Bpos:%5D.index('/')+1%0A    except (ValueError):%0A        done = True%0A%0A
 %0Aout
@@ -342,17 +342,17 @@
 %5B:pos%5D+'
-i
+b
 '+inFile
@@ -465,23 +465,24 @@
 y = 
-127 - x
+ x - 127
 %0A    if 
 not 
@@ -481,20 +481,16 @@
  if 
-not 
 abs(y) 
-%3E
+%3C
  60:
@@ -500,17 +500,17 @@
       x 
--
++
 = y%0A    
@@ -547,13 +547,13 @@
 b = 
+x-
 127
--x
 %0A   
@@ -558,17 +558,17 @@
    if b 
-%3C
+%3E
  0:%0A    
@@ -578,17 +578,16 @@
  return 
--
 b%0A    el
@@ -612,17 +612,14 @@
  255
--b%0A    %0A%0A
++b%0A%0A# 
 fn =
@@ -645,16 +645,18 @@
 range)%0A%0A
+# 
 scipy.mi
@@ -684,8 +684,46 @@
 (img))%0A%0A
+scipy.misc.imsave(outFile, 255-img)%0A%0A%0A

clean up