【问题标题】:getting pixel value for image indexed by labels获取由标签索引的图像的像素值
【发布时间】:2023-03-19 10:18:01
【问题描述】:

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

我确信在 Numpy 中有一种非常 Pythonic 的方式来做到这一点。

【问题讨论】:

    标签: python numpy indexing


    【解决方案1】:

    您可以像这样使用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]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 2014-07-16
      • 2020-04-13
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      相关资源
      最近更新 更多