axe*_*brz 5 python convolution sobel tensorflow
convolutionTensorflow中是否有任何方法将Sobel滤波器应用于图像img(张量类型float32和等级2)?
sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], 'float32')
result = tf.convolution(img, sobel_x) # <== TO DO THIS
Run Code Online (Sandbox Code Playgroud)
我已经看过,tf.nn.conv2d但我看不出如何使用它进行此操作.有什么方法可以tf.nn.conv2d用来解决我的问题吗?
mrr*_*rry 14
也许我在这里错过了一个微妙的东西,但似乎你可以使用tf.expand_dims()和将Sobel滤镜应用于图像tf.nn.conv2d(),如下所示:
sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)
sobel_x_filter = tf.reshape(sobel_x, [3, 3, 1, 1])
sobel_y_filter = tf.transpose(sobel_x_filter, [1, 0, 2, 3])
# Shape = height x width.
image = tf.placeholder(tf.float32, shape=[None, None])
# Shape = 1 x height x width x 1.
image_resized = tf.expand_dims(tf.expand_dims(image, 0), 3)
filtered_x = tf.nn.conv2d(image_resized, sobel_x_filter,
strides=[1, 1, 1, 1], padding='SAME')
filtered_y = tf.nn.conv2d(image_resized, sobel_y_filter,
strides=[1, 1, 1, 1], padding='SAME')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5499 次 |
| 最近记录: |