图像处理实例

import matplotlib
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import os

# 调整图片大小
os.getcwd()
img_raw_data = tf.gfile.FastGFile('cat.jpeg', 'rb').read()# 图片解码方式为(‘r’:UTF-8编码; ‘rb’:非UTF-8编码)
img_data = tf.image.decode_jpeg(img_raw_data)# 解码图片
with tf.Session() as sess:
    resized = tf.image.resize_images(img_data, [300, 300], method=0)#method:图片形状调整方法ResizeMethod.BILINEAR:默认方法,双线性插值ResizeMethod.NEAREST_NEIGHBOR:最近邻插值,ResizeMethod.BICUBIC:双三次插值,ResizeMethod.AREA:区域插值
    cat = np.asarray(resized.eval(), dtype='uint8') #变为uint8才能显示
    plt.imshow(cat)
    plt.show()
# 裁剪和填充图片
    croped = tf.image.resize_image_with_crop_or_pad(img_data, 300, 300)
    padded = tf.image.resize_image_with_crop_or_pad(img_data, 3000, 3000)
    plt.imshow(croped.eval())
    plt.show()
    plt.imshow(padded.eval())
    plt.show()

# 对角线翻转图像
    transposed = tf.image.transpose_image(img_data)
    plt.imshow(transposed.eval())
    plt.show()

# 图像色彩调整
    # 在[-max_delta, max_delta)的范围随机调整图片的亮度。
    adjusted = tf.image.random_brightness(img_data, max_delta=0.5)
    plt.imshow(adjusted.eval())
    plt.show()

# 调整图像色调饱和度
    adjusted = tf.image.adjust_hue(img_data, 0.1)
    plt.imshow(adjusted.eval())
    plt.show()

项目源代码请点击这里

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值