标签:img 边缘 检测 filter tf shape cnn import op
filter 的重要性 ,
在这里 显现出来了
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import tensorflow as tf
testimg = mpimg.imread("C:/Users/admin/Desktop/co.jpg")
plt.imshow(testimg)
<matplotlib.image.AxesImage at 0x21e656487b8>
[外链图片转存失败(img-KZnB3N2L-1568631235551)(output_2_1.png)]
print(testimg.shape)
(968, 1292, 3)
img = np.reshape(testimg,[1,968,1292,3])
inputimg = tf.Variable(tf.constant(1.,shape=[1,968,1292,3]))
"""filter_sobel =tf.Variable(tf.constant([[-1.,-1.,-1.],[0,0,0],[1.,1.,1.],
[-2.,-2.,-2.],[0,0,0],[2.,2.,2.],
[-1.,-1.,-1.],[0,0,0],[1.,1.,1.]],
shape=[3,3,3,1]))
"""
filter_prewitt=tf.Variable(tf.constant([[1.,1.,1.],[0,0,0],[-1.,-1.,-1.],
[1.,1.,1.],[0,0,0],[-1.,-1.,-1.],
[1.,1.,1.],[0,0,0],[-1.,-1.,-1.]],
shape=[3,3,3,1]))
op = tf.nn.conv2d(inputimg,filter_prewitt,strides=[1,1,1,1],padding ="SAME")
#op1 =tf.cast(((op-tf.reduce_min(op))/(tf.reduce_max(op)-tf.reduce_min(op)))
# *255,tf.uint8)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
t = sess.run(op,feed_dict={inputimg:img})
t = np.reshape(t,[968,1292])
plt.imshow(t,cmap="Greys_r")
```![在这里插入图片描述](https://www.icode9.com/i/ll/?i=20190916185509495.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21heW9uZ2t1bg==,size_16,color_FFFFFF,t_70)
<matplotlib.image.AxesImage at 0x21e6b5c7908>
[外链图片转存失败(img-63CDNsWL-1568631235552)(output_6_1.png)]
```python
标签:img,边缘,检测,filter,tf,shape,cnn,import,op 来源: https://blog.csdn.net/mayongkun/article/details/100897728
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。