非常教程

Scikit image参考手册

future

future.graph

skimage.future.graph.cut_normalized(标签,抹布)

在区域邻接图上执行归一化图切割。

skimage.future.graph.cut_threshold(标签,...)

合并重量小于阈值的区域。

skimage.future.graph.merge_hierarchical(...)

执行RAG的分层合并。

skimage.future.graph.ncut(标签,抹布,...)

在区域邻接图上执行归一化图切割。

skimage.future.graph.rag_boundary(标签,...)

基于区域边界的路由器RAG

skimage.future.graph.rag_mean_color(image,...)

使用平均颜色计算区域邻接图。

skimage.future.graph.show_rag(labels,rag,img)

在图像上显示区域邻接图。

skimage.future.graph.RAG(label_image,...)

图像的区域邻接图(RAG),子类

skimage.future.graph.graph_cut

skimage.future.graph.graph_merge

skimage.future.graph.rag

cut_normalized

skimage.future.graph.cut_normalized(labels, rag, thresh=0.001, num_cuts=10, in_place=True, max_edge=1.0)[source]

在区域邻接图上执行归一化图切割。

给定图像的标签及其相似性RAG,递归地执行双向归一化剪切。属于无法进一步剪切的子图的所有节点都会在输出中分配一个唯一的标签。

参数:

标签:ndarray标签数组。抹布:RAG区域邻接图。阈值:浮点阈值。如果N-cut的值超过阈值,子图将不会进一步细分。num_cuts:int确定最优值之前要执行的数字或N切分。in_place:bool如果设置,则修改碎布。对于每个节点n,函数将设置一个新的属性rag.noden。max_edge:float,可选RAG中边缘的最大可能值。这对应于相同区域之间的边缘。这用于在RAG中放置自己的边缘。

返回:

out:ndarray新的带标签的数组。

参考

R289

Shi, J.; Malik, J., “Normalized cuts and image segmentation”, Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. 22, no. 8, pp. 888-905, August 2000.

例子

>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img, compactness=30, n_segments=400)
>>> rag = graph.rag_mean_color(img, labels, mode='similarity')
>>> new_labels = graph.cut_normalized(labels, rag)

cut_threshold

skimage.future.graph.cut_threshold(labels, rag, thresh, in_place=True)[source]

合并重量小于阈值的区域。

给定图像的标签和RAG,通过合并区域来输出新的标签,这些区域的节点之间的权重将小于给定的阈值。

参数:

标签:ndarray标签数组。抹布:RAG区域邻接图。阈值:浮点阈值。由具有较小权重的边连接的区域被组合。in_place:bool如果设置,则修改碎布。该功能将删除重量小于阈值的边。如果设置为False,则在继续操作之前,该功能会制作抹布的副本。

返回:

out:ndarray新的带标签的数组。

参考

R290

Alain Tremeau and Philippe Colantoni “Regions Adjacency Graph Applied To Color Image Segmentation” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274

例子

>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img)
>>> rag = graph.rag_mean_color(img, labels)
>>> new_labels = graph.cut_threshold(labels, rag, 10)

merge_hierarchical

skimage.future.graph.merge_hierarchical(labels, rag, thresh, rag_copy, in_place_merge, merge_func, weight_func)[source]

执行RAG的分层合并。

贪婪地合并最相似的一对节点,直到没有边缘低于thresh保持。

参数:

标签:ndarray标签数组。抹布:RAG区域邻接图。thresh:float合并由权重小于thresh的边连接的区域。rag_copy:bool如果设置,RAG在修改之前被复制。in_place_merge:bool如果设置了,则节点合并到位。否则,为每个合并创建一个新节点。merge_func:callable在合并两个节点之前调用此函数。对于合并src和dst时的RAG图,它被调用如下merge_func(graph,src,dst)。weight_func:callable计算与合并节点相邻的节点的新权重的函数。这直接作为参数weight_func提供给merge_nodes。

返回:

out:ndarray新的带标签的数组。

ncut

skimage.future.graph.ncut(labels, rag, thresh=0.001, num_cuts=10, in_place=True, max_edge=1.0)[source]

在区域邻接图上执行归一化图切割。

给定图像的标签及其相似性RAG,递归地执行双向归一化剪切。属于无法进一步剪切的子图的所有节点都会在输出中分配一个唯一的标签。

参数:

标签:ndarray标签数组。抹布:RAG区域邻接图。阈值:浮点阈值。如果N-cut的值超过阈值,子图将不会进一步细分。num_cuts:int确定最优值之前要执行的数字或N切分。in_place:bool如果设置,则修改碎布。对于每个节点n,函数将设置一个新的属性rag.noden。max_edge:float,可选RAG中边缘的最大可能值。这对应于相同区域之间的边缘。这用于在RAG中放置自己的边缘。

返回:

out:ndarray新的带标签的数组。

参考

R291

Shi, J.; Malik, J., “Normalized cuts and image segmentation”, Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. 22, no. 8, pp. 888-905, August 2000.

例子

>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img, compactness=30, n_segments=400)
>>> rag = graph.rag_mean_color(img, labels, mode='similarity')
>>> new_labels = graph.cut_normalized(labels, rag)

rag_boundary

skimage.future.graph.rag_boundary(labels, edge_map, connectivity=2)[source]

基于区域边界的路由器RAG

给定图像的初始分割及其边缘图,该方法构造相应的区域邻接图(RAG)。RAG中的每个节点都代表图像中的一组像素,其中包含相同的标签labels。两个相邻区域之间的重量是edge_map沿其边界的平均值。

labels : ndarray标记的图像。edge_map : ndarray这应该具有相同的形状labels。对于沿着2个相邻区域之间的边界的所有像素,相应像素的平均值edge_map是它们之间的边缘权重。connectivity : int, optional平方距离小于connectivity彼此的像素被认为是相邻的。它可以从1到labels.ndim。它的行为与connectivity参数中的相同scipy.ndimage.filters.generate_binary_structure

例子

>>> from skimage import data, segmentation, filters, color
>>> from skimage.future import graph
>>> img = data.chelsea()
>>> labels = segmentation.slic(img)
>>> edge_map = filters.sobel(color.rgb2gray(img))
>>> rag = graph.rag_boundary(labels, edge_map)

rag_mean_color

skimage.future.graph.rag_mean_color(image, labels, connectivity=2, mode='distance', sigma=255.0)[source]

使用平均颜色计算区域邻接图。

给定图像及其初始分割,该方法构造相应的区域邻接图(RAG)。RAG中的每个节点代表一组内image具有相同标签的像素labels。两个相邻区域之间的权重表示两个区域的相似程度或不相似程度取决于mode参数。

参数:

图像:ndarray,形状(M,N,...,P,3)输入图像。标签:ndarray,形状(M,N,...,P)标签图像。这应该有一个小于图像的维度。如果图像具有尺寸(M,N,3),则标签应具有尺寸(M,N)。连通性:int,可选像素的平方距离小于彼此的连通性被认为是相邻的。它的范围可以从1到labels.ndim。它的行为与scipy.ndimage.generate_binary_structure中的连接参数相同。模式:{'距离','相似性'},可选分配边权重的策略。'距离':两个相邻区域之间的权重是(| c_1 - c_2 |),其中(c_1)和(c_2)是两个区域的平均颜色。它代表欧氏距离的平均颜色。'相似性':两个相邻的权重为(e ^ { - d ^ 2 / sigma})其中(d = | c_1 - c_2 |),其中(c_1)和(c_2)是两个区域的平均颜色。它代表了两个地区的相似程度。sigma:float,可选用于模式为“相似性”时的计算。它规定了两种颜色应该彼此接近的程度,因为它们对应的边缘重量非常重要。西格玛的一个非常大的值可以使任何两种颜色表现得好像它们是相似的。

返回:

out:RAG区域邻接图。

参考

R292

Alain Tremeau and Philippe Colantoni “Regions Adjacency Graph Applied To Color Image Segmentation” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274

例子

>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img)
>>> rag = graph.rag_mean_color(img, labels)

show_rag

skimage.future.graph.show_rag(labels, rag, img, border_color='black', edge_width=1.5, edge_cmap='magma', img_cmap='bone', in_place=True, ax=None)[source]

在图像上显示区域邻接图。

给定一个带标记的图像及其相应的RAG,用指定的颜色显示图像上RAG的节点和边缘。边缘显示在图像中两个相邻区域的质心之间。

参数:

标签:ndarray,形状(M,N)标签图像。抹布:RAG区域邻接图。img:ndarray,shape(M,N,3)输入图像。如果colormap为None,则图像应为RGB格式。border_color:颜色规范,可选用于绘制区域之间边界的颜色。edge_width:float,可选RAG边缘被绘制的厚度。edge_cmap:matplotlib.colors.Colormap,可选用任何绘制边缘的matplotlib颜色表。img_cmap:matplotlib.colors.Colormap,可选用于绘制图像的任何matplotlib颜色表。如果设置为None,则图像将按原样绘制。in_place:bool,可选如果设置了,RAG将被修改。对于每个节点n,函数将设置一个新的属性rag.noden。ax:matplotlib.axes.Axes,可选要绘制的轴。如果没有指定,

返回:

lc:matplotlib.collections.LineCollection表示图的边的线的集合。它可以传递给matplotlib.figure.Figure.colorbar()函数。

例子

>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.coffee()
>>> labels = segmentation.slic(img)
>>> g =  graph.rag_mean_color(img, labels)
>>> lc = graph.show_rag(labels, g, img)
>>> cbar = plt.colorbar(lc)

RAG

class skimage.future.graph.RAG(label_image=None, connectivity=1, data=None, **attr)[source]

Bases: networkx.classes.graph.Graph

图像的区域邻接图(RAG),子类networx.Graph

参数:

label_image:int数组初始分割,每个区域标记为不同的整数。label_image中的每个唯一值都将对应图中的一个节点。connectivity:{1,...,label_image.ndim}中的int,可选在label_image中像素之间的连通性。对于2D图像,1的连通性对应于上下左右的直接邻居,而2的连通性也包括对角邻居。请参阅scipy.ndimage.generate_binary_structure。data:networkx图形规格,可选要传递给NetworkX Graph构造函数的初始或附加边。参见networkx.Graph。有效的边缘规范包括边缘列表(元组列表),NumPy数组和SciPy稀疏矩阵。** attr:关键字参数,可选要添加到图形的其他属性。

__init__(label_image=None, connectivity=1, data=None, **attr)[source]add_edge(u, v, attr_dict=None, **attr)[source]

在更新最大节点ID时u和之间添加边v

另请参阅

networkx.Graph.add_edge().

add_node(n, attr_dict=None, **attr)[source]

n在更新最大节点ID时添加节点。

另请参阅

networkx.Graph.add_node().

copy()[source]

使用其最大节点ID复制图形。

另请参阅

networkx.Graph.copy().

fresh_copy()[source]

返回具有相同数据结构的新副本图。

新副本没有节点,边或图属性。它与当前图形的数据结构相同。此方法通常用于创建图形的空白版本。

当使用networkx v2对Graph进行子类化并且不会为v1导致问题时,这是必需的。以下是从1.x文件迁移到2.x文件的更多细节:

With the new GraphViews (SubGraph, ReversedGraph, etc)
you can't assume that ``G.__class__()`` will create a new
instance of the same graph type as ``G``. In fact, the
call signature for ``__class__`` differs depending on
whether ``G`` is a view or a base class. For v2.x you
should use ``G.fresh_copy()`` to create a null graph of
the correct type---ready to fill with nodes and edges.

merge_nodes(src, dst, weight_func=<function min_weight>, in_place=True, extra_arguments=[], extra_keywords={})[source]

合并节点srcdst

合并后的新节点是邻近的所有邻居srcdstweight_func被调用来决定入侵新节点的边的权重。

参数:

src,dst:int要合并的节点。weight_func:callable,可选用于决定事件在新节点上的边的属性的函数。对于src和`dst的每个邻居n,weight_func将被调用如下:weight_func(src,dst,n,* extra_arguments,** extra_keywords)。src,dst和n是RAG对象中顶点的标识,RAG对象又是networkx.Graph的子类。预计会返回所产生边缘属性的字典。in_place:bool,可选如果设置为True,则合并的节点具有id dst,否则合并的节点会返回一个新的id。extra_arguments:sequence,可选传递给weight_func的额外位置参数的序列。extra_keywords:dictionary,可选关键字参数的字典传递给weight_func。|

返回:

id:int新节点的标识。

注意

如果in_placeFalse结果节点有一个新的ID,而不是dst

next_id()[source]

返回id要插入的新节点。

当前的实现返回比最大值多一个id

返回:

id:int要插入的新节点的标识。

future相关

Scikit image

Scikit-image 是用于图像处理的 Python 包,使用原生的 NumPy 数组作为图像对象。

主页 http://scikit-image.org/
源码 https://github.com/scikit-image/scikit-image
发布版本 0.13.1