#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/4/13 10:54
# @Author : @linlianqin
# @Site :
# @File : 數據增強(distorted).py
# @Software: PyCharm
# @description:一些基于TensorFlow的數據處理方法import tensorflow as tf
import cv2
import matplotlib.pyplot as pltpath = r'E:\gitHubProjects\tensorflow_learning\CNN卷積神經網絡-cifar數據集分類\tensorflow_image_processing\1.png'def tf_imgae_processing():# 讀取圖像文件image_raw = tf.gfile.GFile(path,'rb').read() # 以二進制的形式讀取with tf.Session() as sess:## 對圖像進行解碼得到圖像的三維矩陣數據image_data = tf.image.decode_image(image_raw)h,w,c = image_data.eval().shapeprint("image_data.shape:",(h,w,c))# 顯示圖像plt.imshow(image_data.eval())plt.show()# 裁剪圖像crop_img = tf.random_crop(image_data,[300,300,c])plt.imshow(crop_img.eval())plt.show()## 保存圖像crop_encode_img = tf.image.encode_png(crop_img)with tf.gfile.GF