最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python使用TensorFlow進(jìn)行圖像處理的方法

 更新時(shí)間:2018年02月28日 10:21:23   作者:HackTheCode  
本篇文章主要介紹了使用TensorFlow進(jìn)行圖像處理的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

一、圖片的放大縮小

在使用TensorFlow進(jìn)行圖片的放大縮小時(shí),有三種方式:

1、tf.image.resize_nearest_neighbor():臨界點(diǎn)插值
2、tf.image.resize_bilinear():雙線性插值
3、tf.image.resize_bicubic():雙立方插值算法

下面是示例代碼:

# encoding:utf-8
# 使用TensorFlow進(jìn)行圖片的放縮
import tensorflow as tf
import cv2
import numpy as np

# 讀取圖片
img = cv2.imread("1.jpg")
# 顯示原始圖片
cv2.imshow("resource", img)

h, w, depth = img.shape
img = np.expand_dims(img, 0)

# 臨界點(diǎn)插值
nn_image = tf.image.resize_nearest_neighbor(img, size=[h+100, w+100])
nn_image = tf.squeeze(nn_image)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  nn_image = sess.run(nn_image)
nn_image = np.uint8(nn_image)

# 雙線性插值
bi_image = tf.image.resize_bilinear(img, size=[h+100, w+100])
bi_image = tf.squeeze(bi_image)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  bi_image = sess.run(bi_image)
bi_image = np.uint8(bi_image)

# 雙立方插值算法
bic_image = tf.image.resize_bicubic(img, size=[h+100, w+100])
bic_image = tf.squeeze(bic_image)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  bic_image = sess.run(bic_image)
bic_image = np.uint8(bic_image)
# 顯示結(jié)果圖片
cv2.imshow("result_nn", nn_image)
cv2.imshow("result_bi", bi_image)
cv2.imshow("result_bic", bic_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

二、圖片的亮度調(diào)整

在使用TensorFlow進(jìn)行圖片的亮度調(diào)整時(shí),有兩種方式:
1、tf.image.adjust_brightness():亮度的全局調(diào)整
2、tf.image.random_brightness():亮度的隨機(jī)調(diào)整

下面是示例代碼:

# encoding:utf-8
# 使用TensorFlow調(diào)整圖片的亮度
import tensorflow as tf
import cv2
import numpy as np

# 讀取圖片
img = cv2.imread("1.jpg")
# 顯示原始圖片
cv2.imshow("resource", img)

img = np.expand_dims(img, 0)
# adjust_brightness
bright_img = tf.image.adjust_brightness(img, delta=.5)
bright_img = tf.squeeze(bright_img)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  result = sess.run(bright_img)
result = np.uint8(result)

rand_image = tf.image.random_brightness(img, max_delta=.5)
rand_image = tf.squeeze(rand_image)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  result2 = sess.run(rand_image)
result2 = np.uint8(result2)

cv2.imshow("result", result)
cv2.imshow("result2", result2)
cv2.waitKey(0)
cv2.destroyAllWindows()

三、圖片的對(duì)比度調(diào)整

在使用TensorFlow進(jìn)行圖片的對(duì)比度調(diào)整時(shí),有兩種方式:
1、tf.image.adjust_contrast():對(duì)比度的全局調(diào)整
2、tf.image.random_contrast():對(duì)比度的隨機(jī)調(diào)整

代碼與圖片的亮度調(diào)整類似,這里就不贅述了。

四、圖片的飽和度調(diào)整

在使用TensorFlow進(jìn)行圖片的飽和度調(diào)整時(shí),使用下列函數(shù):

tf.image.adjust_saturation() 

飽和度調(diào)整范圍為0~5

下面示例代碼:

# encoding:utf-8
# 使用TensorFlow調(diào)整圖片的亮度
import tensorflow as tf
import cv2
import numpy as np

# 讀取圖片
img = cv2.imread("1.jpg")
# 顯示原始圖片
cv2.imshow("resource", img)

# 圖像的飽和度調(diào)整
stand_img = tf.image.adjust_saturation(img, saturation_factor=2.4)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  result = sess.run(stand_img)
result = np.uint8(result)

cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

五、圖片的標(biāo)準(zhǔn)化

在使用TensorFlow對(duì)圖像數(shù)據(jù)進(jìn)行訓(xùn)練之前,常需要執(zhí)行圖像的標(biāo)準(zhǔn)化操作,它與歸一化是有區(qū)別的,歸一化不改變圖像的直方圖,標(biāo)準(zhǔn)化操作會(huì)改變圖像的直方圖。標(biāo)準(zhǔn)化操作使用如下函數(shù):

tf.image.per_image_standardization() 

下面是示例代碼:

# encoding:utf-8
# 使用TensorFlow調(diào)整圖片的亮度
import tensorflow as tf
import cv2
import numpy as np

# 讀取圖片
img = cv2.imread("1.jpg")
# 顯示原始圖片
cv2.imshow("resource", img)

# 圖像標(biāo)準(zhǔn)化操作
stand_img = tf.image.per_image_standardization(img)
with tf.Session() as sess:
  # 運(yùn)行 'init' op
  result = sess.run(stand_img)
result = np.uint8(result)

cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

六、圖像的色彩空間轉(zhuǎn)化

使用TensorFlow進(jìn)行圖像的色彩空間轉(zhuǎn)化,包括HSV、RGB、灰度色彩空間之間的轉(zhuǎn)化,使用的函數(shù)如下所示:

tf.image.rgb_ to_hsv() 
tf.image.rgb_ to_grayscale() 
tf.image.hsv_ to_rgb() 

代碼與圖像的標(biāo)準(zhǔn)化操作的代碼相似,這里不再贅述。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

隆林| 万载县| 河北省| 博罗县| 平阳县| 芮城县| 桂阳县| 扬中市| 蓬安县| 连南| 堆龙德庆县| 富顺县| 开平市| 莫力| 新沂市| 新乡县| 修武县| 浦北县| 泸州市| 临澧县| 景德镇市| 卓资县| 乌兰浩特市| 康平县| 灵璧县| 如东县| 宁津县| 汶川县| 芒康县| 易门县| 隆昌县| 台山市| 西城区| 阿坝县| 泰州市| 西安市| 含山县| 环江| 莱州市| 白河县| 衡南县|