(11)图像的阈值分割
skimage.filters.threshold_otsu(image, nbins=256):
from skimage import data,filters import matplotlib.pyplot as plt image = data.camera() thresh = filters.threshold_otsu(image) #返回一个阈值 dst =(image <= thresh)*1.0 #根据阈值进行分割
以下几种阈值取值类似: thresh = filters.threshold_yen(image)
thresh = filters.threshold_li(image)
还有一种较为复杂的:thresh = filters.threshold_isodata(image) 取值跟otsu一样
threshold_adaptive
调用函数为:
skimage.filters.threshold_adaptive(image, block_size, method='gaussian')
block_size: 块大小,指当前像素的相邻区域大小,一般是奇数(如3,5,7。。。)
method: 用来确定自适应阈值的方法,有'mean', 'generic', 'gaussian' 和 'median'。省略时默认为gaussian
该函数直接访问一个阈值后的图像,而不是阈值。
(12)基本图形的绘制1、画线条
函数调用格式为:
skimage.draw.line(r1,c1,r2,c2)
r1,r2: 开始点的行数和结束点的行数
c1,c2: 开始点的列数和结束点的列数
返回当前绘制图形上所有点的坐标,如:
rr, cc =draw.line(1, 5, 8, 2)
表示从(1,5)到(8,2)连一条线,返回线上所有的像素点坐标[rr,cc]
若对线绘成白线,则:
img[rr, cc] =255
如果想画其它颜色的线条,则可以使用set_color()函数,格式为:
skimage.draw.set_color(img, coords, color)
color取[r,g,b] 比如蓝色[0,0,255]2、画圆
函数格式:skimage.draw.circle(cy, cx, radius)
cy和cx表示圆心点,radius表示半径
rr, cc=draw.circle(150,150,50) draw.set_color(img,[rr,cc],[255,0,0])
3、多边形
函数格式:skimage.draw.polygon(Y,X)
Y为多边形顶点的行集合,X为各顶点的列值集合。Y=np.array([10,10,60,60]) 分别对应行的左上右上左下右下 X=np.array([200,400,400,200]) rr, cc=draw.polygon(Y,X) draw.set_color(img,[rr,cc],[255,0,0])
本文介绍了使用Python的scikit-image库进行图像阈值分割的方法,包括全局阈值分割(如Otsu、Yen、Li等)和局部自适应阈值分割。此外,还详细讲解了如何利用scikit-image绘制基本图形,例如线条、圆形和多边形。
3602

被折叠的 条评论
为什么被折叠?



