圖像翻轉
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)
圖像尺寸調整
圖像尺寸調整屬於基礎的圖像幾何變換,TensorFlow提供了幾種尺寸調整的函數:
tf.image.resize_images:將原始圖像縮放成指定的圖像大小,其中的參數method(默認值為ResizeMethod.BILINEAR)提供了四種插值算法,具體解釋可以參考圖像幾何變換(縮放、旋轉)中的常用的插值算法
tf.image.resize_image_with_crop_or_pad:剪裁或填充處理,會根據原圖像的尺寸和指定的目標圖像的尺寸選擇剪裁還是填充,如果原圖像尺寸大於目標圖像尺寸,則在中心位置剪裁,反之則用黑色像素填充。
tf.image.central_crop:比例調整,central_fraction決定了要指定的比例,取值范圍為(0,1],該函數會以中心點作為基准,選擇整幅圖中的指定比例的圖像作為新的圖像。
參考:https://blog.csdn.net/chaipp0607/article/details/73089910