codecamp

TensorFlow图像操作

注意:接受 Tensor 参数的函数也可以接受被 tf.convert_to_tensor 接受的任何内容

TensorFlow 编码和解码图像

TensorFlow 提供操作来解码和编码 JPEG 和 PNG 格式。编码图像由标量字符串 Tensors 表示,解码图像由shape为[height, width, channels]的3-D uint8张量表示。(PNG也支持 uint16)

编码和解码操作一次适用于一个图像。他们的输入和输出都是可变的大小。如果您需要固定大小的图像,请将解码操作的输出传递到裁剪和调整大小操作之一。

注意:PNG 编码和解码操作支持 RGBA,但转换操作目前只支持 RGB,HSV 和 GrayScale。目前,Alpha 通道必须从图像中剥离,并使用切片操作重新附加。

调整大小操作

调整大小的操作接受输入图像作为几种类型的张量。他们总是将大小调整后的图像输出为 float32 张量。

方便函数 tf.image.resize_images 支持4维和3维张量作为输入和输出。4维张量用于批量的图像,用于单个图像的3维张量。

其他大小调整操作只支持4维图像批处理作为输入:tf.image.resize_area,tf.image.resize_bicubic,tf.image.resize_bilinear,tf.image.resize_nearest_neighbor.

例:

# Decode a JPG image and resize it to 299 by 299 using default method.
image = tf.image.decode_jpeg(...)
resized_image = tf.image.resize_images(image, [299, 299])

裁剪

翻转,旋转和移位

颜色空间之间的转换

图像操作可以在单个图像或一批图像上工作,具体取决于其输入的张量形状。

如果3维,则shape是 [height, width, channels],而 Tensor 表示一个图像。如果4维,则shape是 [batch_size, height, width, channels],而 Tensor 表示 batch_size 图像。

目前,channels 可以有效地为 1,2,3或4,单通道图像是灰度级,3通道的图像被编码为 RGB 或 HSV。具有2或4个通道的图像包括 Alpha 通道,必须在将图像传递到大多数图像处理功能之前从图像中剥离(并且可以稍后重新附加)。

在内部,图像或者以 float32 每像素一个通道存储(隐含地,假定值位于[0,1))或者 uint8 每个像素每个通道一个(假定值在于[0,255])。

TensorFlow 可以在 RGB 或 HSV 的图像之间进行转换.转换功能仅适用于浮动图像,因此您需要使用其他格式转换图像 tf.image.convert_image_dtype。

例:

# Decode an image and convert it to HSV.
rgb_image = tf.image.decode_png(...,  channels=3)
rgb_image_float = tf.image.convert_image_dtype(rgb_image, tf.float32)
hsv_image = tf.image.rgb_to_hsv(rgb_image)

TensorFlow 图像调整

TensorFlow 提供了以各种方式调整图像的功能:亮度,对比度,色相和饱和度。每个调整都可以用预定义的参数或从预定义的间隔中选取的随机参数完成。随机调整通常有助于扩大训练集并减少过度配合。

如果几个调整被链接,建议通过首先将图像转换为最自然的数据类型和表示(RGB 或 HSV)来最小化冗余转换的数量。

TensorFlow 图像使用边框

TensorFlow 图像去噪

TensorFlow直方图
TensorFlow 输入和读取器
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }