潘阳爱jese吧 关注:7贴子:105
  • 0回复贴,共1
import numpy as np
def getMSE(image, dm):
assert(image.shape == dm.shape)
w, h, c = image.shape
mse = np.zeros((w,h))
for i in range(w):
for j in range(h):
rgb_image = np.array(image[i,j,:])
rgb_dm = np.array(dm[i,j,:])
l_image = np.sqrt(rgb_image.dot(rgb_image))
l_dm = np.sqrt(rgb_dm.dot(rgb_dm))
mse[i,j] = np.abs(l_image - l_dm)
return mse/(mse.max() + 0.00000001)
def getTheta(v1, v2):
l1 = np.sqrt(v1.dot(v1))
if l1 == 0:
l1 = 0.1
l2 = np.sqrt(v2.dot(v2))
if l2 ==0:
l2 = 0.1
theta = v1.dot(v2) / l1*l2
return theta
def getDeltaTheta(image, dm):
assert(image.shape == dm.shape)
w, h, c = image.shape
theta = np.zeros((w,h))
temp = np.array([0.0,1.0,0.0]).astype(np.float)
for i in range(w):
for j in range(h):
rgb_image = np.array(image[i,j,:])
rgb_dm = np.array(dm[i,j,:])
rgb_delta = rgb_image - rgb_dm
delta_r = rgb_delta[0]
delta_g = rgb_delta[1]
delta_b = rgb_delta[2]
cosin_angle = np.abs(delta_r-delta_g) + np.abs(delta_g-delta_b) + np.abs(delta_b-delta_r)
theta[i,j] = cosin_angle
return theta/(theta.max() + 0.00000001)
def getMask(gt, dm, thres=0.15):
delta_length = getMSE(gt, dm)
delta_theta = getDeltaTheta(gt, dm)
delta = delta_length + 3*delta_theta
delta = delta / delta.max()
mask = delta> thres
return mask


IP属地:上海1楼2019-10-22 16:50回复