圖像預處理之圖像翻轉、圖像色彩調整
阿新 • • 發佈:2018-09-07
tran 色相 target get pytho pan aip highlight clas
圖像翻轉
tf.image.flip_up_down:上下翻轉
tf.image.flip_left_right:左右翻轉
tf.image.transpose_image:對角線翻轉
除此之外,TensorFlow還提供了隨機翻轉的函數,保證了樣本的樣本的隨機性:
tf.image.random_flip_up_down:隨機上下翻轉圖片
tf.image.random_flip_left_right:隨機左右翻轉圖片
圖像色彩調整
亮度:
tf.image.adjust_brightness:調整圖片亮度
tf.image.random_brightness:在某範圍隨機調整圖片亮度
對比度:
tf.image.adjust_contrast:調整圖片對比度
tf.image.random_contrast:在某範圍隨機調整圖片對比度
色相:
tf.image.adjust_hue:調整圖片色相
tf.image.random_hue:在某範圍隨機調整圖片色相
飽和度:
tf.image.adjust_saturation:調整圖片飽和度
tf.image.random_saturation:在某範圍隨機調整圖片飽和度
歸一化:
per_image_standardization:三維矩陣中的數字均值變為0,方差變為1。在以前的版本中,它其實叫做per_image_whitening,也就是白化操作。
import matplotlib.pyplot as plt import tensorflow as tf image_raw_data = tf.gfile.FastGFile(‘.//image//1.jpg‘,‘rb‘).read() with tf.Session() as sess: img_data = tf.image.decode_jpeg(image_raw_data) plt.imshow(img_data.eval()) plt.show() # 將圖片的亮度-0.5。 adjusted = tf.image.adjust_brightness(img_data, -0.5) plt.imshow(adjusted.eval()) plt.show() # 將圖片的亮度0.5 adjusted = tf.image.adjust_brightness(img_data, 0.5) plt.imshow(adjusted.eval()) plt.show() # 在[-max_delta, max_delta)的範圍隨機調整圖片的亮度。 adjusted = tf.image.random_brightness(img_data, max_delta=0.5) plt.imshow(adjusted.eval()) plt.show() # 將圖片的對比度-5 adjusted = tf.image.adjust_contrast(img_data, -5) plt.imshow(adjusted.eval()) plt.show() # 將圖片的對比度+5 adjusted = tf.image.adjust_contrast(img_data, 5) plt.imshow(adjusted.eval()) plt.show() # 在[lower, upper]的範圍隨機調整圖的對比度。 adjusted = tf.image.random_contrast(img_data, 0.1, 0.6) plt.imshow(adjusted.eval()) plt.show() #調整圖片的色相 adjusted = tf.image.adjust_hue(img_data, 0.1) plt.imshow(adjusted.eval()) plt.show() # 在[-max_delta, max_delta]的範圍隨機調整圖片的色相。max_delta的取值在[0, 0.5]之間。 adjusted = tf.image.random_hue(img_data, 0.5) plt.imshow(adjusted.eval()) plt.show() # 將圖片的飽和度-5。 adjusted = tf.image.adjust_saturation(img_data, -5) plt.imshow(adjusted.eval()) plt.show() # 在[lower, upper]的範圍隨機調整圖的飽和度。 adjusted = tf.image.random_saturation(img_data, 0, 5) # 將代表一張圖片的三維矩陣中的數字均值變為0,方差變為1。 adjusted = tf.image.per_image_standardization(img_data)
參考:https://blog.csdn.net/chaipp0607/article/details/73089910
圖像預處理之圖像翻轉、圖像色彩調整