def local_normalize(img, num_ch=1, const=127.0):
if num_ch == 1:
mu = convolve(img[:, :, 0], kern, mode='nearest')
mu_sq = mu * mu
im_sq = img[:, :, 0] * img[:, :, 0]
tmp = convolve(im_sq, kern, mode='nearest') - mu_sq
sigma = np.sqrt(np.abs(tmp))
structdis = (img[:, :, 0] - mu) / (sigma + const)
# Rescale within 0 and 1
# structdis = (structdis + 3) / 6
structdis = 2. * structdis / 3.
norm = structdis[:, :, None]
elif num_ch > 1:
norm = np.zeros(img.shape, dtype='float32')
for ch in range(num_ch):
mu = convolve(img[:, :, ch], kern, mode='nearest')
mu_sq = mu * mu
im_sq = img[:, :, ch] * img[:, :, ch]
tmp = convolve(im_sq, kern, mode='nearest') - mu_sq
sigma = np.sqrt(np.abs(tmp))
structdis = (img[:, :, ch] - mu) / (sigma + const)
# Rescale within 0 and 1
# structdis = (structdis + 3) / 6
structdis = 2. * structdis / 3.
norm[:, :, ch] = structdis
return norm
评论列表
文章目录