Advertisement
Guest User

newfile.py

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. import numpy as np
  2. import imageio as io
  3. import PIL.Image as im
  4.  
  5.  
  6. def blur(arr, n):
  7.     ret = np.copy(arr)
  8.     height=arr.shape[0]
  9.     width =arr.shape[1]
  10.     for y in range(0,height):
  11.         for x in range(0,width):
  12.             rect = arr[max(0,y-n):min(y+n+1,height) , max(0,x-n):min(x+n+1,width) , :]
  13.             ret[y,x,:]=np.mean(rect,(0,1))
  14.     return ret
  15.  
  16.      
  17. def edge (arr):
  18.     ret = np.copy(arr)
  19.     ret[0,0,:]=0
  20.     width = arr.shape[1]
  21.     height=arr.shape[0]
  22.     for y in range(0,height):
  23.         print(y*100/height,'%')
  24.         for x in range(0,width):
  25.             if(x==0 and y==0):
  26.                 continue
  27.             rect = arr[max(0,y-1):y+1, max(0,x-1): x+1, :]
  28.             rect = rect.ravel()
  29.             rect=rect.reshape((rect.size//3,3))
  30.             right=rect[-1].ravel()
  31.             left=rect[:-1]
  32.             ed=abs(right-left)
  33.             #print(ed)
  34.             '''if(x==1 and y==0):
  35.                 print('ed: ' ,ed)
  36.                 print('left: ',left)
  37.                 print('right: ',right)
  38.                 print('left-right: ',left-right)
  39.                 print('mean: ',np.mean(ed,0))'''
  40.             ret[y,x]=np.mean(ed,0)
  41.     return np.round(ret)
  42.  
  43.  
  44. def blackwhite(arr):
  45.     return np.mean(arr,2)
  46.  
  47.  
  48. def blur1(arr,n):
  49.     ret=np.copy(arr)
  50.     width = arr.shape[1]
  51.     height=arr.shape[0]
  52.     weight=0
  53.     for y in range(0,height):
  54.         for x in range(0,width):
  55.             if(x==0 and y==0):
  56.                 rect = arr[0:min(height,y+n+1),0:min(width,x+n+1),:]
  57.                 weight= rect.size//3
  58.  
  59.  
  60.  
  61.  
  62. lizt =np.array([   [[233,23,28],[123,234,67],[43,178,209]],
  63.                             [[21,90,123] , [12,65,86]   ,   [3,87,176]] ,
  64.                             [[23,34,17]   , [23,46,19]   , [129,36,29]]   ],dtype=np.float32)
  65.  
  66.  
  67.  
  68. img=np.asarray(io.imread("chess.jpg"))
  69. img =img[:,:,:3];
  70. img[:,:,(1)]=0
  71. #img = img[200:205,200:205,:3]
  72. #print(img)
  73. io.imwrite('r.png',img)
  74. #print(np.mean(lizt,2))
  75. #print(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement