mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-12 12:50:49 +08:00
Added docs
This commit is contained in:
+45
-2
@@ -3,8 +3,30 @@ import _construct
|
||||
from skimage import util
|
||||
|
||||
class RAG(nx.Graph):
|
||||
"""
|
||||
The class for holding the Region Adjacency Graph (RAG).
|
||||
|
||||
Each region is a contiguous set of pixels in an image, usuall
|
||||
sharing some common property.Adjacent regions have an edge
|
||||
between their corresponding nodes.
|
||||
"""
|
||||
|
||||
def merge_nodes(self,i,j):
|
||||
"""Merges nodes `i` and `j`.
|
||||
|
||||
The new combined node is adjacent to all the neighbors of `i`
|
||||
and `j`. In case of conflicting edges, edge with higher weight
|
||||
is chosen.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
i : int
|
||||
Node to be merged.
|
||||
j : int
|
||||
Node to be merged.
|
||||
|
||||
"""
|
||||
|
||||
def merge_nodes(i,j):
|
||||
if not self.has_edge(i, j):
|
||||
raise ValueError('Cant merge non adjacent nodes')
|
||||
|
||||
@@ -24,7 +46,28 @@ class RAG(nx.Graph):
|
||||
self.node[j]['labels'] += self.node[i]['labels']
|
||||
self.remove_node(i)
|
||||
|
||||
def rag_meancolor(img,labels):
|
||||
|
||||
def rag_meancolor(img, labels):
|
||||
"""Computes the Region Adjacency Graph of a color image using
|
||||
difference in mean color of regions as edge weights.
|
||||
|
||||
Given an image and its segmentation, this method constructs the
|
||||
corresponsing Region Adjacency Graph (RAG).Each node in the RAG
|
||||
represents a contiguous pixels with in `img` the same label in
|
||||
`arr`
|
||||
|
||||
Parameters
|
||||
----------
|
||||
img : (width, height, 3) or (width, height, depth, 3) ndarray
|
||||
Input image.
|
||||
arr : (width, height) or (width, height, depth) ndarray
|
||||
The array with labels.
|
||||
|
||||
Returns
|
||||
-------
|
||||
out : RAG
|
||||
The region adjacency graph.
|
||||
"""
|
||||
|
||||
img = util.img_as_ubyte(img)
|
||||
if img.ndim == 4 :
|
||||
|
||||
Reference in New Issue
Block a user