(Tensorflow之十四)图像预处理

原图像

这里写图片描述

图像加载

原码:

import matplotlib.pyplot as plt
import tensorflow as tf

image_path = "/xxx/timg.jpeg"
image_data = tf.gfile.FastGFile(image_path,'r').read()


with tf.Session() as sess:
    image_data = tf.image.decode_jpeg(image_data)
    print(image_data.eval())

打印出的图像像素点

[[[254 254 254]
  [254 254 254]
  [254 254 254]
  ...,
  [254 254 254]
  [254 254 254]
  [254 254 254]]
 [[254 254 254]
  [254 254 254]
  [254 254 254]
  ...,
  [254 254 254]
  [254 254 254]
  [254 254 254]]
 [[254 254 254]
  [254 254 254]
  [254 254 254]
  ...,

图像修剪

    resize_image = tf.image.resize_images(image_data,[50,50],method=1)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

    resize_image = tf.image.resize_image_with_crop_or_pad(image_data,400,400)
    plt.imshow(resize_image.eval())
    plt.show()
    resize_image = tf.image.resize_image_with_crop_or_pad(image_data,600,600)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

图像翻转

    resize_image = tf.image.flip_left_right(image_data)
    plt.imshow(resize_image.eval())
    plt.show()
    resize_image = tf.image.flip_up_down(image_data)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

图像亮度调整

    resize_image = tf.image.adjust_brightness(image_data,-0.5)
    plt.imshow(resize_image.eval())
    plt.show()
    resize_image = tf.image.adjust_brightness(image_data,+0.5)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

图像对比度调整

    resize_image = tf.image.adjust_contrast(image_data,3)
    plt.imshow(resize_image.eval())
    plt.show()
    resize_image = tf.image.adjust_contrast(image_data,-3)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

图像饱和度调整

    resize_image = tf.image.adjust_saturation(image_data,-3)
    plt.imshow(resize_image.eval())
    plt.show()
    resize_image = tf.image.adjust_saturation(image_data,3)
    plt.imshow(resize_image.eval())
    plt.show()

这里写图片描述

图像存储

resize_image = tf.image.adjust_saturation(image_data,3)
encode_image = tf.image.encode_jpeg(resize_image)
with tf.gfile.GFile("/home/abig/vscode/project1/save.jpeg","wb") as f:
f.write(encode_image.eval())

存储后的图片
这里写图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值