import matplotlib.pyplot as plt
import numpy as np
a=np.random.randint(2, size=(3,3))#生成3x3随机黑白图
im = plt.imshow(a, cmap=‘Greys’, interpolation=‘none’, vmin=0, vmax=1, aspect=‘equal’)#显示图像
print(a)
startle = float(“inf”)
if a[1][1] == 1:
for i in range(0,a.shape[0]):
for j in range(0,a.shape[0]):
b = np.array([i,j])
if a[i][j]==1:
continue
L1 = np.sqrt(np.sum((a[1][1] - b) ** 2))
if L1 < startle:
startle = L1
print (startle)#历遍,算中心点到邻居点距离
plt.show()
3x3黑白图像算中心点最短距离
最新推荐文章于 2024-07-19 16:36:18 发布