使用scipy ndimage.measurements.center_of_mass错误的质心

时间:2019-04-15 23:53:57

标签: python-3.x numpy scipy

我正在尝试使用Scipy库中的ndimage.measurements.center_of_mass在二进制图像上找到重心。

我的代码如下:

def show_keypoints(image, key_point):
    plt.imshow(image, interpolation='nearest')
    plt.scatter(key_point[0],key_point[1], s=20, marker='.', c='lightgreen')


#Loading the image (shape : (576,576) as np.array))
img = load_img(path)
centroid = scipy.ndimage.measurements.center_of_mass(img)

fig = plt.figure()  
ax = plt.subplot()
ax.set_title('Label')
show_keypoints(img, centroid)
plt.show()   

获取:

enter image description here

因此,我检查了输入的图像是否正确,这是正确的,我使用np.unique(imgs[i])得到了(array([0, 1], dtype=uint8),检查图像是否为二进制。

我不确定这里不是什么。

有人有主意吗?

此致

1 个答案:

答案 0 :(得分:2)

将参数的顺序更改为分散:

def update(tree: Tree, id: String, val: Int): Tree = {
  tree match {
    case NodeType1(childs) =>
      NodeType1(childs.map(update(_, id, val)))
    case NodeType2(a, childs) =>
      NodeType2(a, childs.map(update(_, id, val))
    case NodeType3(a, b, childs) =>
      NodeType3(a, b, childs.map(update(_, id, val))
    ...  
    case Leaf(`id`, oldVal) =>
      Leaf(id, val)
  }
}

plt.scatter(key_point[1], key_point[0], s=20, marker='.', c='lightgreen') 使用基于图像的约定来绘制其数据,而imshowscatter使用常规(x,y)坐标。

相关问题