我試圖了解方向輸出,skimage.measure.regionprops_table但我有點困惑。任何人都可以幫助我了解方向的輸出嗎?
根據檔案,orientation回傳第 0 軸(行)和橢圓長軸之間的角度,該橢圓的第二矩與該區域具有相同的秒矩,逆時針范圍從 -pi/2 到 pi/2。
在下面的代碼示例中,我沿 x 軸創建了一個矩形,因此主軸沿 x 軸。我希望得到 0 度的方向角,但我得到了 90 度。對于 90 度旋轉的矩形,它回傳 0 度方向角。我有點困惑為什么會這樣。不應該反過來嗎?對于以 30 度放置的矩形,方向回傳 -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'])
uj5u.com熱心網友回復:
在 scikit-image 中,在 2D 中,“第 0”軸是行,從左上角的 0 到左下角的 n。您可以在檔案的“坐標約定”頁面中閱讀更多相關資訊:
https://scikit-image.org/docs/0.19.x/user_guide/numpy_images.html#coordinate-conventions
這樣做是為了將坐標與 NumPy 陣列的索引相匹配。這意味著實際上,0 的方向對應于垂直,90 對應于水平。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429209.html
標籤:python-3.x scikit 图像
