Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. from __future__ import print_function
  2. from sys import argv
  3. import os.path
  4. from copy import deepcopy
  5. import numpy as np
  6. from PIL import Image
  7. def box_filter(src_path=os.getcwd()+'/tst_1.jpg', dst_path=os.getcwd()+'/transf_1.jpg', w=5,h=5):
  8. jpgfile=Image.open(src_path)
  9. img = np.array(jpgfile.getdata()).reshape(jpgfile.size[0],jpgfile.size[1],3)
  10. img=img[:,:,0]
  11. img1= deepcopy(img)
  12. pref=deepcopy(img)
  13. for i in range(1,img.shape[0]):
  14. pref[i,0]=img[1,0]+pref[i-1,0]
  15. for j in range(1,img.shape[1]):
  16. pref[0,j]=img[0,j]+pref[0,j-1]
  17. for i in range(0,img.shape[0]):
  18. for j in range(0,img.shape[1]):
  19. pref[i,j]=pref[i,j-1]+pref[i-1,j]-pref[i-1,j-1]+img[i,j]
  20. for i in range(w,img.shape[0]):
  21. for j in range(h,img.shape[1]):
  22. img1[i,j]=(pref[i, j] - pref[i - w, j] - pref[i, j - h] + pref[i - w, j - h]) /( w*h)
  23. img1=img1.reshape((img1.shape[1],img1.shape[0],1))
  24. img1=np.concatenate((img1,img1,img1),axis=2)
  25. s=np.load('foo_file.npy')
  26. diff=img1-s #Dif is NOT zero matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement