def normal_map(tensor, shape):
"""
Generate a tangent-space normal map.
:param Tensor tensor:
:param list[int] shape:
:return: Tensor
"""
height, width, channels = shape
reference = value_map(tensor, shape, keep_dims=True)
x = normalize(1 - convolve(ConvKernel.sobel_x, reference, [height, width, 1]))
y = normalize(convolve(ConvKernel.sobel_y, reference, [height, width, 1]))
z = 1 - tf.abs(normalize(tf.sqrt(x * x + y * y)) * 2 - 1) * .5 + .5
return tf.stack([x[:, :, 0], y[:, :, 0], z[:, :, 0]], 2)
评论列表
文章目录