tensorflow接口研讀image_op

image_op函數使用。

一、圖像的讀取及保存

3.1 tf.image.decode_gif(contents, name=None)
3.2 tf.image.decode_jpeg(contents, channels=None, ratio=None, fancy_upscaling=None, try_recover_truncated=None, acceptable_fraction=None, dct_method=None, name=None)
3.3 tf.image.encode_jpeg(image, format=None, quality=None, progressive=None, optimize_size=None, chroma_downsampling=None, density_unit=None, x_density=None, y_density=None, xmp_metadata=None, name=None)
3.4 tf.image.decode_png(contents, channels=None, dtype=None, name=None)
3.5 tf.image.encode_png(image, compression=None, name=None)
3.6 tf.image.decode_image(contents, channels=None, name=None)

二、尺寸調整

3.7 tf.image.resize_images(images, size, method=0, align_corners=False)
3.8 tf.image.resize_area(images, size, align_corners=None, name=None)
3.9 tf.image.resize_bicubic(images, size, align_corners=None, name=None)
3.10 tf.image.resize_bilinear(images, size, align_corners=None, name=None)
3.11 tf.image.resize_nearest_neighbor(images, size, align_corners=None, name=None)
3.12 tf.image.resize_image_with_crop_or_pad(image, target_height, target_width)
3.13 tf.image.central_crop(image, central_fraction)
3.14 tf.image.pad_to_bounding_box(image, offset_height, offset_width, target_height, target_width)
3.15 tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width)
3.16 tf.image.extract_glimpse(input, size, offsets, centered=None, normalized=None, uniform_noise=None, name=None)
3.17 tf.image.crop_and_resize(image, boxes, box_ind, crop_size, method=None, extrapolation_value=None, name=None)
3.18 tf.image.flip_up_down(image)
3.19 tf.image.random_flip_up_down(image, seed=None)
3.20 tf.image.flip_left_right(image)
3.21 tf.image.random_flip_left_right(image, seed=None)
3.22 tf.image.transpose_image(image)
3.23 tf.image.rot90(image, k=1, name=None)

三、色彩模式調整

3.24 tf.image.rgb_to_grayscale(images, name=None)
將一個或多個圖片由RGB模式轉化為灰度模式。 

3.25 tf.image.grayscale_to_rgb(images, name=None)
將一個或多個圖片由灰度模式轉化為RGB模式。 

3.26 tf.image.hsv_to_rgb(images, name=None)
將一個或多個圖片由HSV模式轉化為RGB模式。 

3.27 tf.image.rgb_to_hsv(images, name=None)
將一個或多個圖片由RGB模式轉化為HSV模式。 



3.29 tf.image.adjust_brightness(image, delta)
調整RGB或灰度圖的明暗度。 image_out=image*delta。

3.30 tf.image.random_brightness(image, max_delta, seed=None)
隨機調整RGB或灰度圖的明暗度。隨機值范圍 `[-max_delta, max_delta)`。

3.31 tf.image.adjust_contrast(images, contrast_factor)
調整RGB或灰度圖的對比度。

在運算前,image和delta都先轉換為float類型,運算完成后再返回初始類型。

對圖片而言,每個通道的對比度調節是獨立的。該函數先計算該通道像素平均值mean,而后對每個值進行運算
`(x - mean) * contrast_factor + mean`.

3.32 tf.image.random_contrast(image, lower, upper, seed=None)
隨機調整RGB或灰度圖的對比度。對比于`adjust_contrast`,`contrast_factor`從`[lower,upper]`中隨機取值。

3.33 tf.image.adjust_hue(image, delta, name=None)

調節RGB圖像的色彩。

該函數將圖片先轉換為float類型,之而轉換為HSV模式,對HSV模式中的hue通道進行運算,完成后再轉回RGB模式,乃至原始數據類型。

##### 參數:
*  <b>`image`</b>: RGB格式圖片,最末尺度必須為3。
*  <b>`delta`</b>: float.  添加到hue通道的值,必須在[-1,1]之間。

3.34 tf.image.random_hue(image, max_delta, seed=None)
隨機調節RGB圖像的色彩。隨機delta值,范圍為`[-max_delta, max_delta]`.


3.35 tf.image.adjust_gamma(image, gamma=1, gain=1)

進行灰度矯正。Out = In*gamma。

若gamma>1,圖片將變暗;若gamma<1,圖片將變亮;


3.36 tf.image.adjust_saturation(image, saturation_factor, name=None)
調節RGB圖像的飽和度。

該函數將圖片先轉換為float類型,之而轉換為HSV模式,對HSV模式中的saturation通道進行運算,完成后再轉回RGB模式,乃至原始數據類型。

3.37 tf.image.random_saturation(image, lower, upper, seed=None)

#隨機調節RGB圖像的飽和度。`saturation_factor`隨機在`[lower,upper]`中取值。

四 其它

3.28 tf.image.convert_image_dtype(image, dtype, saturate=False, name=None)
#轉化圖片數據類型至`dtype`。并將數據歸一為 [0,1]。

3.38 tf.image.per_image_standardization(image)
#將圖片標準化,`均值為0,方差為1。
#out=(x - mean) / adjusted_stddev。
#adjusted_stddev = max(stddev, 1.0/sqrt(image.NumElements()))。`stddev` 是圖片所有值的標準方差。

3.39 tf.image.draw_bounding_boxes(images, boxes, name=None)
#給一批圖片繪制方框,每張圖片的方框數量、大小、位置都一樣。
#boxes:shape:`[batch, num_bounding_boxes, 4]`,方框坐標 `[y_min, x_min, y_max, x_max]`,取值范圍`[0.0, 1.0]`。

3.40 tf.image.non_max_suppression(boxes, scores, max_output_size, iou_threshold=None, name=None)

Greedily selects a subset of bounding boxes in descending order of score,

pruning away boxes that have high intersection-over-union (IOU) overlap
with previously selected boxes.  Bounding boxes are supplied as
[y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any
diagonal pair of box corners and the coordinates can be provided as normalized
(i.e., lying in the interval [0, 1]) or absolute.  Note that this algorithm
is agnostic to where the origin is in the coordinate system.  Note that this
algorithm is invariant to orthogonal transformations and translations
of the coordinate system; thus translating or reflections of the coordinate
system result in the same boxes being selected by the algorithm.

The output of this operation is a set of integers indexing into the input
collection of bounding boxes representing the selected boxes.  The bounding
box coordinates corresponding to the selected indices can then be obtained
using the `tf.gather operation`.  For example:

  selected_indices = tf.image.non_max_suppression(
      boxes, scores, max_output_size, iou_threshold)
  selected_boxes = tf.gather(boxes, selected_indices)

##### Args:


*  <b>`boxes`</b>: A `Tensor` of type `float32`.
    A 2-D float tensor of shape `[num_boxes, 4]`.
*  <b>`scores`</b>: A `Tensor` of type `float32`.
    A 1-D float tensor of shape `[num_boxes]` representing a single
    score corresponding to each box (each row of boxes).
*  <b>`max_output_size`</b>: A `Tensor` of type `int32`.
    A scalar integer tensor representing the maximum number of
    boxes to be selected by non max suppression.
*  <b>`iou_threshold`</b>: An optional `float`. Defaults to `0.5`.
    A float representing the threshold for deciding whether boxes
    overlap too much with respect to IOU.
*  <b>`name`</b>: A name for the operation (optional).

##### Returns:

  A `Tensor` of type `int32`.
  A 1-D integer tensor of shape `[M]` representing the selected
  indices from the boxes tensor, where `M <= max_output_size`.



3.41 tf.image.sample_distorted_bounding_box(image_size, bounding_boxes, seed=None, seed2=None, min_object_covered=None, aspect_ratio_range=None, area_range=None, max_attempts=None, use_image_if_no_bounding_boxes=None, name=None)
#隨機輸出截取圖片。
Generate a single randomly distorted bounding box for an image.

Bounding box annotations are often supplied in addition to ground-truth labels
in image recognition or object localization tasks. A common technique for
training such a system is to randomly distort an image while preserving
its content, i.e. *data augmentation*. This Op outputs a randomly distorted
localization of an object, i.e. bounding box, given an `image_size`,
`bounding_boxes` and a series of constraints.

The output of this Op is a single bounding box that may be used to crop the
original image. The output is returned as 3 tensors: `begin`, `size` and
`bboxes`. The first 2 tensors can be fed directly into `tf.slice` to crop the
image. The latter may be supplied to `tf.image.draw_bounding_boxes` to visualize
what the bounding box looks like.

Bounding boxes are supplied and returned as `[y_min, x_min, y_max, x_max]`. The
bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and
height of the underlying image.

For example,

```python
    # Generate a single distorted bounding box.
    begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
        tf.shape(image),
        bounding_boxes=bounding_boxes)

    # Draw the bounding box in an image summary.
    image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0),
                                                  bbox_for_draw)
    tf.image_summary('images_with_box', image_with_box)

    # Employ the bounding box to distort the image.
    distorted_image = tf.slice(image, begin, size)

Note that if no bounding box information is available, setting
use_image_if_no_bounding_boxes = true will assume there is a single implicit
bounding box covering the whole image. If use_image_if_no_bounding_boxes is
false and no bounding boxes are supplied, an error is raised.

Args:
  • <b>image_size</b>: A Tensor. Must be one of the following types: uint8, int8, int16, int32, int64.
    1-D, containing [height, width, channels].
  • <b>bounding_boxes</b>: A Tensor of type float32.
    3-D with shape [batch, N, 4] describing the N bounding boxes
    associated with the image.
  • <b>seed</b>: An optional int. Defaults to 0.
    If either seed or seed2 are set to non-zero, the random number
    generator is seeded by the given seed. Otherwise, it is seeded by a random
    seed.
  • <b>seed2</b>: An optional int. Defaults to 0.
    A second seed to avoid seed collision.
  • <b>min_object_covered</b>: An optional float. Defaults to 0.1.
    The cropped area of the image must contain at least this
    fraction of any bounding box supplied. The value of this parameter should be
    non-negative. In the case of 0, the cropped area does not need to overlap
    any of the bounding boxes supplied.
  • <b>aspect_ratio_range</b>: An optional list of floats. Defaults to [0.75, 1.33].
    The cropped area of the image must have an aspect ratio =
    width / height within this range.
  • <b>area_range</b>: An optional list of floats. Defaults to [0.05, 1].
    The cropped area of the image must contain a fraction of the
    supplied image within in this range.
  • <b>max_attempts</b>: An optional int. Defaults to 100.
    Number of attempts at generating a cropped region of the image
    of the specified constraints. After max_attempts failures, return the entire
    image.
  • <b>use_image_if_no_bounding_boxes</b>: An optional bool. Defaults to False.
    Controls behavior if no bounding boxes supplied.
    If true, assume an implicit bounding box covering the whole input. If false,
    raise an error.
  • <b>name</b>: A name for the operation (optional).
Returns:

A tuple of Tensor objects (begin, size, bboxes).

  • <b>begin</b>: A Tensor. Has the same type as image_size. 1-D, containing [offset_height, offset_width, 0]. Provide as input to
    tf.slice.
  • <b>size</b>: A Tensor. Has the same type as image_size. 1-D, containing [target_height, target_width, -1]. Provide as input to
    tf.slice.
  • <b>bboxes</b>: A Tensor of type float32. 3-D with shape [1, 1, 4] containing the distorted bounding box.
    Provide as input to tf.image.draw_bounding_boxes.

3.42 tf.image.total_variation(images, name=None)

Calculate and return the total variation for one or more images.

The total variation is the sum of the absolute differences for neighboring
pixel-values in the input images. This measures how much noise is in the
images.

This can be used as a loss-function during optimization so as to suppress
noise in images. If you have a batch of images, then you should calculate
the scalar loss-value as the sum:
loss = tf.reduce_sum(tf.image.total_variation(images))

This implements the anisotropic 2-D version of the formula described here:

https://en.wikipedia.org/wiki/Total_variation_denoising

Args:
  • <b>images</b>: 4-D Tensor of shape [batch, height, width, channels] or
    3-D Tensor of shape [height, width, channels].
  • <b>name</b>: A name for the operation (optional).
Raises:
  • <b>ValueError</b>: if images.shape is not a 3-D or 4-D vector.
Returns:

The total variation of images.

If images was 4-D, return a 1-D float Tensor of shape [batch] with the
total variation for each image in the batch.
If images was 3-D, return a scalar float with the total variation for
that image.

- - -

###3.4 tf.image.decode_png(contents, channels=None, dtype=None, name=None)

將PNG編碼的圖片解碼成uint8或uint16的tensor。

參數 `channels`表示解碼圖片期望的顏色通道數。 可配置的值為:
- 0: 使用JPEG編碼圖片本身的通道數。
- 1: 輸出灰度圖片
- 3: 輸出RGB格式圖片
- 4: 輸出RGBA格式圖片

##### 參數:
*  <b>`contents`</b>: PNG編碼圖片。
*  <b>`channels`</b>:  `int`類型,默認為`0`.

##### 示例:

image_decoded=tf.image.decode_png(tf.read_file('example.png'),channels=3)


- - -

###3.5 tf.image.encode_png(image, compression=None, name=None)

進行PNG圖片格式編碼。

`image` 為3維`[height, width, channels]`的uint8或uint16類型的tensor。
其中, `channels` 是:

*   1: 灰度格式
*   2: 灰度+alpha格式
*   3: RGB格式
*   4: RGBA格式

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`的uint8或uint16類型的tensor。

##### 示例:

image_decoded=tf.image.decode_png(tf.read_file('example.png'),channels=3)
enc=tf.image.encode_png(image_decoded)
fname=tf.constant('1.png')
fwrite=tf.write_file(fname,enc)
with tf.Session() as sess:
result=sess.run(fwrite)


- - -

###3.6 tf.image.decode_image(contents, channels=None, name=None)

對`decode_gif`, `decode_jpeg`, and `decode_png`進行簡化的函數,自動檢測圖片是GIG,JPEG或PNG。

注意: `decode_gif` 返回的是4維`[num_frames, height, width, 3]矩陣,而
 `decode_jpeg` 和 `decode_png`返回的是3維`[height, width, num_channels]`矩陣。

##### 參數:
*  <b>`contents`</b>:  `string`類型。
*  <b>`channels`</b>: `int`類型,默認為`0`。
- - -

###3.7 tf.image.resize_images(images, size, method=0, align_corners=False)

使用方法`method`,將`images`大小調整至`size`,

調整圖片大小可能造成圖片扭曲,可以使用函數`resize_image_with_crop_or_pad`避免。

支持的方法`method` 如下:

*   <b>`ResizeMethod.BILINEAR`</b>:雙線性插值法。
*   <b>`ResizeMethod.NEAREST_NEIGHBOR`</b>: 臨近插值法。
*   <b>`ResizeMethod.BICUBIC`</b>: 雙三次插值法。
*   <b>`ResizeMethod.AREA`</b>:面積插值法。

##### 參數:
*  <b>`images`</b>: 4維`[batch, height, width, channels]` 或3維 `[height, width, channels]`張量。
*  <b>`size`</b>: 只含兩個值的1維張量`new_height, new_width`,圖片的新尺寸。
*  <b>`method`</b>: 調整大小方法,默認為 `ResizeMethod.BILINEAR`.
*  <b>`align_corners`</b>: bool型,默認為`false`,若為`true`, 精確對齊輸入和輸出的所有4個角。
 
##### 示例:

resize_images1=tf.image.resize_images(image_decoded,[1200,1200],method=tf.image.ResizeMethod.BILINEAR)

輸出為float類型。


- - -

###3.8 tf.image.resize_area(images, size, align_corners=None, name=None)

通過面積插值法將 `images`大小調整至`size`,輸出為float類型。

##### 參數:
*  <b>`images`</b>: 可以為一下類型的4維 `[batch, height, width, channels]`tensor, `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
*  <b>`size`</b>: 只含兩個值的1維張量`new_height, new_width`,圖片的新尺寸。
- - -

###3.9 tf.image.resize_bicubic(images, size, align_corners=None, name=None)

通過雙三次插值法將 `images`大小調整至`size`,輸出為float類型。

##### 參數:
*  <b>`images`</b>: 可以為一下類型的4維 `[batch, height, width, channels]`tensor, `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
*  <b>`size`</b>: 只含兩個值的1維張量`new_height, new_width`,圖片的新尺寸。
- - -

###3.10 tf.image.resize_bilinear(images, size, align_corners=None, name=None)

通過雙線性插值法將 `images`大小調整至`size`,輸出為float類型。

##### 參數:
*  <b>`images`</b>: 可以為一下類型的4維 `[batch, height, width, channels]`tensor, `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
*  <b>`size`</b>: 只含兩個值的1維張量`new_height, new_width`,圖片的新尺寸。
- - -

###3.11 tf.image.resize_nearest_neighbor(images, size, align_corners=None, name=None)

通過臨近插值法將 `images`大小調整至`size`,輸出為float類型。

##### 參數:
*  <b>`images`</b>: 可以為一下類型的4維 `[batch, height, width, channels]`tensor, `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
*  <b>`size`</b>: 只含兩個值的1維張量`new_height, new_width`,圖片的新尺寸。
- - -

###3.12 tf.image.resize_image_with_crop_or_pad(image, target_height, target_width)

裁剪或擴充圖片尺寸至目標寬度以及高度。

如果圖片的`width`或`height`大于`target_width`或`target_height`,該函數會沿著對應的尺度進行中心裁剪。
如果圖片的`width`或`height`小于`target_width`或`target_height`,該函數會沿著對應的尺度進行中心擴充。

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`tensor。
*  <b>`target_height`</b>: 目標高度。
*  <b>`target_width`</b>: 目標寬度。

##### 示例:

resize_images5=tf.image.resize_image_with_crop_or_pad(image_decoded,300,300)

- - -

###3.13 tf.image.central_crop(image, central_fraction)

對圖片進行中心裁剪。

保留圖片每個尺度的中心區域,對外部進行裁剪。如果我們配置`central_fraction`為0.5,該函數只會返回下圖標識X的數據。

     --------
    |        |
    |  XXXX  |
    |  XXXX  |
    |        |  “X”是圖片50%處于中間的部分。
     --------

##### 參數:
*  <b>`image`</b>: 3維 [height, width, depth]tensor。
*  <b>`central_fraction`</b>: float (0, 1],裁剪比例。

##### 示例:

central=tf.image.central_crop(image_decoded,0.5)

- - -

###3.14 tf.image.pad_to_bounding_box(image, offset_height, offset_width, target_height, target_width)

擴展 `image` 到指定的 `height` 和`width`,擴展的部分填充0。

在圖片的上部填充`offset_height`行0元素和在圖片的左邊填充`offset_width`列0元素后,將圖片沿著下部行填充和右部列填充擴展至指定的高、寬。

##### 參數:
*  <b>`image`</b>: 3維 `[height, width, channels]`tensor。
*  <b>`offset_height`</b>: 上部增加0元素的行數。
*  <b>`offset_width`</b>: 左部增加0元素的行數。
*  <b>`target_height`</b>: 輸出圖片的高度。
*  <b>`target_width`</b>: 輸出圖片的寬度。

##### 示例:

pad_to=tf.image.pad_to_bounding_box(image_decoded,100,100,2000,2000)

- - -

###3.15 tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width)

圖片指定的范圍裁剪,保留指定范圍內的數據。

該函數從`image`中裁剪出一個長方形的區域。長方形左上角在圖片中的坐標為`offset_height, offset_width`
那么它的右下角在圖片中的坐標為`offset_height + target_height, offset_width + target_width`。

##### 參數:
*  <b>`image`</b>: 3維 `[height, width, channels]`tensor。
*  <b>`offset_height`</b>: 左上角坐標的高度值。
*  <b>`offset_width`</b>: 左上角坐標的寬度值。
*  <b>`target_height`</b>: 輸出圖片的高度。
*  <b>`target_width`</b>: 輸出圖片的寬度。

#####示例:

crop_to=tf.image.crop_to_bounding_box(image_decoded,100,100,400,400)

- - -

###3.16 tf.image.extract_glimpse(input, size, offsets, centered=None, normalized=None, uniform_noise=None, name=None)

與crop_to_bounding_box功能類似。不同之處在于,input是一組4維張量 `[batch_size, height,
width, channels]`,存有batch_size張圖片。該函數對每張圖片截取相同大小不同位置的數據。
截取后的tensor為 `[batch_size, glimpse_height,glimpse_width, channels]`。

* 若坐標不是標準化和中心指定的, 0.0 and 1.0對應最小和最大的高度或寬度。
* 若坐標是標準化和中心指定的,坐標 (-1.0, -1.0) 對應左上角,右下角對應坐標(1.0, 1.0)。
* 若坐標不是標準化,則應使用像素坐標值。

##### 參數:
*  <b>`input`</b>: 4維`[batch_size, height, width, channels]`tensor。
*  <b>`size`</b>: 1維`int32`型,表示截取窗口大小,[glimpse_height,glimpse_width]。
*  <b>`offsets`</b>: 每個截取窗口中心位置的坐標,`float32`型[batch_size,2]。
*  <b>`centered`</b>: `bool`型,默認為`True`,表明`offset`為窗口中心位置坐標;若為`False`,則表示窗口左上角坐標。
*  <b>`normalized`</b>:  `bool`型,默認為 `True`,表示偏移坐標是標準化的。
*  <b>`uniform_noise`</b>:  `bool`型,默認為 `True`,表示截取是產生噪聲。

##### 示例:

size=tf.Variable([200,200])
offsets=tf.constant([[64,64],[159,155],[400,600]],dtype=tf.float32)
extract_glimpse=tf.image.extract_glimpse(images,size,offsets,centered=False,normalized=False,uniform_noise=False)

- - -

###3.17 tf.image.crop_and_resize(image, boxes, box_ind, crop_size, method=None, extrapolation_value=None, name=None)

類似于`crop_to_bounding_box`,不同之處在于,本函數在裁剪后將所有圖片重新調整為指定尺寸,指定尺寸由參數`crop_size`獲取。

##### 參數:
*  <b>`image`</b>:4維`[batch, image_height, image_width, depth]`tensor。
*  <b>`boxes`</b>: 2維`[num_boxes, 4]` `float32`類型tensor。第‘i’行為標準化坐標`[y1, x1, y2, x2]`,標準化坐標值`y`對應圖片坐標`y * (image_height - 1)`,因此,[0,1]對應圖片`[0, image_height - 1]。通常,要求y2>y1,x2>x1。
*  <b>`box_ind`</b>: 1維`[num_boxes] `int32`型tensor,取值范圍`[0, batch)`。該值指定box對應第幾張圖片。
*  <b>`crop_size`</b>: 1維`size = [crop_height, crop_width]``int32`型tensor,所有裁剪后的圖片尺寸將全部改變為該值。
*  <b>`method`</b>: 調整圖片大小的方法,默認為 `bilinear`,目前也只支持這種方法。



- - -

###3.18 tf.image.flip_up_down(image)

將圖片上下翻轉。即翻轉坐標為`height`。

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`tensor。


- - -

###3.19 tf.image.random_flip_up_down(image, seed=None)

隨機將圖片進行上下翻轉,翻轉概率為50%。

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`tensor。
*  <b>`seed`</b>: 隨機種子,用法在constant_ops中有介紹。

- - -

###3.20 tf.image.flip_left_right(image)

將圖片左右翻轉。即翻轉坐標為`width`。

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`tensor。

##### 示例:

flip_left_right=tf.image.flip_left_right(image_decoded)

- - -

###3.21 tf.image.random_flip_left_right(image, seed=None)

隨機將圖片進行左右翻轉,翻轉概率為50%。

##### 參數:
*  <b>`image`</b>: 3維`[height, width, channels]`tensor。
*  <b>`seed`</b>:  隨機種子,用法在constant_ops中有介紹。




- - -

###3.22 tf.image.transpose_image(image)

對圖片第一第二維度進行轉置操作。

##### 參數:

*  <b>`image`</b>:3維`[height, width, channels]`tensor。完成為3維`[width,height, channels]`tensor。

##### 示例:

transpose_image=tf.image.transpose_image(image_decoded)

- - -

###3.23 tf.image.rot90(image, k=1, name=None)

將圖片逆時針旋轉,步長為90度。

##### 參數:
*  <b>`image`</b>:3維`[height, width, channels]`tensor。
*  <b>`k`</b>:旋轉倍率,默認為1。圖片旋轉角度為`k*90`。 

##### 示例:

rot180=tf.image.rot90(image_decoded,k=2)

- - -

###3.24 tf.image.rgb_to_grayscale(images, name=None)

將一個或多個圖片由RGB模式轉化為灰度模式。 
##### 參數:
*  <b>`images`</b>: RGB tensor,最末維度必須為3,對應RGB三個通道。

- - -

###3.25 tf.image.grayscale_to_rgb(images, name=None)

將一個或多個圖片由灰度模式轉化為RGB模式。 
##### 參數:
*  <b>`images`</b>: 灰度 tensor,最末維度必須為1。

- - -

###3.26 tf.image.hsv_to_rgb(images, name=None)

將一個或多個圖片由HSV模式轉化為RGB模式。 
##### 參數:
*  <b>`images`</b>: 最后一個維度必須為3。
- - -

###3.27 tf.image.rgb_to_hsv(images, name=None)

將一個或多個圖片由RGB模式轉化為HSV模式。 
##### 參數:
*  <b>`images`</b>: 最后一個維度必須為3。

- - -

###3.28 `tf.image.convert_image_dtype(image, dtype, saturate=False, name=None)

轉化圖片數據類型至`dtype`。并將數據歸一為 [0,1)。
##### 參數:


*  <b>`image`</b>: 圖片
*  <b>`dtype`</b>: 將要轉化成的數據類型。
*  <b>`saturate`</b>: 如果 `True`,在轉化前裁剪越限的值

##### 示例:

image_decoded=tf.image.decode_png(tf.read_file('871002.png'),channels=1)
max1=tf.reduce_max(image_decoded)#max1=215
convert=tf.image.convert_image_dtype(image_decoded,tf.float32)
max=tf.reduce_max(convert)#max=0.843137(215/255)

- - -

###3.29 tf.image.adjust_brightness(image, delta)

調整RGB或灰度圖的明暗度。

在運算前,image和delta都先轉換為float類型,運算完成后再返回初始類型。delta取值范圍為[0,1)。
##### 參數:
*  <b>`image`</b>:  tensor.
*  <b>`delta`</b>: image_out=image*delta。

##### 示例:

adjust_brightness=tf.image.adjust_brightness(image_decoded,0.4)


- - -

###3.30 tf.image.random_brightness(image, max_delta, seed=None)

隨機調整RGB或灰度圖的明暗度。隨機值范圍 `[-max_delta, max_delta)`。

##### 參數:
*  <b>`image`</b>:image.
*  <b>`max_delta`</b>: float, 必須為非負。
*  <b>`seed`</b>: 種子。
- - -

###3.31 tf.image.adjust_contrast(images, contrast_factor)
調整RGB或灰度圖的對比度。

在運算前,image和delta都先轉換為float類型,運算完成后再返回初始類型。

對圖片而言,每個通道的對比度調節是獨立的。該函數先計算該通道像素平均值mean,而后對每個值進行運算
`(x - mean) * contrast_factor + mean`.

##### 參數:
*  <b>`images`</b>: Images,至少為 3維。
*  <b>`contrast_factor`</b>: 調整因子。

##### 示例:

adjust_contrast=tf.image.adjust_contrast(image_decoded,0.4)

- - -

###3.32 tf.image.random_contrast(image, lower, upper, seed=None)

隨機調整RGB或灰度圖的對比度。對比于`adjust_contrast`,`contrast_factor`從`[lower,upper]`中隨機取值。
##### 參數:

*  <b>`image`</b>: Images,至少為 3維。
*  <b>`lower`</b>: float.  隨機調整因子的最低值。
*  <b>`upper`</b>: float.  隨機調整因子的最高值。
*  <b>`seed`</b>:種子。

- - -

###3.33 tf.image.adjust_hue(image, delta, name=None)

調節RGB圖像的色彩。

該函數將圖片先轉換為float類型,之而轉換為HSV模式,對HSV模式中的hue通道進行運算,完成后再轉回RGB模式,乃至原始數據類型。

##### 參數:
*  <b>`image`</b>: RGB格式圖片,最末尺度必須為3。
*  <b>`delta`</b>: float.  添加到hue通道的值,必須在[-1,1]之間。

##### 示例:

adjust_hue=tf.image.adjust_hue(image_decoded,delta=0.4)

- - -

###3.34 tf.image.random_hue(image, max_delta, seed=None)

隨機調節RGB圖像的色彩。隨機delta值,范圍為`[-max_delta, max_delta]`.

##### 參數:
*  <b>`image`</b>: RGB格式圖片,最末尺度必須為3。
*  <b>`max_delta`</b>: float. 最大delta。
*  <b>`seed`</b>: 種子。
- - -

###3.35 tf.image.adjust_gamma(image, gamma=1, gain=1)

進行灰度矯正。Out = In*gamma。

若gamma>1,圖片將變暗;若gamma<1,圖片將變亮;

##### 參數:

*  image : A Tensor.
*  gamma : A scalar. 非負實數。
*  gain  : A scalar. The constant multiplier.

##### 示例:

adjust_gamma=tf.image.adjust_gamma(tf.cast(image_decoded,dtype=tf.float32),0.8)


- - -

###3.36 tf.image.adjust_saturation(image, saturation_factor, name=None)
調節RGB圖像的飽和度。

該函數將圖片先轉換為float類型,之而轉換為HSV模式,對HSV模式中的saturation通道進行運算,完成后再轉回RGB模式,乃至原始數據類型。

##### 參數:

*  <b>`image`</b>:  RGB格式圖片,最末尺度必須為3。
*  <b>`saturation_factor`</b>: float. 飽和因子。

##### 示例:

adjust_saturation=tf.image.adjust_saturation(image_decoded,0.4)

- - -

###3.37 tf.image.random_saturation(image, lower, upper, seed=None)

隨機調節RGB圖像的飽和度。`saturation_factor`隨機在`[lower,upper]`中取值。

##### 參數:
*  <b>`image`</b>: RGB image or images. Size of the last dimension must be 3.
*  <b>`lower`</b>: float. 飽和因子最小值。
*  <b>`upper`</b>: float. 飽和因子最大值。
*  <b>`seed`</b>: 種子。

- - -

###
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 責任鏈模式 使多個對象都有機會處理請求,從而避免請求的發送者和接收者之間發生耦合。此模式將這些對象連成一條鏈,并沿...
    863cda997e42閱讀 260評論 0 0
  • 年少輕狂 無知才會高傲,好像確實如此。不知天高地厚,才不懂謙卑
    100斤閱讀 241評論 0 0
  • 金是先生上中學時的同桌,他們有許多年未見過面。如果不是加微信,通過微信上聊天,在微信上看到彼此的照片,估計他們在大...
    新月如水閱讀 4,113評論 30 25