-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclusters.py
More file actions
executable file
·31 lines (27 loc) · 969 Bytes
/
clusters.py
File metadata and controls
executable file
·31 lines (27 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
import os
import math
import array
import numpy as np
import objects
from objects import *
def RecursiveClustering(cluster_pixels,pivot,pixels):
if(pivot in pixels):
cluster_pixels.append(pivot) ## add this pixel to the cluster
pixels.remove(pivot) ## kill pixel from live pixels list
for pixel in pixels[:]:
dx = abs(pixel.x-pivot.x)
dy = abs(pixel.y-pivot.y)
if((dx+dy)<=2 and dx<=1 and dy<=1):
nextpivot = pixel
RecursiveClustering(cluster_pixels,nextpivot,pixels)
def GetAllClusters(pixels,det):
clusters = []
positions = []
while len(pixels)>0: ## loop as long as there are live pixels in the list
pixel = pixels[0] ## this is the pivot pixel for the cluster recursion
cluster_pixels = []
RecursiveClustering(cluster_pixels,pixel,pixels)
cluster = Cls(cluster_pixels,det)
clusters.append( cluster )
return clusters