caffe 数据增强

15 篇文章 0 订阅

caffe中的数据增强,只发现mirror、scale、crop三种                 ( 主推1和2 )

1、skimage         http://www.zhimengzhe.com/bianchengjiaocheng/qitabiancheng/43881.html

import skimage注释:PIL和numpy等结合不好,skimage可以完美结合


2、 imgaug            https://github.com/aleju/imgaug

import imgaug as ia

from imgaug import augmenters as iaa


imgaug 依赖Required dependencies:

six
numpy
scipy
scikit-image (pip install -U scikit-image)
OpenCV (i.e. cv2)

下载并安装imgaug

python setup.py sdist
sudo pip install dist/imgaug-0.1.tar.gz
网站地址https://github.com/aleju/imgaug


git地址:https://github.com/aleju/imgaug.git



3、PIL                  http://blog.csdn.net/LordofRobots/article/details/77160191

from PIL import Image 

from PIL import ImageEnhance

#原始图像  
image = Image.open('lena.jpg')  
image.show()  
  
#亮度增强  
enh_bri = ImageEnhance.Brightness(image)  
brightness = 1.5  
image_brightened = enh_bri.enhance(brightness)  
image_brightened.show()  
  
#色度增强  
enh_col = ImageEnhance.Color(image)  
color = 1.5  
image_colored = enh_col.enhance(color)  
image_colored.show()  
  
#对比度增强  
enh_con = ImageEnhance.Contrast(image)  
contrast = 1.5  
image_contrasted = enh_con.enhance(contrast)  
image_contrasted.show()  
  
#锐度增强  
enh_sha = ImageEnhance.Sharpness(image)  
sharpness = 3.0  
image_sharped = enh_sha.enhance(sharpness)  
image_sharped.show() 

4、PCA Jittering

<span style="font-size:14px;"># -*- coding: utf-8 -*-  
  
import numpy as np  
import os  
from PIL import Image, ImageOps  
import argparse  
import random  
from scipy import misc  
  
def PCA_Jittering(path):  
    img_list = os.listdir(path)  
    img_num = len(img_list)  
      
    for i in range(img_num):  
        img_path = os.path.join(path, img_list[i])  
        img = Image.open(img_path)  
          
        img = np.asanyarray(img, dtype = 'float32')  
          
        img = img / 255.0  
        img_size = img.size / 3  
        img1 = img.reshape(img_size, 3)  
        img1 = np.transpose(img1)  
        img_cov = np.cov([img1[0], img1[1], img1[2]])  
        lamda, p = np.linalg.eig(img_cov)  
          
        p = np.transpose(p)  
          
        alpha1 = random.normalvariate(0,3)  
        alpha2 = random.normalvariate(0,3)  
        alpha3 = random.normalvariate(0,3)  
          
        v = np.transpose((alpha1*lamda[0], alpha2*lamda[1], alpha3*lamda[2]))      
        add_num = np.dot(p,v)  
          
        img2 = np.array([img[:,:,0]+add_num[0], img[:,:,1]+add_num[1], img[:,:,2]+add_num[2]])  
          
        img2 = np.swapaxes(img2,0,2)  
        img2 = np.swapaxes(img2,0,1)  
        save_name = 'pre'+str(i)+'.png'  
        save_path = os.path.join(path, save_name)  
        misc.imsave(save_path,img2)  
          
        #plt.imshow(img2)  
        #plt.show()</span> 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值