我想我明白你在问什么,我的建议是计算你的像素之间共享的“墙壁”的数量:
我认为从左到右,个体的连续性会下降。
计算墙的数量并不难,但是在我这里实现它的方式可能会很慢。
import random
width = 5
height = 5
image = [[0 for x in range(width)] for y in range(height)]
num_pts_in_individual = 4
#I realize this may give replicate points
individual = [[int(random.uniform(0,height)),int(random.uniform(0,width))] for x in range(num_pts_in_individual)]
#Fill up the image
for point in individual:
image[point[0]][point[1]] = 1
#Print out the image
for row in image:
print row
def count_shared_walls(image):
num_shared = 0
height = len(image)
width = len(image[0])
for h in range(height):
for w in range(width):
if image[h][w] == 1:
if h > 0 and image[h-1][w] == 1:
num_shared += 1
if w > 0 and image[h][w-1] == 1:
num_shared += 1
if h < height-1 and image[h+1][w] == 1:
num_shared += 1
if w < width-1 and image[h][w+1] == 1:
num_shared += 1
return num_shared
shared_walls = count_shared_walls(image)
print shared_walls
共享墙的不同图像,并计数:
[0, 0, 0, 0, 0]
[0, 1, 0, 0, 0]
[0, 0, 0, 0, 0]
[1, 0, 0, 1, 1]
[0, 0, 0, 0, 0]
2
[1, 0, 0, 0, 0]
[0, 0, 0, 1, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[1, 0, 1, 0, 0]
0
[0, 0, 0, 1, 1]
[0, 0, 0, 1, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[1, 0, 0, 0, 0]
4
一个与这个主要问题是,如果在像素位置发生变化,这并不能改变共享壁的数目,也不会影响比分。也许你所描述的距离方法和共享墙方法的组合是最好的。
一个说明性的例子会对此有所帮助。目前,我怀疑你会得到任何实质性回应。另外,当你没有提出编程问题时,请不要用语言来标记它。 – Prune
@Prune我编辑了这个问题,你还有什么建议添加以重新打开它? – h4k1m
我建议你加入更多关于你认为是什么定义一个群体的讨论,以及什么会影响连续性(我相信这就是你需要的词)。例如,考虑钻石中的一组正方形...让我们使用象棋/战列舰符号... a2,b3,b1,c2 - 与a2,c1,c1,d2处的弧相比较。哪个更连续?一个像素距离一个集群的中心还有多远,仍然是该集群的一部分?群集的邻接是否影响该范围?什么是“重力”方程,决定三个竞争集群中的哪一个(或者哪一个)声称它们之间有一个像素? – Prune