我只是用TensorFlow来计算16,96,96,1形状的张量A的Sobel边映射。
我发现在TensorFlow中,有一个名为'tf.image.sobel_edges‘的函数,它可以返回每个通道的边缘映射。对于这个函数,它返回形状为16,96,96,1,2的张量。我的理解是边缘映射应该是二值图像,所以输出应该是16,96,96,1,1,但是这个函数的输出是16,96,96,1,2.如果我只想获得图像的边缘能量,如何从这个函数的输出中获得图像的边缘能量?
你能解释一下吗?提前感谢!
发布于 2019-06-24 17:47:22
边缘文档表明,返回的张量包含图像沿水平轴和垂直轴的梯度分量,在单通道图像的情况下。为了计算梯度的大小并获得边缘能量图像,我们只需要计算这些分量之和的平方根,这样:
import tensorflow as tf
tf.enable_eager_execution()
img = tf.random.normal(shape=(16,96,96,1),dtype=tf.float32) # replace with your image data
grad_components = tf.image.sobel_edges(img)
grad_mag_components = grad_components**2
grad_mag_square = tf.math.reduce_sum(grad_mag_components,axis=-1) # sum all magnitude components
grad_mag_img = tf.sqrt(grad_mag_square) # this is the image tensor you wanthttps://stackoverflow.com/questions/56740582
复制相似问题