#!/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