1. 程式人生 > >tensorflow處理影象函式

tensorflow處理影象函式

import matplotlib.pyplot as plt;
import tensorflow as tf;

img_raw = tf.gfile.FastGFile('path/output.jpg', 'rb').read()
img = tf.image.decode_jpeg(img_raw)
img = tf.image.convert_image_dtype(img, dtype=tf.float32)
 
with tf.Session() as sess:
    #按照比例
    resized = tf.image.central_crop(img,0.5)
     #影象翻轉
    resized=tf.image.flip_left_right(img);
    resized=tf.image.flip_up_down(img);
    #影象色彩調整
    resized=tf.image.adjust_brightness(img,-0.5);
    resized=tf.image.adjust_brightness(img,0.5);
    #對比度調整
    resized=tf.image.adjust_contrast(img,-5);
    resized=tf.image.adjust_contrast(img,5);
    #調整影象色相
    resized=tf.image.adjust_hue(img,0.67);
    #調整飽和度
    resized=tf.image.adjust_saturation(img,-5);
    #將影象標準化,就是將數字均值變為0,方差變成1
    resized=tf.image.per_image_standardization(img);
    #處理標註框
    batched=tf.expand_dims(img,0);
    boxes=tf.constant([[[0.05,0.04,0.05,0.04],[0.06,0.04,0.04,0.04]]]);
    resized=tf.image.draw_bounding_boxes(batched,boxes);
    print(resized);
#     plt.imshow(resized.eval())
#     plt.show()