枣庄市建设项目环评备案网站,爱情动作片做网站,山西省煤矿建设协会网站,wordpress不能访问首页注意#xff1a;sobel算子不保证结果在0-255#xff0c;需要做一次归一化处理#xff0c;再乘以255输出的数据shape与图像的shape不一样#xff0c;需要一次转化效果代码import matplotlib.pyplot as plt # plt 用于显示图片import matplotlib.image as mpimg # mpimg 用于…注意sobel算子不保证结果在0-255需要做一次归一化处理再乘以255输出的数据shape与图像的shape不一样需要一次转化效果代码import matplotlib.pyplot as plt # plt 用于显示图片import matplotlib.image as mpimg # mpimg 用于读取图片import numpy as npimport tensorflow as tfmyimg mpimg.imread(test.jpg) # 读取和代码处于同一目录下的图片plt.imshow(myimg) # 显示图片plt.axis(off) # 不显示坐标轴plt.show()print(myimg.shape)full np.reshape(myimg, [1, *myimg.shape])inputfull tf.Variable(tf.constant(1.0, shape[1, *myimg.shape]))filter tf.Variable(tf.constant([[-1.0, -1.0, -1.0], [0, 0, 0], [1.0, 1.0, 1.0],[-2.0, -2.0, -2.0], [0, 0, 0], [2.0, 2.0, 2.0],[-1.0, -1.0, -1.0], [0, 0, 0], [1.0, 1.0, 1.0]],shape[3, 3, 3, 1]))op tf.nn.conv2d(inputfull, filter, strides[1, 1, 1, 1], paddingSAME) # 3个通道输入生成1个feature mao tf.cast(((op - tf.reduce_min(op)) / (tf.reduce_max(op) - tf.reduce_min(op))) * 255, tf.uint8)with tf.Session() as sess:sess.run(tf.global_variables_initializer())t, f sess.run([o, filter], feed_dict{inputfull: full})print(t.shape) # (1, 512, 512, 1)t np.reshape(t, myimg.shape[:2])print(t.shape) # (512, 512)plt.imshow(t, cmapGreys_r) # 显示图片plt.axis(off) # 不显示坐标轴plt.show()转载至链接:https://my.oschina.net/ahaoboy/blog/1923134