gpt4 book ai didi

python - 获取由标签索引的图像的像素值

转载 作者:行者123 更新时间:2023-12-01 08:22:43 24 4
gpt4 key购买 nike

我有一个已分割的 RGB 图像 Img(256,256,3)。该图像的标签位于数组 Lbl(256,256) 中,标签值的范围为 0-n,其中 n 是图像中的簇数。如何获取分配给特定簇的像素的实际 RGB 值?例如,如何找到分配给聚类 1 的所有像素值?

我确信在 Numpy 中有一种非常 Pythonic 的方法可以做到这一点。

最佳答案

您可以使用 np.where() 来做到这一点,如下所示:

import numpy as np

# Make sample empty image
a = np.zeros((8,8),dtype=np.uint8)

# Label a couple of random pixels as "3" to find
a[2,2]=3
a[3,4]=3

# Find them
my3s = np.where(a==3)
Out[13]: (array([2, 3]), array([2, 4]))

关于python - 获取由标签索引的图像的像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522562/

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