#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 18-8-7 下午2:53
# @File : data_argument.py
# @Software: PyCharm
# @Author : wxw
# @Contact : xwwei@lighten.ai
# @Desc :
import tensorflow as tf
import cv2
import numpy as np
with tf.Session() as sess:
raw_img = tf.gfile.Open('patch.jpg', 'rb').read()
img_data = tf.image.decode_image(raw_img)
img_data = tf.image.convert_image_dtype(img_data, tf.float32)
cv2.imshow('raw_image', img_data.eval())
print('raw_shape:', img_data.eval().shape)
"""resize"""
# img_data = tf.image.resize_images(img_data.eval(), (224, 224))
"""crop and black pad"""
# img_data = tf.image.resize_image_with_crop_or_pad(img_data, target_height=1000,
# target_width=1000)
"""按照倍数中心裁剪, 倍数=(0, 1]"""
# img_data = tf.image.central_crop(img_data, central_fraction=0.2)
"""pad """
# img_data = tf.image.pad_to_bounding_box(img_data, offset_height=10, offset_width=10,
# target_height=576+10, target_width=576+10)
"""crop"""
# img_data = tf.image.crop_to_bounding_box(img_data, 40, 40, 576-40, 576-40)
"""extract
o----->y
|
|
v
x
"""
# img_data = tf.image.extract_glimpse(tf.expand_dims(img_data, 0), size=[100, 100],
# offsets=tf.reshape(tf.constant([-.4, .4], dtype=tf.float32), [1, 2]))
"""roi pooling 必要操作 boxes为长宽比值!!! """
# img_data = tf.image.crop_and_resize(tf.expand_dims(img_data, 0), boxes=[[0/576, 0/576, 1, 1]],
# box_ind=[0], crop_size=[100, 100])
"""上下翻转/左右/转置翻转/90度旋转---(random_)flip_up_down/flip_left_right/transpose/rot90"""
# img_data = tf.image.rot90(img_data, k=-1)
"""Converting Between Colorspaces"""
"""灰度"""
# img_data = tf.image.rgb_to_grayscale(img_data)
"""图像亮度[-1, 1]"""
# img_data = tf.image.adjust_brightness(img_data, delta=-.7)
"""随机图像亮度"""
# img_data = tf.image.random_brightness(img_data, max_delta=0.6)
"""随机对比度"""
# img_data = tf.image.random_contrast(img_data, lower=0, upper=4)
"""随机色调"""
# img_data = tf.image.random_hue(img_data, 0.5)
"""随机饱和度"""
# img_data = tf.image.random_saturation(img_data, lower=0, upper=2)
"""图片标准化 (x - mean) / max(stddev, 1.0/sqrt(image.NumElements()))"""
# img_data = tf.image.per_image_standardization(img_data)
"""draw boxes"""
# img_data = tf.image.draw_bounding_boxes(tf.expand_dims(img_data, 0), [[[0.1, 0.2, 0.5, 0.9]]])
print('Tensor:', img_data)
print(img_data.eval().shape)
print(img_data.eval())
cv2.imshow('changed', img_data[0].eval())
cv2.waitKey()
网友评论