Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow中是否有卷积函数来应用Sobel滤波器?_Python_Tensorflow_Convolution_Sobel - Fatal编程技术网

Python Tensorflow中是否有卷积函数来应用Sobel滤波器?

Python Tensorflow中是否有卷积函数来应用Sobel滤波器?,python,tensorflow,convolution,sobel,Python,Tensorflow,Convolution,Sobel,Tensorflow中是否有任何卷积方法将Sobel滤波器应用于图像img(类型为float32和秩2的张量) sobel_x=tf.常量([-1,0,1],-2,0,2],-1,0,1],'float32') result=tf.convolution(img,sobel_x)#也许我在这里遗漏了一个微妙之处,但您似乎可以使用and对图像应用sobel过滤器,如下所示: sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf

Tensorflow中是否有任何
卷积
方法将Sobel滤波器应用于图像
img
(类型为
float32
和秩2的张量)

sobel_x=tf.常量([-1,0,1],-2,0,2],-1,0,1],'float32')

result=tf.convolution(img,sobel_x)#也许我在这里遗漏了一个微妙之处,但您似乎可以使用and对图像应用sobel过滤器,如下所示:

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')

Tensorflow 1.8添加了tf.image.sobel_edges(),这是目前最简单、可能也是最健壮的方法。

完成后,我发现可以应用tf.squence(过滤的_x)。非常感谢。你能再解释一下它是怎么工作的吗?我怎样才能真正卷积一幅真实的图像并展示出来呢?第二个“sobel_x_过滤器”(sobel_x_过滤器)中有一个打字错误。@OliasailO谢谢你指出这一点!我已更新代码。您的sobel_x筛选器不正确<代码>tf.常量([[1,0,-1],[2,0,-2],[1,0,-1]],tf.float32)
最左侧必须与最右侧交换。
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')