我想我明白你在問什麼,我的建議是計算你的像素之間共享的「牆壁」的數量:![different types of continuity](https://i.stack.imgur.com/EBmay.png)
我認爲從左到右,個體的連續性會下降。
計算牆的數量並不難,但是在我這裏實現它的方式可能會很慢。
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