skimage regionprops 方向产生令人困惑的结果

skimage regionprops orientation producing confusing results

我想了解 skimage.measure.regionprops_table 的方向输出,但我有点困惑。谁能帮助我理解方向的输出?

根据文档,orientation returns 第 0 轴(行)和与区域具有相同二阶矩的椭圆长轴之间的角度,范围从 -pi/2 到 pi/2 逆时针。

在下面的代码示例中,我沿 x 轴创建了一个矩形,因此长轴沿 x 轴。我希望获得 0 度的方向角,但我得到了 90 度。对于旋转 90 度的矩形,它 returns 0 度方向角。我有点困惑为什么会这样。不应该反过来吗?对于以 30 度放置的矩形,方向 returns -60 度。

第 0 个轴(行)是什么意思?可能有人可以根据以下示例指导我。

这是我试过的一个简单代码:

from skimage.transform import rotate
import cv2
import numpy as np
from matplotlib import pyplot as plt
from skimage import measure
import pandas as pd
import math
from skimage.util import img_as_ubyte

testimg = np.zeros([100,150],dtype=np.uint8)
cv2.rectangle(testimg, (30, 40), (70, 50), (255,0,0), -1)
#testimg = img_as_ubyte(rotate(testimg, angle=90, order=0))
ret1, thresh = cv2.threshold(testimg, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
plt.imshow(thresh, cmap='gray')

ret3, markers = cv2.connectedComponents(thresh)
plt.imshow(markers)
testprops = measure.regionprops_table(markers, properties=['label', 'area', 'centroid', 'major_axis_length', 'minor_axis_length', 'orientation']) # v18.x
testdata = pd.DataFrame(testprops)
testdata['angle_degree'] = math.degrees(testdata['orientation'])

在scikit-image中,在2D中,“第0”轴是行,从左上角的0到左下角的n。您可以在文档的“坐标约定”页面中阅读更多相关信息:

https://scikit-image.org/docs/0.19.x/user_guide/numpy_images.html#coordinate-conventions

这样做是为了将坐标与 NumPy 数组的索引进行匹配。这意味着确实,方向 0 对应于垂直,90 对应于水平。