skimage2.graph.cut_normalized#
- skimage2.graph.cut_normalized(labels, rag, thresh=0.001, num_cuts=10, in_place=True, max_edge=1.0, *, rng=None)[source]#
Perform Normalized Graph cut on the Region Adjacency Graph.
Given an imageâs labels and its similarity RAG, recursively perform a 2-way normalized cut on it. All nodes belonging to a subgraph that cannot be cut further are assigned a unique label in the output.
- Parameters:
- labelsndarray
The array of labels.
- ragRAG
The region adjacency graph.
- threshfloat
The threshold. A subgraph wonât be further subdivided if the value of the N-cut exceeds
thresh.- num_cutsint
The number or N-cuts to perform before determining the optimal one.
- in_placebool
If set, modifies
ragin place. For each nodenthe function will set a new attributerag.nodes[n]['ncut label'].- max_edgefloat, optional
The maximum possible value of an edge in the RAG. This corresponds to an edge between identical regions. This is used to put self edges in the RAG.
- rng{
numpy.random.Generator, int}, optional Pseudo-random number generator. By default, a PCG64 generator is used (see
numpy.random.default_rng()). Ifrngis an int, it is used to seed the generator.The
rngis used to determine the starting point ofscipy.sparse.linalg.eigsh.
- Returns:
- outndarray
The new labeled array.
References
[1]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.
Examples
>>> from _skimage2 import data, segmentation, graph >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels, mode='similarity') >>> new_labels = graph.cut_normalized(labels, rag)