为接下来的大项目做准备
boxfilter是opencv自带的
import cv2
import numpy as np
# guidefilter : python implementation
# I : guide image
# P : inout image
# rads : the radius of windows
# eps : the regularization parameter
def boxfilter(I,rad):
N = np.zeros(np.shape(I))
cv2.boxfilter(I,N,rad)
return N
def guidefilter(I,P,rads,eps):
hgt = I.shpae[0]
wid = I.shpae[1]
N = np.ones(np.shape(I))
meanI = boxfilter(I,rads)
meanP = boxfilter(P,rads)
meanIP = boxfilter(I*P,rads)
covIP = meanIP - meanI * meanP
meanII = boxfilter(I*I,rads)
varI = meanII - I*I
a = covIP / (varI+eps)
b = meanP - a*meanI
meanA = boxfilter(a,rads)/N
meanB = boxfilter(b,rads)/N
res = meanA * I + meanB
return res