Content deleted Content added
m Open access bot: url-access updated in citation with #oabot. |
|||
(34 intermediate revisions by 28 users not shown) | |||
Line 1:
{{short description|Algorithm for labeling clusters on a grid}}
{{Machine learning bar}}
The '''Hoshen–Kopelman algorithm''' is a simple and efficient [[algorithm]] for labeling [[Cluster analysis|clusters]] on a grid
== Percolation theory ==
[[Percolation theory]] is the study of the behavior and [[statistics]] of [[
{| style="margin: auto;"
|-
| <gallery>
Occupied_Grids_P_%3D_0.24.png |
</gallery>
Occupied_Grids_P_%3D_0.64.png |
</gallery>
|}
== Hoshen–Kopelman algorithm for cluster finding ==
In this algorithm, we scan through a grid looking for occupied cells and labeling them with cluster labels. The scanning process is called
== Union-find algorithm ==
This algorithm is
==
During the [[raster scan]] of the grid, whenever an occupied cell is encountered, neighboring cells are scanned to check whether any of them have already been scanned. If we find already scanned neighbors, the <code>union</code> operation is performed, to specify that these neighboring cells are in fact members of the same
On the other hand, if the current cell has no neighbors, it is assigned a new, previously unused, label. The entire grid is processed in this way.
Following [[
<strong>Raster Scan and Labeling on the Grid</strong>▼
largest_label = 0;▼
for x in 0 to n_columns {▼
if occupied[x,y] then▼
left = occupied[x-1,y];▼
above = occupied[x,y-1];▼
if (left == 0) and (above == 0) then /* Neither a label above nor to the left. */▼
largest_label = largest_label + 1; /* Make a new, as-yet-unused cluster label. */▼
else if (left != 0) and (above == 0) then /* One neighbor, to the left. */▼
else if (left == 0) and (above != 0) then /* One neighbor, above. */▼
else /* Neighbors BOTH to the left and above. */▼
union(left,above); /* Link the left and above clusters. */▼
}▼
}▼
void union(int x, int y) {▼
label = zeros[n_columns, n_rows]
labels[find(x)] = find(y);▼
labels = [0:n_columns*n_rows] /* Array containing integers from 0 to the size of the image. */
while (labels[x] != x) {▼
int z = labels[x];▼
x = z;▼
}▼
return y;▼
}
'''Union'''
}
'''Find'''
int find(int x) {
while (labels[y] != y)
y = labels[y];
labels[x] = y;
▲ }
▲ return y;
}
== Example ==
Consider the following example. The dark cells in the grid in
The algorithm processes the input grid, cell by cell, as follows: Let's say that grid is a two-dimensional array.
Line 90 ⟶ 97:
* <code>grid[4][4]</code> is unoccupied so it is not labeled.
* <code>grid[4][5]</code> is occupied so check cell to the left and above, both the cells are unoccupied so assign a new label <code>7</code>.
* <code>grid[5][0]</code> , <code>grid[5][1]</code> , <code>grid[5][2]</code> and <code>grid[5][3]</code> are unoccupied so they are not labeled.
* <code>grid[5][4]</code> is occupied so check cell to the left and above, both the cells are unoccupied so assign a new label <code>8</code>.
* <code>grid[5][5]</code> is occupied so check cell to the left and above, both, cell to the left and above are occupied so merge the two clusters and assign the cluster label of the cell above to the cell on the left and to this cell i.e. <code>7</code>. (Merging using union algorithm will label all the cells with label <code>8</code> to <code>7</code>).
{| style="margin: auto;"
|-
| <gallery>
H-K algorithm Input.png |
</gallery>
H-K algorithm output.png |
</gallery>
|}
== Applications ==
*
* [[Connectivity (graph theory)|Nodal Connectivity Information]]
* Modeling of [[Electrical resistivity and conductivity|electrical conduction]]
== See
* [[K-means clustering|K-means clustering algorithm]]
* [[Fuzzy clustering|Fuzzy clustering algorithm]]
* Gaussian ([[Expectation–maximization algorithm|Expectation Maximization]]) clustering algorithm
* Clustering Methods <ref>{{Cite web|url=https://web.stanford.edu/class/cs345a/slides/12-clustering.pdf|title=Clustering
* C-means Clustering Algorithm <ref>{{Cite web|url=https://sites.google.com/site/dataclusteringalgorithms/fuzzy-c-means-clustering-algorithm|title=Fuzzy c-means clustering
* [[Connected-component labeling]]
== References ==
{{Reflist}}
{{DEFAULTSORT:Hoshen-Kopelman algorithm}}
[[Category:
|