CNN处理图片
In [5]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import tensorflow as tf import matplotlib.pyplot as plt import numpy as np # 平滑均值滤波 #KaTeX parse error: Expected 'EOF', got '_' at position 14: \text {filter_̲{arg}=np.}.full (shape=[3, \text {(shape=[3,} (shape=[3,, 3, 1, 1], fill_value=1 / 9) # # 高斯平滑滤波 f i l t e r a r g = n p . filter_arg=np. filterarg=np. . a r r a y ( [ [ 1 / 16 , 2 / 16 , .array([[1/16,2/16, .array([[1/16,2/16, / / / / / /,[2/16,4/16,2/16],[1/16,2/16,1/16]]).reshape([3,3,1,1 pic3=tf. \text {pic3=tf.} pic3=tf..constant(pic2, dt ype=tf \text {ype=tf} ype=tf.float32) KaTeX parse error: Expected 'EOF', got '_' at position 14: \text {filter_̲{arg}}=\text {t….constant(filter_arg, dtype=tf.float32) # 卷积 KaTeX parse error: Expected 'EOF', got '_' at position 11: \text {pic_̲{cnn}}=\text {t….nn.conv2d(pic3, fil t e r = f i l t e r a r g , ter=filter_arg, ter=filterarg, strides = = =[1, 1, 1, 1], padding=‘SAME’) with tf.Session() as sess: KaTeX parse error: Expected 'EOF', got '_' at position 25: …c4=sess.run(pic_̲{cnn})} print(pic4.shape) plt.imshow(pic4.transpose([3,1,2,0]).reshape([582,1024,3]).astype(np.uint8)/255) # 图片灰度化处理 s = − 1 ) s=-1) s=−1).astype(np.uin # plt.show() pic = = = plt.imread(‘./欧式.jpg’) pic2 = = = pic.reshape([1, 582, 1024, 3]).transpose([3,1,2,0]) # plt.imshow(pic4.transpose( [ 3 , 1 , 2 , 0 ] [3,1,2,0] [3,1,2,0]).reshape((582,1024,3)).mean(axi |
---|
(3, 582, 1024, 1)
In [3]: | 1 | plt.imshow(pic) |
---|
Out[3]: <matplotlib.image.AxesImage at 0x1d088552198>