gpt4 book ai didi

python - 如何随机拾取二值图像中非零像素的位置?

转载 作者:太空宇宙 更新时间:2023-11-04 02:05:45 25 4
gpt4 key购买 nike

我有一个大小为 NxMxK 的二进制图像。我想随机选取图像中的非零像素位置。但是,我只能得到所有非零像素的图。我应该如何使用 python 来完成

我正在使用

location = np.where(array==True)
#Return
(array([ 66, 66, 66, ..., 133, 133, 133]), array([35, 35, 35, ..., 59, 59, 59]), array([102, 103, 104, ..., 105, 106, 107]))

我的预期是像素位置喜欢 (66,35,102) 或 (66,35,103)...因为它是随机的

更新:这是我目前的解决方案

ln = np.random.choice (indices[0], size=1)[0]
lm = np.random.choice (indices[1], size=1)[0]
lk = np.random.choice (indices[2], size=1)[0]

最佳答案

你在找吗

np.random.choice (location, size=1)

关于python - 如何随机拾取二值图像中非零像素的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54775944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com