tensorflow卷积实现图片轮廓提取

import matplotlib.pyplot as plt
import matplotlib.image as mping
import numpy as np
import tensorflow as tf

img = mping.imread("lena-flipped.bmp")
plt.imshow(img)
plt.axis("off")
plt.show()
print(img.shape)

image = np.reshape(img,[1,512,512,3])
input_image = tf.Variable(tf.constant(1.0,shape=[1,512,512,3]))
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]))
conv1 =tf.nn.conv2d(input_image,filter=filter,strides=[1,1,1,1],padding="SAME")
# 图片归一化
norm = tf.cast(((conv1-tf.reduce_min(conv1))/(tf.reduce_max(conv1)-tf.reduce_min(conv1))), tf.float32)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    output,_ = sess.run([norm,filter],feed_dict={input_image:image})

    t = np.squeeze(output,axis=[0,3])
    plt.imshow(t,cmap="Greys_r")
    plt.axis("off")
    plt.show()

提取前:

提取后:

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值