日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 提取轮廓_TensorFlow 卷积操作模拟sobel算子提取图像轮廓

發(fā)布時間:2024/9/27 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 提取轮廓_TensorFlow 卷积操作模拟sobel算子提取图像轮廓 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

注意:

sobel算子不保證結果在0-255,需要做一次歸一化處理,再乘以255

輸出的數(shù)據(jù)shape與圖像的shape不一樣,需要一次轉化

效果

代碼

import matplotlib.pyplot as plt # plt 用于顯示圖片

import matplotlib.image as mpimg # mpimg 用于讀取圖片

import numpy as np

import tensorflow as tf

myimg = 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], padding='SAME') # 3個通道輸入,生成1個feature ma

o = 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, cmap='Greys_r') # 顯示圖片

plt.axis('off') # 不顯示坐標軸

plt.show()

轉載至鏈接:https://my.oschina.net/ahaoboy/blog/1923134

總結

以上是生活随笔為你收集整理的java 提取轮廓_TensorFlow 卷积操作模拟sobel算子提取图像轮廓的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。