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 通道必须从图像中剥离,并使用切片操作重新附加。

tf.image.decode_gif
tf.image.decode_jpeg
tf.image.encode_jpeg
tf.image.decode_png
tf.image.encode_png
tf.image.decode_image

调整大小操作
调整大小的操作接受输入图像作为几种类型的张量。他们总是将大小调整后的图像输出为 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])

tf.image.resize_images
tf.image.resize_area
tf.image.resize_bicubic
tf.image.resize_bilinear
tf.image.resize_nearest_neighbor
裁剪
tf.image.resize_image_with_crop_or_pad
tf.image.central_crop
tf.image.pad_to_bounding_box
tf.image.crop_to_bounding_box
tf.image.extract_glimpse
tf.image.crop_and_resize
翻转,旋转和移位
tf.image.flip_up_down
tf.image.random_flip_up_down
tf.image.flip_left_right
tf.image.random_flip_left_right
tf.image.transpose_image
tf.image.rot90
颜色空间之间的转换
图像操作可以在单个图像或一批图像上工作,具体取决于其输入的张量形状。

如果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)

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

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

tf.image.adjust_brightness
tf.image.random_brightness
tf.image.adjust_contrast
tf.image.random_contrast
tf.image.adjust_hue
tf.image.random_hue
tf.image.adjust_gamma
tf.image.adjust_saturation
tf.image.random_saturation
tf.image.per_image_standardization
TensorFlow 图像使用边框
tf.image.draw_bounding_boxes
tf.image.non_max_suppression
tf.image.sample_distorted_bounding_box
TensorFlow 图像去噪
tf.image.total_variation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值