ms.set_kernel(random.choice(filter(lambda s: s!='fisher', ms.kernels())))
ms.set_spatial(random.choice(ms.spatials()))

modes, indices = ms.cluster()



# Print out basic stats...
print 'kernel = %s; spatial = %s' % (ms.get_kernel(), ms.get_spatial())
print 'exemplars = %i; features = %i' % (ms.exemplars(), ms.features())
print 'quality = %.3f; epsilon = %.3f; iter_cap = %i' % (ms.quality, ms.epsilon, ms.iter_cap)
print 'weight = %.1f' % ms.weight()
print



# Create a grid of samples...
scale = 5.0
axis = numpy.arange(0.0, scale+1e-3, 0.25)
x, y = numpy.meshgrid(axis, axis)
dm = numpy.concatenate((y.flatten().reshape((-1,1)), x.flatten().reshape((-1,1))), axis=1)

clusters = ms.assign_clusters(dm)

for j in xrange(axis.shape[0]):
  for i in xrange(axis.shape[0]):
    loc = j*axis.shape[0] + i
    print clusters[loc],
  print
Example #2
0
  try:
    image[y,x,:] = 255.0
  except:
    print 'Bad draw:', vec

image = array2cv(image)
cv.SaveImage('fisher_mercator_draw.png', image)



# Do mean shift on it, output a colour coded set of regions, same projection...
print 'MS...'
## Actual work...
ms.merge_range = 0.1
modes, indices = ms.cluster()
clusters = ms.assign_clusters(block.reshape(-1,3))

## Create an image...
clusters = clusters.reshape((height, width))
image = numpy.zeros((height, width, 3), dtype=numpy.float32)

for i in xrange(clusters.max()+1):
  colour = numpy.random.random(3)
  image[clusters==i,:] = colour.reshape((1,3))

## Save it...
image = array2cv(255.0 * image)
cv.SaveImage('fisher_mercator_ms.png', image)


Example #3
0
normal_kernels = ['uniform', 'triangular', 'epanechnikov', 'cosine', 'gaussian', 'cauchy', 'logistic']
ms.set_kernel(random.choice(normal_kernels))
ms.set_spatial(random.choice(ms.spatials()))

modes, indices = ms.cluster()



# Print out basic stats...
print 'kernel = %s; spatial = %s' % (ms.get_kernel(), ms.get_spatial())
print 'exemplars = %i; features = %i' % (ms.exemplars(), ms.features())
print 'quality = %.3f; epsilon = %.3f; iter_cap = %i' % (ms.quality, ms.epsilon, ms.iter_cap)
print 'weight = %.1f' % ms.weight()
print



# Create a grid of samples...
scale = 5.0
axis = numpy.arange(0.0, scale+1e-3, 0.25)
x, y = numpy.meshgrid(axis, axis)
dm = numpy.concatenate((y.flatten().reshape((-1,1)), x.flatten().reshape((-1,1))), axis=1)

clusters = ms.assign_clusters(dm)

for j in xrange(axis.shape[0]):
  for i in xrange(axis.shape[0]):
    loc = j*axis.shape[0] + i
    print clusters[loc],
  print