pytorch_13-图像处理之skimage

之前程序使用的是PIL(Python image library),今天遇到了另一种图像处理包--skimage。

skimage即scikit-image,PIL和Pillow只提供最基础的数字图像处理,功能有限,OpenCV是一个c++库,只是提供了Python接口,更新速度非常慢,scikit-image是基于scipy的一款图像处理包,将图片作为numpy数组进行处理,正好与MATLAB一样。

子模块名称                 主要实现功能

  1. io                            读取、保存和显示图片或视频
  2. data                       提供一些测试图片和样本数据
  3. color                           颜色空间变换
  4. filters             图像增强、边缘检测、排序滤波器、自动阈值等
  5. draw               操作于numpy数组上的基本图形绘制,包括线条、矩形、圆和文本等
  6. transform          几何变换或其它变换,如旋转、拉伸和拉东变换等
  7. morphology          形态学操作,如开闭运算、骨架提取等
  8. exposure              图片强度调整,如亮度调整、直方图均衡等
  9. feature                        特征检测与提取等
  10. measure                  图像属性的测量,如相似性或等高线等
  11. segmentation                          图像分割
  12. restoration                           图像恢复
  13. util                                  通用函数

安装:pip install scikit-image

官网:https://scikit-image.org/

 1 from skimage import io as img
 2 import torch
 3 
 4 def process_image():
 5     """
 6     利用skimage处理数据
 7     :return: 
 8     """
 9     x = img.imread('%s/%s'%(opt.input_dir,opt.input_name)) #类型为numpy
10     if opt.nc_im == 3: # 如果是3通道
11         x = x[:, :, :, None]
12         x = x.transpose((3, 2, 0, 1)) / 255  # (图片个数,channel,height,width)
13     else:
14         x = color.rgb2gray(x)
15         x = x[:, :, None, None]
16         x = x.transpose(3, 2, 0, 1)
17     x= torch.from_numpy(x)
18     x = x.type(torch.cuda.FloatTensor) if not opt.not_cuda else x.type(torch.FloatTensor)
19     out = (x-0.5)*2
20     out = out.clamp(-1,1)
21     return out

猜你喜欢

转载自www.cnblogs.com/shuangcao/p/12045735.html
今日推荐