1. 程式人生 > >tensorflow: 影象操作

tensorflow: 影象操作

調整影象大小:

tf.image.resize_images
tf.image.resize_area
tf.image.resize_bicubic
tf.image.resize_bilinear
tf.image.resize_nearest_neighbor

resize_images是總介面,介面引數為:

tf.image.resize_images(images,size,method=ResizeMethod.BILINEAR,align_corners=False)

images: shape為[batch, height, width, channels]的4-D影象張量,或者shape為[height, width, channels]的3-D影象張量;

size: shape為[new_height, new_width]

method:

方法 介紹
ResizeMethod.BILINEAR 雙線性插值
ResizeMethod.NEAREST_NEIGHBOR 最近鄰插值
ResizeMethod.BICUBIC 雙三次插值
ResizeMethod.AREA 基於區域的插值

align_corners: 精確對準輸入輸出的四個角,False表示不精確對準

其餘四個介面引數如下:

(images,size,align_corners=False,name=None)

擷取影象一部分:

#從中間擷取一部分影象,如果擷取的部分大於原影象,則填充0
tf.image.resize_image_with_crop_or_pad(image,1000,1000)

#按比例擷取影象
tf.image.central_crop(image,0.5)

影象翻轉:

#上下翻轉
tf.image.flip_up_down(image)

#左右翻轉
tf.image.flip_left_right(image)

#對角線翻轉
tf.image.transpose_image(image)

#隨機翻轉
tf.image.random_flip_left_right(image)
tf.image.random_flip_up_down(image)

影象色彩調整(亮度、對比度、飽和度和色相):

#亮度調整
tf.image.adjust_brightness(image,-0.5)
#在[-max_delta,max_delta]內隨機調整亮度
tf.image.random_brightness(image,0.5)

#對比度調整
tf.image.adjust_contrast(image,-5)
tf.image.random_contrast(image,2,7)

#色相調整
tf.image.adjust_hue(image,0.3)
#在[-maxdelta,maxdelta]範圍內隨機調整影象的色相 maxdelat 在0-0.5的範圍內
tf.image.random_hue(image,0.4)

#飽和度調整
tf.image.adjust_saturation(image,5)
tf.image.random_saturation(image,1,10)

標準化:

#將影象均值變為0,方差變為1
tf.image.per_image_standardization(image)