我正在嘗試獲取此影像沿軸 = 0 的非白色最小和最大像素位置。但是,np.where 不能沿軸 = 零作業。我已經嘗試了其他 np 功能,但它們不起作用。我已經閱讀了檔案,但仍然沒有解決。有沒有人有這個功能?


uj5u.com熱心網友回復:
如果我正確理解了這個問題,那么目標是找到限制包含所有非白色像素的影像區域的行和列的索引。例如,這可以如下進行。
加載示例影像:
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("sample.jpg").copy()
plt.imshow(img)

找到非白色像素的邊界框并顯示結果:
# indices of non-white pixels
rows, cols = np.nonzero(np.any(img != 255, axis=-1))
# indices of rows and columns of the bounding box
rbox = rows.min(), rows.max()
cbox = cols.min(), cols.max()
# show the selection
img[rbox[0]:rbox[1] 1, cbox[0]:cbox[1] 1, 1] = 0
plt.imshow(img)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/407672.html
標籤:
