神经网络训练中图像数据预处理的一些方式(一)
来源:互联网 发布:苹果屏幕录像软件 编辑:程序博客网 时间:2024/05/22 06:49
神经网络训练中图像数据预处理的一些方式
1. crop
1. 1 对于有黑色背景的图片,将数据crop在有效区域内
对于一些有黑色背景的图片,如下图:
这样的图片在做数据预处理的时候,黑色背景的无效区域,带来了很大的运算量开销。面对这种图片,我们一般先将区域限制到它的有效区域。
代码如下:
import numpy as npfrom skimage.filters import threshold_otsufrom skimage import measure, exposureimport skimagedef tight_crop(img, size=None): img_gray = np.mean(img, 2) img_bw = img_gray > threshold_otsu(img_gray) img_label = measure.label(img_bw, background=0) largest_label = np.argmax(np.bincount(img_label.flatten())[1:])+1 img_circ = (img_label == largest_label) img_xs = np.sum(img_circ, 0) img_ys = np.sum(img_circ, 1) xs = np.where(img_xs>0) ys = np.where(img_ys>0) x_lo = np.min(xs) x_hi = np.max(xs) y_lo = np.min(ys) y_hi = np.max(ys) img_crop = img[y_lo:y_hi, x_lo:x_hi, :] return img_cropimport scipy.miscfrom PIL import Imageimg = scipy.misc.imread('./raw1.jpg')img = img.astype(np.float32)img /= 255img_crop = tight_crop(img)pilImage = Image.fromarray(skimage.util.img_as_ubyte(img_crop))pilImage.show()
结果如下:
2. 对比度
接1,有一些图像可能比较模糊,对比度增强可能有很好的效果。对比度增强的方式很多。
2.1 adaptive histogram equalization
代码
def channelwise_ahe(img): img_ahe = img.copy() for i in range(img.shape[2]): img_ahe[:,:,i] = exposure.equalize_adapthist(img[:,:,i], clip_limit=0.03) return img_aheimg_ahe = channelwise_ahe(img_crop)pilImage = Image.fromarray(skimage.util.img_as_ubyte(img_ahe))pilImage.show()
效果如下:
待续。。。
0 0
- 神经网络训练中图像数据预处理的一些方式(一)
- 神经网络算法学习---图像数据预处理1
- 神经网络算法学习---图像数据预处理
- Tensorflow中图像的预处理
- 数据预处理的一些方法
- 数据预处理的一些知识
- 神经网络中训练数据集、验证数据集和测试数据集的区别
- 图像预处理技术一
- 图像数据预处理
- TensorFlow图像数据预处理
- tensorflow图像数据预处理
- 基于卷积神经网络的数据预处理以及模型参数保存
- 【Stanford CNN课程笔记】6.神经网络的数据预处理
- 总结一:神经网络训练过程中可能引起NaN的三种原因总结
- 使用caffe训练自己的图像数据
- YOLO v2 训练自己的图像数据
- 数据预处理一些笔记
- 一些数据预处理方法
- 2017 GAITC全球人工智能技术大会即将于5月召开!
- php的xml操作
- 秦皇岛-北戴河-景
- CodeForces 632 A.Grandma Laura and Apples(水~)
- dos命令运行java程序
- 神经网络训练中图像数据预处理的一些方式(一)
- 不可见字符
- JavaScript学习笔记9-返回语句
- 数据预处理:独热编码(One-Hot Encoding)
- SpringMVC系列(3)之@RequestParam与@PathVariable区别
- 移植boost到hi3519
- [leetCode刷题笔记]129. Sum Root to Leaf Numbers
- Spring何时初始化bean
- Chart.js Uncaught ReferenceError: require is not defined