`n图像距离\u变换\u bf`转换错误的元素?

2024-04-26 18:49:40 发布

您现在位置:Python中文网/ 问答频道 /正文

ndimage.distance_transform_bf的文档中:

This function calculates the distance transform of the input, by replacing each background element (zero values), with its shortest distance to the foreground (any element non-zero).

现在让我们在代码中尝试一下:

import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage
square = np.zeros((16, 16))
square[4:-4, 4:-4] = 1
plt.imshow(square)

dist = ndimage.distance_transform_bf(square)
plt.imshow(dist)

显然,这个函数是在转换前景元素而不是背景。这是一个明显的错误还是我遗漏了什么?你知道吗


Tags: the文档importdistasnptransformplt