1. #! /usr/bin/python
  2. import Image
  3.  
  4. #Created by vvdr12
  5. #Fully open license.  Have fun.
  6. #change threshold value in 'def contrastspoints' for higher/lower line density.
  7. #put a 'test.jpg' file in the same folder as the code.
  8.  
  9. #_functions______________________________________________
  10.  
  11. def contrastpoints(x,j,img):
  12.     threshold=26
  13.     contrast=[]
  14.     i=0
  15.     l2=1
  16.     while l2==1:
  17.            
  18.         r1=img[i,j][0]
  19.         b1=img[i,j][1]
  20.         g1=img[i,j][2]
  21.         ave1=((r1+b1+g1)/3)
  22.  
  23.         r2=img[(i+1),j][0]
  24.         b2=img[(i+1),j][1]
  25.         g2=img[(i+1),j][2]
  26.         ave2=((r2+b2+g2)/3)
  27.        
  28.         r3=img[(i+2),j][0]
  29.         b3=img[(i+2),j][1]
  30.         g3=img[(i+2),j][2]
  31.         ave3=((r3+b3+g3)/3)
  32.        
  33.         r4=img[(i+3),j][0]
  34.         b4=img[(i+3),j][1]
  35.         g4=img[(i+3),j][2]
  36.         ave4=((r4+b4+g4)/3)
  37.  
  38.         if abs(ave2-ave1)>threshold:
  39.             if abs(ave1-ave3)>(threshold/2):
  40.                 contrast.append(i)
  41.  
  42.         i=i+1      
  43.         if i==(x-3):
  44.             l2=0
  45.     return contrast
  46.  
  47. #_Page_Setup____________________________________________
  48.  
  49. # Asks for the file path
  50. f = raw_input("Please enter your file's full path: ")
  51. source = Image.open(f, 'r')
  52. img = source.load()
  53. print source.format
  54. print source.size
  55. print source.mode
  56.  
  57. x = source.size[0]
  58. y = source.size[1]
  59.  
  60.  
  61.  
  62. #_______________________________________________________
  63.  
  64.  
  65. i=0
  66. j=0#set to 500 for short test run
  67. k=0
  68. l=0
  69. m=0 #contrast func
  70. l1=1
  71. contrast=contrastpoints(x,j,img) #contrast func
  72. print "\n", j, "/", y
  73. while (l1==1):
  74.    
  75.     if len(contrast)>m: #contrast func
  76.         if i>=contrast[m]:
  77.             img[i,j]=(0,0,0)
  78.             m=m+1
  79.    
  80.     i=i+1
  81.     if i==(x-1):
  82.         contrast=contrastpoints(x,j,img) #contrast func
  83.         m=0 #contrast func
  84.         i=0
  85.  
  86.         k=k+1
  87.         if k==1:
  88.             k=0
  89.  
  90.             j=j+1
  91.             print j, "/",y     
  92.             if j==y: #set to 510 for short test run
  93.                 l1=0
  94.            
  95.  
  96.    
  97. source.save("japanify.png")