Tensorflow-图像增强api的使用

图片的缩放

#resize

#tf.image.resize_area
#tf.image.resize_bicubic //二次线性函数缩放
#tf.image.resize_nearest_neighbor  //使用最相似的像素点缩放
name = './图片.jgp'
img_string = tf.read_file(name)
img_decoded = tf.image.decode_image(img_string)
img_decoded = tf.reshape(img_decoded,[1,365,600,3]) //由3维矩阵变为4维

resize_img  = tf.image.resize_bicubic(img_decoded,[730,1200])

sess = tf.Session()
img_decoded_val = sess.run(resize_img)
img_decoded_val = img_decoded_val.reshape([730,1200,3]) //height:700 weight:1200 passageway:3
img_decoded_val = np.asarrary(img_decoded_val, np.uint8)

printf img_decoded_val.shape

%img_decoded_val
imgshow(img_decoded_val)

图片的裁剪

#crop

#tf.image.pad_to_bounding_box //填充
#tf.image.crop_to_bounding_box  //裁剪
#tf.random_crop //随机裁剪

name = './图片.jgp'
img_string = tf.read_file(name)
img_decoded = tf.image.decode_image(img_string)
img_decoded = tf.reshape(img_decoded,[1,365,600,3]) //由3维矩阵变为4维

padded_img  = tf.image.pad_to_bounding_box(img_decoded,[50, 100 , 500, 800]) //x:50 y:100

sess = tf.Session()
img_decoded_val = sess.run(padded_img)
img_decoded_val = img_decoded_val.reshape([800, 800, 3]) //height:700 weight:1200 passageway:3
img_decoded_val = np.asarrary(img_decoded_val, np.uint8)

printf img_decoded_val.shape

%img_decoded_val
imgshow(img_decoded_val)

图片的翻转

#flip

#tf.image.flip_up_down
#tf.image.flip_left_right
#tf.image.random_flip_up_down
#tf.image.random_flop_lefr_right

name = './图片.jgp'
img_string = tf.read_file(name)
img_decoded = tf.image.decode_image(img_string)
img_decoded = tf.reshape(img_decoded,[1,365,600,3]) //由3维矩阵变为4维

flip_img  = tf.image.flip_up_down(img_decoded)

sess = tf.Session()
img_decoded_val = sess.run(resize_img)
img_decoded_val = img_decoded_val.reshape([365, 600]) //height:700 weight:1200 passageway:3
img_decoded_val = np.asarrary(img_decoded_val, np.uint8)

printf img_decoded_val.shape

%img_decoded_val
imgshow(img_decoded_val)

改变光照

#brightness

#tf.image.adjust_brightness
#tf.image.random_brightness
#tf.image.adjust_constrast
#tf.image.random_constrast

name = './图片.jgp'
img_string = tf.read_file(name)
img_decoded = tf.image.decode_image(img_string)
img_decoded = tf.reshape(img_decoded,[1,365,600,3]) //由3维矩阵变为4维

flip_img  = tf.image.adjust_brightness(img_decoded, -0.5) //-0.5光照降低50% 0.5增强50%

sess = tf.Session()
img_decoded_val = sess.run(resize_img)
img_decoded_val = img_decoded_val.reshape([365, 600]) //height:700 weight:1200 passageway:3
img_decoded_val = np.asarrary(img_decoded_val, np.uint8)

printf img_decoded_val.shape

%img_decoded_val
imgshow(img_decoded_val)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值