Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from sys import argv
- import os.path
- from copy import deepcopy
- import numpy as np
- from PIL import Image
- def box_filter(src_path=os.getcwd()+'/tst_1.jpg', dst_path=os.getcwd()+'/transf_1.jpg', w=5,h=5):
- jpgfile=Image.open(src_path)
- img = np.array(jpgfile.getdata()).reshape(jpgfile.size[0],jpgfile.size[1],3)
- img=img[:,:,0]
- img1= deepcopy(img)
- pref=deepcopy(img)
- for i in range(1,img.shape[0]):
- pref[i,0]=img[1,0]+pref[i-1,0]
- for j in range(1,img.shape[1]):
- pref[0,j]=img[0,j]+pref[0,j-1]
- for i in range(0,img.shape[0]):
- for j in range(0,img.shape[1]):
- pref[i,j]=pref[i,j-1]+pref[i-1,j]-pref[i-1,j-1]+img[i,j]
- for i in range(w,img.shape[0]):
- for j in range(h,img.shape[1]):
- img1[i,j]=(pref[i, j] - pref[i - w, j] - pref[i, j - h] + pref[i - w, j - h]) /( w*h)
- img1=img1.reshape((img1.shape[1],img1.shape[0],1))
- img1=np.concatenate((img1,img1,img1),axis=2)
- s=np.load('foo_file.npy')
- diff=img1-s #Dif is NOT zero matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement