Objective Cluster Identification A Finite State Machine Approach ● Want to find and identify homogeneous to Cluster Identification Using the patches in a 2D matrix, where: Hoshen-Kopelman Algorithm ● Cluster membership defined by adjacency ● No need for distance function ● Sequential cluster IDs not necessary ● Common task in analysis of geospatial data (landscape maps) Matthew Aldridge Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Overview Data structures ● Assigns unique IDs to homogeneous ● Matrix regions in a lattice ● Preprocessed to replace target class with -1 , ● Handles only one target class at a time everything else with 0 ● Cluster ID/size array (“csize”) ● Lattice preprocessing needed to filter out unwanted classes ● Indexing begins at 1 ● Single-pass cluster identification ● Index represents cluster ID ● Positive values indicate cluster size ● Second pass to relabel temporary IDs, but not strictly necessary ● Proper cluster label ● 2-D lattice represented as matrix herein ● Negative values provide ID redirection ● Temporary cluster label
Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm csize array Clustering procedure 1 -3 ● + values: cluster size ● Matrix traversed row-wise 2 8 ● If current cell nonzero ● Cluster 2 has 8 members 3 5 ● Search for nonzero (target class) neighbors ● - values: ID redirection 4 -1 ● If no nonzero neighbors found ... 5 4 ● Cluster 4 is the same as ● Give cell new label 6 1 cluster 1, same as cluster 3 ● Else ... 0 7 ● Cluster 4/1/3 has 5 members ● Find proper labels K of nonzero neighbor cells ● Redirection allowed for ● min( K ) is the new proper label for current cell noncircular, recursive path and nonzero neighbors for finite number of steps Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-Four Neighborhood Nearest-4 HK in action... ● North/East/West/South neighbors -1 0 -1 0 0 -1 -1 0 1 0 -1 0 -1 0 -1 -1 0 -1 2 0 ● Used in classic HK implementations 3 0 0 0 -1 -1 -1 -1 0 -1 4 0 ● Of the four neighbors, only N/W have 5 0 -1 -1 0 -1 0 -1 0 -1 6 0 been previously labeled at any given time -1 0 0 0 -1 0 -1 0 7 0 8 0 -1 0 0 -1 -1 0 0 0 9 0 10 0 0 0 -1 -1 -1 -1 0 -1 11 0 12 0 0 0 -1 -1 -1 -1 0 -1 i-1, j N i, j-1 i, j i, j+1 W C E ● Matrix has been preprocessed i+1, j S ● Target class value(s) replaced with -1 , all others with 0
Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 1 1 1 2 1 2 1 -1 0 -1 0 -1 -1 0 -1 -1 0 -1 0 -1 -1 0 -1 3 2 3 2 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 4 0 4 0 5 0 5 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 6 0 6 0 7 0 7 0 -1 0 0 0 -1 0 -1 0 -1 0 0 0 -1 0 -1 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 0 0 -1 -1 -1 -1 0 -1 12 0 0 0 -1 -1 -1 -1 0 -1 12 0 ● First row, two options: ● Add top buffer row of zeros, OR ● Ignore N neighbor check Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 2 1 2 1 0 -1 0 -1 -1 0 -1 2 1 1 0 -1 0 -1 -1 0 -1 2 1 3 2 3 2 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 4 0 4 0 5 0 5 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 6 0 6 0 -1 0 0 0 -1 0 -1 0 7 0 -1 0 0 0 -1 0 -1 0 7 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 12 0 12 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1
Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 2 1 2 2 2 2 2 1 0 2 0 -1 -1 0 -1 1 0 2 0 -1 -1 0 -1 3 2 3 2 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 4 0 4 0 5 0 5 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 6 0 6 0 7 0 7 0 -1 0 0 0 -1 0 -1 0 -1 0 0 0 -1 0 -1 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 0 0 -1 -1 -1 -1 0 -1 12 0 0 0 -1 -1 -1 -1 0 -1 12 0 Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 2 1 2 1 0 2 0 4 -1 0 -1 2 2 1 0 2 0 4 3 0 -1 2 2 3 2 3 4 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 4 1 4 -3 5 0 5 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 6 0 6 0 -1 0 0 0 -1 0 -1 0 7 0 -1 0 0 0 -1 0 -1 0 7 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 12 0 12 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1
Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 2 1 2 2 2 2 2 1 0 2 0 4 3 0 -1 1 0 2 0 4 3 0 5 3 4 3 4 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 4 -3 4 -3 5 0 5 1 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 6 0 6 0 7 0 7 0 -1 0 0 0 -1 0 -1 0 -1 0 0 0 -1 0 -1 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 0 0 -1 -1 -1 -1 0 -1 12 0 0 0 -1 -1 -1 -1 0 -1 12 0 Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 3 3 0 1 2 1 2 1 0 2 0 4 3 0 5 2 10 1 0 2 0 4 3 0 5 2 12 3 -2 3 -2 0 0 2 2 2 2 0 5 0 0 2 2 2 2 0 5 4 -3 4 -3 5 2 5 3 -1 -1 0 -1 0 -1 0 -1 6 6 0 2 0 2 0 5 6 0 6 2 -1 0 0 0 -1 0 -1 0 7 0 -1 0 0 0 -1 0 -1 0 7 0 8 0 8 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 -1 0 0 0 9 0 9 0 10 0 10 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1 11 0 11 0 12 0 12 0 0 0 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 0 -1
Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-4 HK in action... Nearest-4 HK in action... 1 0 2 0 0 3 3 0 1 0 2 0 0 2 2 0 1 2 1 2 2 12 2 12 1 0 2 0 4 3 0 5 1 0 2 0 2 2 0 5 3 -2 3 -2 0 0 2 2 2 2 0 5 0 0 2 2 2 2 0 5 4 -3 4 -3 5 3 5 3 6 6 0 2 0 2 0 5 6 6 0 2 0 2 0 5 6 3 6 3 7 11 7 11 6 0 0 0 7 0 8 0 6 0 0 0 7 0 8 0 8 1 8 1 6 0 0 9 7 0 0 0 6 0 0 7 7 0 0 0 9 -7 9 -7 10 -7 10 -7 0 0 10 7 7 7 0 11 0 0 7 7 7 7 0 11 11 2 11 2 0 0 7 7 7 7 0 11 12 0 0 0 7 7 7 7 0 11 12 0 ● Skipping ahead ● Optional second pass to relabel cells to their proper labels Hoshen-Kopelman Algorithm Hoshen-Kopelman Algorithm Nearest-Eight Neighborhood Nearest-Eight Neighborhood ● NW, N, NE, E, SE, S, SW, W ● Sometimes more appropriate in landscape analysis ● When examining a cell, compare to W, ● Rasterization can segment continuous NW, N, NE neighbors features if only using nearest-four neighborhood i-1, j-1 i-1, j i-1, j+1 NW N NE i, j-1 i, j i, j+1 W C E i+1, j-1 i+1, j i+1, j+1 SW S SE
Hoshen-Kopelman Algorithm UNION-FIND Algorithm Nearest-4 vs. Nearest-8 Results Disjoint-Set Data Structure ● Maintains collection of non-overlapping 1 0 2 0 0 2 2 0 1 0 2 0 0 2 2 0 sets of objects 1 0 2 0 2 2 0 5 1 0 2 0 2 2 0 2 ● Each set identifiable by a single 0 0 2 2 2 2 0 5 0 0 2 2 2 2 0 2 representative object 6 6 0 2 0 2 0 5 2 2 0 2 0 2 0 2 6 0 0 0 7 0 8 0 2 0 0 0 2 0 2 0 ● Rep. may change as set changes, but 6 0 0 7 7 0 0 0 2 0 0 2 2 0 0 0 remains the same as long as set unchanged 0 0 7 7 7 7 0 11 0 0 2 2 2 2 0 5 ● Disjoint-set forest is a type of D-S data 0 0 7 7 7 7 0 11 0 0 2 2 2 2 0 5 structure with sets represented by rooted trees ● Root of tree is representative UNION-FIND Algorithm UNION-FIND Algorithm Disjoint-Set Data Structure Operations HK relation to UNION-FIND ● MAKE-SET( x ) ● csize array may be viewed as a disjoint- set forest ● Creates a new set whose only member is x ● UNION( x , y ) 1 2 1 2 5 6 7 8 11 ● Combines the two sets containing objects x 2 12 3 -2 and y 4 -3 ● FIND-SET( x ) 5 3 6 3 3 9 10 7 11 ● Returns the representative of the set 8 1 containing object x 9 -7 10 -7 ● An algorithm that performs these ops is 11 2 4 12 0 known as a UNION-FIND algorithm
Recommend
More recommend