本文整理汇总了Python中cluster.Cluster.kmeansCluster方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.kmeansCluster方法的具体用法?Python Cluster.kmeansCluster怎么用?Python Cluster.kmeansCluster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.kmeansCluster方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPeakClusters
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import kmeansCluster [as 别名]
def getPeakClusters(self, src):
data_vec = self.convert2Vec(src)
self.getMinMaxVal(data_vec);
uniq_map = dict()
for i in range(0,len(data_vec)):
if not uniq_map.has_key(data_vec[i]):
uniq_map[data_vec[i]] = 1
changeThresh = 1.13
changeCountThresh = 3
maxShades = 5
error = 2
maxClusters = min(8,len(uniq_map))
densityVec = []
for i in range(0,maxClusters):
clst = Cluster()
clst.kmeansCluster(data_vec,i+1)
totalPts = 0
totalDensity = 0.0
for j in range(0,clst.getNumOfClusters()):
totalPts += clst.getSizeOfCluster(j)
for j in range(0,clst.getNumOfClusters()):
numPts = clst.getSizeOfCluster(j)
minVal = clst.getMin(j)
maxVal = clst.getMax(j)
density = numPts/(maxVal-minVal)
if(math.isinf(density)): density = 1000.0
totalDensity += (float(numPts)/totalPts) * density
center = clst.getCenter(j)
#printf("Clst: %d, Center: %.0f, Min: %.0f, Max: %.0f, Range: %.0f, Size: %d, Density: %f\n",j+1,center,minVal,maxVal,maxVal-minVal,numPts,density);
#cout << "-------------------------------------------" << endl;
densityVec.append(totalDensity)
changeVec = []
change = -1.0
for i in range(0,len(densityVec)):
if(i>0):
change = densityVec[i]/densityVec[i-1]
changeVec.append(change)
#printf("%d) Density: %f, Change: %f\n",i+1,densityVec.at(i),change);
else:
#printf("%d) Density: %f, Change: %f\n",i+1,densityVec.at(i),change);
changeVec.append(change)
changeCount = 0
peakPos = 1
for i in range(0, len(changeVec)):
change = changeVec[i]
if(change<=changeThresh and change>=0): changeCount+=1
else: changeCount = 0
#printf("%d: %f, %d\n",i+1,change,changeCount);
if(changeCount>=changeCountThresh or i==(maxClusters-1)):
peakPos = max((i-changeCountThresh),0)
peakPos+=1
break
if(peakPos==1):
peakPos = changeVec.index(max(changeVec)) + 1
peakPos = min(peakPos+error,maxShades)
return peakPos
示例2: range
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import kmeansCluster [as 别名]
newImg = origImg.copy()
for i in range(0,discreteImg.shape[0]):
for j in range(0,discreteImg.shape[1]):
val = discreteImg[i,j]
if(val>0):
shadeMap[val]+=1
if not pointMap.has_key(val):
pointMap[val] = []
pointMap[val].append((j,i))
area = cv2.countNonZero(discreteImg)
for key in shadeMap:
relArea = shadeMap[key] / float(area)
if(relArea<=thresh):
val = key
for i in range(0,len(pointMap[val])):
pt = pointMap[val][i]
newImg[pt] = 0
self.isOutliersRemoved = True
if(self.isOutliersRemoved):
data_vec = self.convert2Vec(newImg)
self.getMinMaxVal(data_vec)
return newImg;
if __name__ == "__main__":
cluster = Cluster()
img = cv2.imread("/home/jason/Desktop/Programs/Crop_Features/acne1_discrete.png",0)
centers = cluster.kmeansCluster(img,4,0,255)
print centers