1.第一版
import numpy as np
import matplotlib. pyplot as plt
import tensorflow as tf
np. set_printoptions( threshold= np. inf)
def show_image ( image) :
shape = np. shape( image)
if len ( shape) == 3 and shape[ 2 ] == 1 :
plt. imshow( image[ : , : , 0 ] , cmap= 'gray' )
plt. show( )
elif len ( shape) == 3 :
plt. imshow( image)
plt. show( )
sess = tf. InteractiveSession( )
image_path = "./images/xiaoren.png"
"""
def read_file(filename, name=None):
filename:给定一个待读取文件的路径
"""
file_contents = tf. read_file( image_path)
print ( 'todo2-**' * 40 )
"""
def decode_image(contents, channels=None, name=None):
将图像数据转换为像素点的数据格式,返回对象为: [height, width, num_channels],
如果是gif的图像返回[num_frames, height, width, num_channels]
height: 图片的高度的像素大小
width: 图片的水平宽度的像素大小
num_channels: 图像的通道数,也就是API中的channels的值
num_frames: 因为gif的图像是一个动态图像,可以将每一个动的画面看成一个静态图像,num_frames相当于在这个gif图像中有多少个静态图像
一、contents: 给定具体的数据对象
二、参数channels:可选值:0 1 3 4,默认为0, 一般使用0 1 3,不建议使用4
0:使用图像的默认通道,也就是图像是几通道的就使用几通道
1:使用灰度级别的图像数据作为返回值(只有一个通道:黑白)
3:使用RGB三通道读取数据
4:使用RGBA四通道读取数据(R:红色,G:绿色,B:蓝色,A:透明度)
"""
image_tensor = tf. image. decode_image( contents= file_contents, channels= 3 )
image_tensor = tf. image. decode_png( contents= file_contents, channels= 3 , dtype= tf. uint8)
print ( '原始数据shape is:{}' . format ( image_tensor. eval ( ) . shape) )
image_tensor = tf. image. decode_gif( contents= file_contents)
print ( "原始数据形状:{}" . format ( np. shape( image_tensor. eval ( ) ) ) )
"""
def resize_images(images,
size,
method=ResizeMethod.BILINEAR,
align_corners=False):
重置大小,放大或者缩小
images: 给定需要进行大小重置的tensor对象,shape要求为: [batch_size, height, width, channel] 或者 [height, width, channel]; 表示可以一次对很多图像做大小重置,也可以仅仅对一个图像做一个大小重置操作;
size:给定一个二元组,也就是(new_height, new_width)
method: 做一个放大和缩小的时候,采用什么算法放大缩小(如何产生新的像素点的值)
class ResizeMethod(object):
BILINEAR = 0 # 默认值,二次线性插值
NEAREST_NEIGHBOR = 1 # 使用邻居的像素值作为新的像素值
BICUBIC = 2 # 三次插值,一般建议使用BICUBIC,但是运行速度比较慢。
AREA = 3 # 使用一个区域的所有颜色的均值作为新的像素值
返回的数据类型和输入的images的数据shape格式一致
"""
resize_image_tensor = tf. image. resize_images(
images= image_tensor, size= ( 128 , 80 ) ,
method= tf. image. ResizeMethod. NEAREST_NEIGHBOR)
float_image_tensor = tf. image. convert_image_dtype( image_tensor, dtype= tf. float32)
resize_image_tensor = tf. image. resize_images(
images= float_image_tensor, size= ( 128 , 80 ) , method= 3 )
print ( "todo3-rize后的数据形状:{}" . format ( resize_image_tensor. eval ( ) . shape) )
show_image( resize_image_tensor. eval ( ) )
"""
def resize_image_with_crop_or_pad(image, target_height, target_width):
image:需要进行操作的图像tensor对象
target_height, target_width: 新图像的高度和宽度
做填充和剪切的时候,是从中心位置开始计算
"""
crop_or_pad_image_tensor = tf. image. resize_image_with_crop_or_pad( image_tensor,
target_height= 800 ,
target_width= 200 )
print ( "4-crop后的数据形状:{}" . format ( np. shape( crop_or_pad_image_tensor. eval ( ) ) ) )
show_image( crop_or_pad_image_tensor. eval ( ) )
central_crop_image_tensor = tf. image. central_crop( image_tensor, central_fraction= 0.6 )
print ( "4-central_crop后的数据形状:{}" . format ( np. shape( central_crop_image_tensor. eval ( ) ) ) )
show_image( central_crop_image_tensor. eval ( ) )
"""
def crop_to_bounding_box(image, offset_height, offset_width, target_height,
target_width):
offset_height:给定从高度那个位置进行剪切,其实给定的是剪切的左上角的像素下标
offset_width: 给定从宽度那个维度进行剪切,其实给定的是剪切的左上角的像素下标
"""
crop_to_bounding_box_image_tensor = tf. image. crop_to_bounding_box(
image_tensor, 100 , 20 , 500 , 490
)
print ( "4-crop_to_bounding后数据形状:{}" . format ( np. shape( crop_to_bounding_box_image_tensor. eval ( ) ) ) )
show_image( crop_to_bounding_box_image_tensor. eval ( ) )
"""
def pad_to_bounding_box(image, offset_height, offset_width, target_height,
target_width):
"""
flip_up_down_image_tensor = tf. image. flip_up_down( image_tensor)
print ( "5上下交换-flip_up_down后形状:{}" . format ( np. shape( flip_up_down_image_tensor. eval ( ) ) ) )
show_image( flip_up_down_image_tensor. eval ( ) )
flip_left_right_image_tensor = tf. image. flip_left_right( image_tensor)
print ( "5左右交换-新的数据形状:{}" . format ( np. shape( flip_left_right_image_tensor. eval ( ) ) ) )
show_image( flip_left_right_image_tensor. eval ( ) )
transpose_image_tensor = tf. image. transpose_image( image_tensor)
print ( "5转置(行,列互换)transpose_image后形状:{}" . format ( np. shape( transpose_image_tensor. eval ( ) ) ) )
show_image( transpose_image_tensor. eval ( ) )
random_int = np. random. randint( low= 0 , high= 3 )
rot90_image_tensor = tf. image. rot90( image_tensor, k= random_int)
print ( "5旋转-新的数据形状:{}" . format ( np. shape( rot90_image_tensor. eval ( ) ) ) )
show_image( rot90_image_tensor. eval ( ) )
float_image_tensor = tf. image. convert_image_dtype( image_tensor, dtype= tf. float32)
gray_image_tensor = tf. image. rgb_to_grayscale( float_image_tensor)
print ( "6-新的数据形状:{}" . format ( np. shape( gray_image_tensor. eval ( ) ) ) )
show_image( gray_image_tensor. eval ( ) )
hsv_image_tensor = tf. image. rgb_to_hsv( float_image_tensor)
print ( "6-新的数据形状:{}" . format ( np. shape( hsv_image_tensor. eval ( ) ) ) )
show_image( hsv_image_tensor. eval ( ) )
rgb_image_tensor = tf. image. hsv_to_rgb( hsv_image_tensor)
print ( "6-新的数据形状:{}" . format ( np. shape( rgb_image_tensor. eval ( ) ) ) )
show_image( rgb_image_tensor. eval ( ) )
rgb_image_tensor = tf. image. grayscale_to_rgb( gray_image_tensor)
print ( "6-新的数据形状:{}" . format ( np. shape( rgb_image_tensor. eval ( ) ) ) )
show_image( rgb_image_tensor. eval ( ) )
a = gray_image_tensor
b = tf. less_equal( a, 0.9 )
"""
def where(condition, x=None, y=None, name=None):
condition: 给定一个bool数据组成的tensor对象
x:当condition中的值为true的时候,返回的值
y:当condition中的值为false的时候,返回的值
NOTE: 要求condition、x、y的数据形状是一致的
"""
c = tf. where( condition= b, x= a, y= a - a)
d = tf. where( condition= b, x= tf. ones_like( c) , y= c)
print ( "6-新的数据形状:{}" . format ( np. shape( d. eval ( ) ) ) )
show_image( d. eval ( ) )
"""
def adjust_brightness(image, delta):
image: 需要调整的图像tensor对象
delta:调整的参数值,取值范围:(-1,1); 该值表示亮度增加或者减少的值。
底层是将image转换为hsv格式的数据,然后再进行处理。# rgb -> hsv -> h,s,v+delta -> rgb
"""
adjust_brightness_image_tensor = tf. image. adjust_brightness( image_tensor, delta= - 0.5 )
print ( "7亮度调整-新的数据形状:{}" . format ( np. shape( adjust_brightness_image_tensor. eval ( ) ) ) )
show_image( adjust_brightness_image_tensor. eval ( ) )
adjust_hue_image_tensor = tf. image. adjust_hue( image_tensor, delta= - 0.8 )
print ( "7色调调整-新的数据形状:{}" . format ( np. shape( adjust_hue_image_tensor. eval ( ) ) ) )
show_image( adjust_hue_image_tensor. eval ( ) )
adjust_saturation_image_tensor = tf. image. adjust_saturation( image_tensor, saturation_factor= 20 )
print ( "7饱和度调整-新的数据形状:{}" . format ( np. shape( adjust_saturation_image_tensor. eval ( ) ) ) )
show_image( adjust_saturation_image_tensor. eval ( ) )
adjust_contrast_image_tensor = tf. image. adjust_contrast( image_tensor, contrast_factor= 100 )
print ( "7对比度调整-新的数据形状:{}" . format ( np. shape( adjust_contrast_image_tensor. eval ( ) ) ) )
show_image( adjust_contrast_image_tensor. eval ( ) )
adjust_gamma_image_tensor = tf. image. adjust_gamma( float_image_tensor, gamma= 100 )
print ( "7图像的校验-新的数据形状:{}" . format ( np. shape( adjust_gamma_image_tensor. eval ( ) ) ) )
show_image( adjust_gamma_image_tensor. eval ( ) )
noisy_image_tensor = image_tensor + tf. cast( 5 * tf. random_normal( shape= [ 600 , 510 , 3 ] , mean= 0 , stddev= 0.1 ) , tf. uint8)
print ( "7给图像加一个噪音-新的数据形状:{}" . format ( np. shape( noisy_image_tensor. eval ( ) ) ) )
show_image( noisy_image_tensor. eval ( ) )
from scipy. misc import imsave, imread, imresize, imshow, imfilter, imrotate
file_path = "./images/xiaoren.png"
img = imread( file_path)
img = imresize( img, size= ( 200 , 200 ) )
imsave( '小人儿.png' , img)
print ( type ( img) )
print ( np. shape( img) )
print ( 'done!!' )
D: \Anaconda\python. exe D: / AI20/ HJZ/ 04 - 深度学习/ 3 - CNN/ 20191207 / 04_02基于TF的图像预处理相关的API. py
todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- ** todo2- **
2019 - 12 - 29 12 : 48 : 23.672201 : I tensorflow/ core/ platform/ cpu_feature_guard. cc: 141 ] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
原始数据shape is : ( 600 , 510 , 3 )
原始数据形状: ( 1 , 600 , 510 , 3 )
todo3- rize后的数据形状: ( 1 , 128 , 80 , 3 )
4 - crop后的数据形状: ( 1 , 800 , 200 , 3 )
4 - central_crop后的数据形状: ( 1 , 360 , 306 , 3 )
4 - crop_to_bounding后数据形状: ( 1 , 500 , 490 , 3 )
5 上下交换- flip_up_down后形状: ( 1 , 600 , 510 , 3 )
5 左右交换- 新的数据形状: ( 1 , 600 , 510 , 3 )
5 转置( 行,列互换) transpose_image后形状: ( 1 , 510 , 600 , 3 )
5 旋转- 新的数据形状: ( 1 , 600 , 510 , 3 )
6 - 新的数据形状: ( 1 , 600 , 510 , 1 )
6 - 新的数据形状: ( 1 , 600 , 510 , 3 )
6 - 新的数据形状: ( 1 , 600 , 510 , 3 )
6 - 新的数据形状: ( 1 , 600 , 510 , 3 )
6 - 新的数据形状: ( 1 , 600 , 510 , 1 )
7 亮度调整- 新的数据形状: ( 1 , 600 , 510 , 3 )
7 色调调整- 新的数据形状: ( 1 , 600 , 510 , 3 )
7 饱和度调整- 新的数据形状: ( 1 , 600 , 510 , 3 )
7 对比度调整- 新的数据形状: ( 1 , 600 , 510 , 3 )
WARNING: tensorflow: tf. op_scope( values, name, default_name) is deprecated, use tf. name_scope( name, default_name, values)
7 图像的校验- 新的数据形状: ( 1 , 600 , 510 , 3 )
7 给图像加一个噪音- 新的数据形状: ( 1 , 600 , 510 , 3 )
< class 'numpy.ndarray' >
( 200 , 200 , 3 )
done!!
Process finished with exit code 0
2.第二版
import numpy as np
import matplotlib. pyplot as plt
import tensorflow as tf
np. set_printoptions( threshold= np. inf)
def show_image ( image) :
shape = np. shape( image)
if len ( shape) == 3 and shape[ 2 ] == 1 :
plt. imshow( image[ : , : , 0 ] , cmap= 'gray' )
plt. show( )
elif len ( shape) == 3 :
plt. imshow( image)
plt. show( )
sess = tf. InteractiveSession( )
image_path = r"C:\Users\hjz\python-project\project\02_lianxi\02_FaceDetecton/3.jpg"
"""
def read_file(filename, name=None):
filename:给定一个待读取文件的路径
"""
file_contents = tf. read_file( image_path)
print ( '**' * 40 )
"""
def decode_image(contents, channels=None, name=None):
将图像数据转换为像素点的数据格式,返回对象为: [height, width, num_channels],
如果是gif的图像返回[num_frames, height, width, num_channels]
height: 图片的高度的像素大小
width: 图片的水平宽度的像素大小
num_channels: 图像的通道数,也就是API中的channels的值
num_frames: 因为gif的图像是一个动态图像,可以将每一个动的画面看成一个静态图像,num_frames相当于在这个gif图像中有多少个静态图像
一、contents: 给定具体的数据对象
二、参数channels:可选值:0 1 3 4,默认为0, 一般使用0 1 3,不建议使用4
0:使用图像的默认通道,也就是图像是几通道的就使用几通道
1:使用灰度级别的图像数据作为返回值(只有一个通道:黑白)
3:使用RGB三通道读取数据
4:使用RGBA四通道读取数据(R:红色,G:绿色,B:蓝色,A:透明度)
"""
image_tensor = tf. image. decode_image( contents= file_contents, channels= 3 )
show_image( image_tensor. eval ( ) )
image_tensor_0 = tf. image. decode_image( contents= file_contents, channels= 3 )
image_tensor = tf. image. decode_png( contents= file_contents, channels= 3 , dtype= tf. uint8)
print ( '1原始数据shape is:{}' . format ( image_tensor. eval ( ) . shape) )
show_image( image_tensor. eval ( ) )
image_tensor = tf. image. decode_gif( contents= file_contents)
print ( "2原始数据形状:{}" . format ( np. shape( image_tensor. eval ( ) ) ) )
"""
def resize_images(images,
size,
method=ResizeMethod.BILINEAR,
align_corners=False):
重置大小,放大或者缩小
images: 给定需要进行大小重置的tensor对象,shape要求为: [batch_size, height, width, channel] 或者 [height, width, channel]; 表示可以一次对很多图像做大小重置,也可以仅仅对一个图像做一个大小重置操作;
size:给定一个二元组,也就是(new_height, new_width)
method: 做一个放大和缩小的时候,采用什么算法放大缩小(如何产生新的像素点的值)
class ResizeMethod(object):
BILINEAR = 0 # 默认值,二次线性插值
NEAREST_NEIGHBOR = 1 # 使用邻居的像素值作为新的像素值
BICUBIC = 2 # 三次插值,一般建议使用BICUBIC,但是运行速度比较慢。
AREA = 3 # 使用一个区域的所有颜色的均值作为新的像素值
返回的数据类型和输入的images的数据shape格式一致
"""
resize_image_tensor = tf. image. resize_images(
images= image_tensor, size= ( 128 , 80 ) ,
method= tf. image. ResizeMethod. NEAREST_NEIGHBOR)
float_image_tensor = tf. image. convert_image_dtype( image_tensor, dtype= tf. float32)
resize_image_tensor = tf. image. resize_images(
images= float_image_tensor, size= ( 128 , 80 ) , method= 3 )
print ( "3 rize后的数据形状:{}" . format ( resize_image_tensor. eval ( ) . shape) )
show_image( resize_image_tensor. eval ( ) )
"""
def resize_image_with_crop_or_pad(image, target_height, target_width):
image:需要进行操作的图像tensor对象
target_height, target_width: 新图像的高度和宽度
做填充和剪切的时候,是从中心位置开始计算
"""
crop_or_pad_image_tensor = tf. image. resize_image_with_crop_or_pad( image_tensor,
target_height= 800 ,
target_width= 200 )
print ( "4 crop后的数据形状:{}" . format ( np. shape( crop_or_pad_image_tensor. eval ( ) ) ) )
show_image( crop_or_pad_image_tensor. eval ( ) )
central_crop_image_tensor = tf. image. central_crop( image_tensor, central_fraction= 0.6 )
print ( "5 central_crop后的数据形状:{}" . format ( np. shape( central_crop_image_tensor. eval ( ) ) ) )
show_image( central_crop_image_tensor. eval ( ) )
"""
def crop_to_bounding_box(image, offset_height, offset_width, target_height,
target_width):
offset_height:给定从高度那个位置进行剪切,其实给定的是剪切的左上角的像素下标
offset_width: 给定从宽度那个维度进行剪切,其实给定的是剪切的左上角的像素下标
"""
crop_to_bounding_box_image_tensor = tf. image. crop_to_bounding_box(
image_tensor, 100 , 20 , 500 , 490
)
print ( "6 crop_to_bounding后数据形状:{}" . format ( np. shape( crop_to_bounding_box_image_tensor. eval ( ) ) ) )
show_image( crop_to_bounding_box_image_tensor. eval ( ) )
"""
def pad_to_bounding_box(image, offset_height, offset_width, target_height,
target_width):
"""
pad_to_bounding_box_image_tensor = tf. image. pad_to_bounding_box(
crop_to_bounding_box_image_tensor, 200 , 100 , 1000 , 1000
)
print ( "7 pad_to_bounding_box数据形状:{}" . format ( np. shape( pad_to_bounding_box_image_tensor. eval ( ) ) ) )
show_image( pad_to_bounding_box_image_tensor. eval ( ) )
flip_up_down_image_tensor = tf. image. flip_up_down( image_tensor)
print ( "8-flip_up_down后形状:{}" . format ( np. shape( flip_up_down_image_tensor. eval ( ) ) ) )
show_image( flip_up_down_image_tensor. eval ( ) )
flip_left_right_image_tensor = tf. image. flip_left_right( image_tensor)
print ( "9-左右交换新的数据形状:{}" . format ( np. shape( flip_left_right_image_tensor. eval ( ) ) ) )
show_image( flip_left_right_image_tensor. eval ( ) )
transpose_image_tensor = tf. image. transpose_image( image_tensor)
print ( "10 transpose_image后形状:{}" . format ( np. shape( transpose_image_tensor. eval ( ) ) ) )
show_image( transpose_image_tensor. eval ( ) )
random_int = np. random. randint( low= 0 , high= 3 )
rot90_image_tensor = tf. image. rot90( image_tensor, k= random_int)
print ( "11 旋转后新的数据形状:{}" . format ( np. shape( rot90_image_tensor. eval ( ) ) ) )
show_image( rot90_image_tensor. eval ( ) )
float_image_tensor = tf. image. convert_image_dtype( image_tensor, dtype= tf. float32)
gray_image_tensor = tf. image. rgb_to_grayscale( float_image_tensor)
print ( "12 RGB -> Gray新的数据形状:{}" . format ( np. shape( gray_image_tensor. eval ( ) ) ) )
show_image( gray_image_tensor. eval ( ) )
hsv_image_tensor = tf. image. rgb_to_hsv( float_image_tensor)
print ( "13 RGB -> HSV新的数据形状:{}" . format ( np. shape( hsv_image_tensor. eval ( ) ) ) )
show_image( hsv_image_tensor. eval ( ) )
rgb_image_tensor = tf. image. hsv_to_rgb( hsv_image_tensor)
print ( "14 hsv -> rgb新的数据形状:{}" . format ( np. shape( rgb_image_tensor. eval ( ) ) ) )
show_image( rgb_image_tensor. eval ( ) )
rgb_image_tensor = tf. image. grayscale_to_rgb( gray_image_tensor)
print ( "16 gray -> rgb新的数据形状:{}" . format ( np. shape( rgb_image_tensor. eval ( ) ) ) )
show_image( rgb_image_tensor. eval ( ) )
a = gray_image_tensor
b = tf. less_equal( a, 0.9 )
"""
def where(condition, x=None, y=None, name=None):
condition: 给定一个bool数据组成的tensor对象
x:当condition中的值为true的时候,返回的值
y:当condition中的值为false的时候,返回的值
NOTE: 要求condition、x、y的数据形状是一致的
"""
c = tf. where( condition= b, x= a, y= a - a)
"""
def adjust_brightness(image, delta):
image: 需要调整的图像tensor对象
delta:调整的参数值,取值范围:(-1,1); 该值表示亮度增加或者减少的值。
底层是将image转换为hsv格式的数据,然后再进行处理。# rgb -> hsv -> h,s,v+delta -> rgb
"""
adjust_brightness_image_tensor = tf. image. adjust_brightness( image_tensor, delta= - 0.5 )
print ( "17 亮度调整新的数据形状:{}" . format ( np. shape( adjust_brightness_image_tensor. eval ( ) ) ) )
show_image( adjust_brightness_image_tensor. eval ( ) )
adjust_hue_image_tensor = tf. image. adjust_hue( image_tensor, delta= - 0.8 )
print ( "18 色调调整新的数据形状:{}" . format ( np. shape( adjust_hue_image_tensor. eval ( ) ) ) )
show_image( adjust_hue_image_tensor. eval ( ) )
adjust_saturation_image_tensor = tf. image. adjust_saturation( image_tensor, saturation_factor= 20 )
print ( "19 饱和度调整新的数据形状:{}" . format ( np. shape( adjust_saturation_image_tensor. eval ( ) ) ) )
show_image( adjust_saturation_image_tensor. eval ( ) )
adjust_contrast_image_tensor = tf. image. adjust_contrast( image_tensor, contrast_factor= 100 )
print ( "20 对比度调整新的数据形状:{}" . format ( np. shape( adjust_contrast_image_tensor. eval ( ) ) ) )
show_image( adjust_contrast_image_tensor. eval ( ) )
adjust_gamma_image_tensor = tf. image. adjust_gamma( float_image_tensor, gamma= 100 )
print ( "21 图像的校验新的数据形状:{}" . format ( np. shape( adjust_gamma_image_tensor. eval ( ) ) ) )
show_image( adjust_gamma_image_tensor. eval ( ) )
per_image_standardization_image_tensor = tf. image. per_image_standardization( image_tensor_0)
print ( "22 图像的归一化新的数据形状:{}" . format ( np. shape( per_image_standardization_image_tensor. eval ( ) ) ) )
show_image( per_image_standardization_image_tensor. eval ( ) )
noisy_image_tensor = image_tensor_0 + tf. cast( 5 * tf. random_normal( shape= [ 1820 , 1024 , 3 ] , mean= 0 , stddev= 0.1 ) , tf. uint8)
print ( "23 给图像加一个噪音新的数据形状:{}" . format ( np. shape( noisy_image_tensor. eval ( ) ) ) )
show_image( noisy_image_tensor. eval ( ) )
writer = tf. summary. FileWriter( "./models/test" , sess. graph)
writer. close( )
from scipy. misc import imsave, imread, imresize, imshow, imfilter, imrotate
file_path = r"C:\Users\hjz\python-project\project\02_lianxi\02_FaceDetecton/3.jpg"
img = imread( file_path)
img = imresize( img, size= ( 200 , 200 ) )
imsave( '小人儿.png' , img)
print ( type ( img) )
print ( np. shape( img) )
imsave( 'test.png' , noisy_image_tensor. eval ( ) )
print ( 'done!!' )
C: \ProgramData\Anaconda2\envs\py36\python. exe C: / Users/ hjz/ Work/ AI/ 03_DL/ 02_demo/ 01_CNN/ 04_02基于TF的图像预处理相关的API. py
C: \ProgramData\Anaconda2\envs\py36\lib\site- packages\h5py\__init__. py: 36 : FutureWarning: Conversion of the second argument of issubdtype from `float ` to `np. floating` is deprecated. In future, it will be treated as `np. float64 == np. dtype( float ) . type `.
from . _conv import register_converters as _register_converters
2020 - 08 - 03 14 : 31 : 16.040467 : I tensorflow/ core/ platform/ cpu_feature_guard. cc: 141 ] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1 原始数据shape is : ( 1820 , 1024 , 3 )
2 原始数据形状: ( 1 , 1820 , 1024 , 3 )
3 rize后的数据形状: ( 1 , 128 , 80 , 3 )
4 crop后的数据形状: ( 1 , 800 , 200 , 3 )
5 central_crop后的数据形状: ( 1 , 1092 , 616 , 3 )
6 crop_to_bounding后数据形状: ( 1 , 500 , 490 , 3 )
7 pad_to_bounding_box数据形状: ( 1 , 1000 , 1000 , 3 )
8 - flip_up_down后形状: ( 1 , 1820 , 1024 , 3 )
9 - 左右交换新的数据形状: ( 1 , 1820 , 1024 , 3 )
10 transpose_image后形状: ( 1 , 1024 , 1820 , 3 )
11 旋转后新的数据形状: ( 1 , 1820 , 1024 , 3 )
12 RGB - > Gray新的数据形状: ( 1 , 1820 , 1024 , 1 )
13 RGB - > HSV新的数据形状: ( 1 , 1820 , 1024 , 3 )
14 hsv - > rgb新的数据形状: ( 1 , 1820 , 1024 , 3 )
16 gray - > rgb新的数据形状: ( 1 , 1820 , 1024 , 3 )
17 亮度调整新的数据形状: ( 1 , 1820 , 1024 , 3 )
18 色调调整新的数据形状: ( 1 , 1820 , 1024 , 3 )
19 饱和度调整新的数据形状: ( 1 , 1820 , 1024 , 3 )
20 对比度调整新的数据形状: ( 1 , 1820 , 1024 , 3 )
WARNING: tensorflow: tf. op_scope( values, name, default_name) is deprecated, use tf. name_scope( name, default_name, values)
21 图像的校验新的数据形状: ( 1 , 1820 , 1024 , 3 )
22 图像的归一化新的数据形状: ( 1820 , 1024 , 3 )
Clipping input data to the valid range for imshow with RGB data ( [ 0 . .1 ] for floats or [ 0 . .255 ] for integers) .
23 给图像加一个噪音新的数据形状: ( 1820 , 1024 , 3 )
< class 'numpy.ndarray' >
( 200 , 200 , 3 )
done!!
Process finished with exit code 0
2.1原始图片:
2.2 归一化图片:
2.3 加噪音图片: