美文网首页图像识别之-特征提取
tensorflow接口研读image_op

tensorflow接口研读image_op

作者: 华夏意匠 | 来源:发表于2017-05-23 22:27 被阅读1207次

    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>: 种子。
    
    - - -
    
    ###

    相关文章

      网友评论

        本文标题:tensorflow接口研读image_op

        本文链接:https://www.haomeiwen.com/subject/mumtxxtx.html