Vgg16/19-Tensorflow 的使用:对于图像的填充和剪切实验比较

Input of vgg16

img =/ 255.0

from [0, 255] to [0, 1.0]

均值:0.229

最大:0.9999

最小:0.0

VGG 16 & VGG 19

Vgg16 能识别的类别,查看:

synset.txt




裁剪法与填充法的比较

Tensorflow有图片填充的代码。

填充法实现代码:

def fill_image(img):
    h = img.shape[0]
    w = img.shape[1]
    
    is_trans = 0
    if h>w:
        is_trans = 1
        img = img.transpose((1,0,2))       
        
    h = img.shape[0]
    w = img.shape[1]
    assert( w>=h )
        
    im_add = np.zeros( (int( (w-h)/2 ), w, 3) )
    
    if is_trans:
        return np.concatenate( (im_add, img, im_add) ).transpose((1,0,2))
    else:
        return np.concatenate( (im_add, img, im_add) )



def fill_image2(img, w_target, h_target):
    w_t, h_t = w_target, h_target
    
    h = img.shape[0]
    w = img.shape[1]
    
    assert( w_t >= w )
    assert( h_t >= h )
    
    im_add = np.zeros( (h, int( (w_t-w)/2 ), 3) )
    img = np.concatenate( (im_add, img, im_add), axis=1 )

    im_add = np.zeros( (int( (h_t-h)/2 ), w_t, 3) )
    img = np.concatenate( (im_add, img, im_add) )
    
    return img



结果

使用图像填充的精度比使用图像剪切的高。对于第 4 张图片,图像中的主体(老虎)并不处于图像正中位置,使用图像剪切会去掉一些重要的部分,此时图像填充的精度明显高于图像剪切的精度。

图像填充:0.8344192,图像剪切:0.8326041

图像填充:0.89500195,图像剪切:0.871053

图像填充:0.8256433,图像剪切:0.78070647

图像填充:0.8568995,图像剪切:0.7757687



深度学习推荐
深度学习推荐

墨之科技,版权所有 © Copyright 2017-2027

湘ICP备14012786号     邮箱:ai@inksci.com