tensorflow 图像数据处理(二)
来源:互联网 发布:导航仪软件 编辑:程序博客网 时间:2024/06/08 06:34
____tz_zs
图像片段截取,图像大小调整,图像翻转以及色彩调整的整个图像预处理过程
案例来源《TensorFlow实战Google深度学习框架》
原图
处理后的图片
# -*- coding: utf-8 -*-"""@author: tz_zs的图片预处理样例"""import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt# 随机处理的顺序可以进一步降低无关因素的影响def distort_color(image, color_ordering=0): if color_ordering == 0: # 随机亮度 image = tf.image.random_brightness(image, max_delta=32. / 255.) # 随机饱和度 image = tf.image.random_saturation(image, lower=0.5, upper=1.5) # 随机色相 image = tf.image.random_hue(image, max_delta=0.2) # 随机对比度 image = tf.image.random_contrast(image, lower=0.5, upper=1.5) elif color_ordering == 1: image = tf.image.random_saturation(image, lower=0.5, upper=1.5) image = tf.image.random_brightness(image, max_delta=32. / 255.) image = tf.image.random_contrast(image, lower=0.5, upper=1.5) image = tf.image.random_hue(image, max_delta=0.2) return tf.clip_by_value(image, 0.0, 1.0)def preprocess_for_train(image, height, width, bbox): # 如果没有提供注释框,则关注整个图像 if bbox is None: bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4]) # [[[ 0. 0. 1. 1.]]] # 转换图像张量的类型 if image.dtype != tf.float32: image = tf.image.convert_image_dtype(image, dtype=tf.float32) # 随机截取图像 # print(tf.shape(image).eval()) # [232 320 3] bbox_begin, bbox_size, _ = tf.image.sample_distorted_bounding_box(tf.shape(image), bounding_boxes=bbox) distorted_image = tf.slice(image, bbox_begin, bbox_size) # 大小 distorted_image = tf.image.resize_images(distorted_image, [height, width], method=np.random.randint(4)) # 翻转 distorted_image = tf.image.random_flip_left_right(distorted_image) # 随机色彩 distorted_image = distort_color(distorted_image, np.random.randint(2)) return distorted_imageimage_raw_data = tf.gfile.FastGFile("picture.jpg", "rb").read()with tf.Session() as sess: img_data = tf.image.decode_jpeg(image_raw_data) boxes = tf.constant([[[0.05, 0.05, 0.9, 0.7], [0.35, 0.47, 0.5, 0.56]]]) for i in range(6): result = preprocess_for_train(img_data, 299, 299, boxes) plt.imshow(result.eval()) plt.show()
阅读全文
0 0
- tensorflow 图像数据处理(二)
- tensorflow 图像数据处理(一)
- 【TensorFlow】数据处理(对图像的处理)
- TensorFlow图像数据处理
- tensorflow 图像数据处理
- TensorFlow 图像预处理(二) 图像翻转,图像色彩调整
- 【TensorFlow】数据处理(输入数据处理框架)
- 图像数据处理(3)
- 图像数据处理(1)
- 图像数据处理(2)
- 图像数据处理(0)
- 海量数据处理(二)
- 【TensorFlow】数据处理(将MNIST转为TFRecord)
- 【TensorFlow】数据处理(队列和多线程)
- 【TensorFlow】数据处理(输入文件队列)
- 数据处理工具用户手册(二)
- 数据处理(二)数据聚合
- tensorflow15《TensorFlow实战Google深度学习框架》笔记-07图像数据处理 code
- context:component-scan标签的use-default-filters属性的作用以及原理分析
- STL各个数据结构特点
- 未知宽高img的居中问题
- mysql 的安装和新用户的创建
- Octree-based convolutional neural network summary
- tensorflow 图像数据处理(二)
- Linux下替换指定的目录及其子目录下所有文件中的某些内容(3种方法)
- 银行转账存储过程类似(mysql)
- 怎样关闭frame窗口
- 2127: happiness
- 2017.09.09网易校招笔试第一题
- JAVA 简单爬虫
- kd-tree : k近邻查询和范围查询
- Android 新手引导半透明蒙层效果实现