tensorflow sobel算子实现
生活随笔
收集整理的這篇文章主要介紹了
tensorflow sobel算子实现
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
搬運(yùn)自https://stackoverflow.com/questions/35565312/is-there-a-convolution-function-in-tensorflow-to-apply-a-sobel-filter
具體實(shí)現(xiàn)如下
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')除了image傳入大小根據(jù)自己需求需要修改一下之外,沒有別的需要注意的地方了。
總結(jié)
以上是生活随笔為你收集整理的tensorflow sobel算子实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10下skimage的安装
- 下一篇: latex基础(文字,图,表)