【Python】skimage模块
可以用来做图像做处理的模块有很多,不过对于使用python不熟悉,或者刚使用python做图像处理的时候,经常不知道应该选择使用哪些模块。比如,scipy中misc和ndimage中都有相应的图像处理函数,现在就介绍一下scikit-image模块吧:
1)例图:
from skimage import data
data里面会有样图,如data.camera()是一张(512, 512)的图;
2)滤波:
from skimage import filters
比如高斯滤波,filters.gaussian(camera, 1)
比如边缘检测:filters.sobel(camera)
3)文件读取:
from skimage import io
io.imread(filename),其中,filename也可以是URL地址;
io.imsave(path, img).
4)数据类型转换:
from skimage import img_as_float
camera_f = img_as_float(camera)将原图uint8类型转变成[-1, 1]之间的范围;
5)颜色空间转换:
from skimage import color
color.rgb2hsvcolor.lab2rgb, etc.
关于图像预处理和增强
6)局部滤波,如filters.sobel_h(img)
7)非局部滤波,如
rom skimage import exposure
中exposure.equalize_hist(img)做直方图均衡;
8)数学形态变换
from skimage import morphology
具体图形生成:比如morphology.diamond(1)生成菱形;
腐蚀操作:morphology.binary_erosion(img, selem=None)
selem表示结构元素,用于设定局部区域的形状和大小。将0值扩充到邻近像素。扩大黑色部分,减小白色部分。可用来提取骨干信息,去掉毛刺,去掉孤立的像素。
膨胀操作:morphology.binary)dilation(img, selem = None)
一般对二值图像进行操作。找到像素值为1的点,将它的邻近像素点都设置成这个值。1值表示白,0值表示黑,因此膨胀操作可以扩大白色值范围,压缩黑色值范围。一般用来扩充边缘或填充小的孔洞。
Opening: erosion + dilation在
注:该操作也适用于非二值图,即灰度图,对应的是最小滤波
(scipy.ndimage.morphology同样也有该操作)
9)图像分割
基于直方图分析的二值分割:(Otsu阈值法)如:val = filters.threshold(img)找到阈值,然后通过mask = img < val得到二值图
图像打标签:对于分割后的图像,可以给每一个区域打标签,如
from skimage import measure
all_labels = measure.label(blobs)
另外,scipy中也有相应操作;
水域分割算法(也叫分水岭算法):
from skimage.morphology import watershed
from skimage.feature import peak_local_max
from scipy import ndimage
>>> distance = ndimage . distance_transform_edt ( image ) >>> local_maxi = peak_local_max ( distance , indices = False , footprint = np . ones (( 3 , 3 )), labels = image ) >>> markers = morphology . label ( local_maxi ) >>> labels_ws = watershed ( - distance , markers , mask = image )另一个 随机walker分割:
from skimage import segmentation
>>> # Transform markers image so that 0-valued pixels are to >>> # be labelled, and -1-valued pixels represent background >>> markers [ ~ image ] = - 1 >>> labels_rw = segmentation . random_walker ( image , markers )
10)测量区域属性,如面积和周长
properties = measure.regionprops(labels_rw)
>>> [ prop . area for prop in properties ] [770, 1168] >>> [ prop . perimeter for prop in properties ] [100.91..., 126.81...]
11)数据可视化和交互
matplotlib中提供了plt.imshow等函数,结合以上滤波、分割(segmentation.clear_border(mask))等使用
另外,skimage也提供显示图像的函数,不过也是基于matplotlib,貌似功能更强大:
from skimage import viewer
>>> new_viewer = viewer . ImageViewer ( coins ) >>> new_viewer . show ()
For more interaction, plugins can be added to the viewer:
>>> new_viewer = viewer.ImageViewer(coins)
>>> from skimage.viewer.plugins import lineprofile>>> new_viewer += lineprofile.LineProfile() >>> new_viewer.show()
12)CV中的特征提取
from skimage import feature
不同角点特征:
from skimage.feature import corner_harris, corner_subpix, corner_peaks
//补充角点特征知识点
另外skimage.transform提供扭曲和仿射变换操作wrap和AffineTransform
【Python】skimage模块相关推荐
- python skimage图像处理(一)
python skimage图像处理(一) This blog is from: https://www.cnblogs.com/wangxiaocvpr/p/11656603.html 基于pyth ...
- python skimage图像处理
python skimage图像处理(一) jiandanjinxin关注 22017.09.26 14:31:04字数 5,913阅读 103,968 本文转自 python数字图像处理 基于pyt ...
- Python 读取显示保存图片----python skimage图像处理
转载:https://blog.csdn.net/weixin_41500849/article/details/80366991 基于python脚本语言开发的数字图片处理包,比如PIL,Pillo ...
- Python Re 模块超全解读!详细
内行必看!Python Re 模块超全解读! 2019.08.08 18:59:45字数 953阅读 121 re模块下的函数 compile(pattern):创建模式对象 > import ...
- python argparse模块_Python argparse模块应用实例解析
这篇文章主要介绍了Python argparse模块应用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 简介 argparse是python ...
- 关于使用python logging模块的几点总结
关于使用python logging模块的几点总结 使用python的标准日志模块logging可以非常方便地记录日志.Python日志系统非常丰富.添加结构化或非结构化日志输出到python代码,写 ...
- python高级-模块(14)
一.python中的模块 有过C语言编程经验的朋友都知道在C语言中如果要引用sqrt函数,必须用语句#include <math.h>引入math.h这个头文件,否则是无法正常进行调用的. ...
- 转载: Python os 模块的功能以及子函数介绍
原文链接: python之os模块 - 程序生(Codey) - 博客园 https://www.cnblogs.com/cxscode/p/8085326.html 一.Python OS模块介绍 ...
- 简单介绍python process模块
在python中大部分情况需要使用多进程,python提供了multiprocessing模块.multiprocessing模块的功能众多:支持子进程.通信和共享数据.执行不同形式的同步,提供了Pr ...
- python io模块_python中的StringIO模块
原博文 2015-10-23 15:21 − # python中的StringIO模块 标签:python StringIO --- > 此模块主要用于在内存缓冲区中读写数据.模块是用类编写的, ...
最新文章
- Android 访问WebService
- excel图片变成代码_三行代码把女朋友照片变成了素描图片!以为我画的!爱我爱的不行...
- Invalid host: lb://xxx_xxx
- 前端学习(1118):高阶函数
- vue路由+ elementUI表格组件:loop文章列表页enter内容页(vue路由传参userid)- 代码篇
- 构造函数和析构函数的作用,面向对象的三大特征
- Python使用库读取数据
- MyReport:DataGrid的打印和打印预览
- mysql 历史记录查询
- 从 0 到 1000+ 台服务器监控的构建之路
- 图像分割各种评测标准
- Kubernetes实践:使用k8s部署微服务应用
- 基于Web在线考试系统的设计与实现
- c语言中eof的作用,C语言中EOF是什么意思?
- 前端常用PS技巧总结之将图片上的LOGO(水印)去掉
- springboot整合log4j2报错Unexpected filename extension of file[file__E__classes_log4j2.yml].Should be .xm
- 迅雷看看引领高清内容多屏合一新趋势
- 结构体嵌套结构体,及其的初始化
- python群聊聊天室程序_Python聊天室程序(基础版)
- 一个通过Rmd文件输出表格到word的简单方法
热门文章
- boost::python::pointee相关的测试程序
- boost::math模块使用 non_finite_num facet 的一个非常简单的例子
- boost::math::differentiation用法的测试程序
- boost::intrusive::list_base_hook用法的测试程序
- GDCM:DICOM文件转换为QImage文件的测试程序
- boost::exchange的测试程序
- Boost:boost::asio模块的allocation service分配服务测试程序
- VTK:PolyData之LinearExtrusion
- VTK:PolyData之GetMiscPointData
- VTK:灯光之LightActor