【问题标题】:How to convert a 3D dataset into a 2D dataset on a grid?如何将 3D 数据集转换为网格上的 2D 数据集?
【发布时间】:2020-11-03 07:54:06
【问题描述】:

我的问题如下:

我有一个 3D 数据集,其中 (x,y) 是网格的笛卡尔坐标,(z) 是网格中每个点的强度/频率,命名​​为 (f)。

我想将这个 3D 数据集 (x,y,f) 转换为 2D (x,y) 数据集,我将根据信号强度在 (x,y) 网格中创建新数据点.

例如,我有以下图表和数据集:
这是某种形式的“热图”,其中坐标 (z) 是信号的强度

我想将此 3D 数据集转换为 2D 数据集,其中将根据先前数据点的强度创建新数据点。例如,如果 (x=1, y=1) 的强度为 20,我想在 (x=1,y=1) 处创建 20 个强度为 1 的数据点。

【问题讨论】:

    标签: python numpy cluster-analysis reshape flatten


    【解决方案1】:

    这样的?

    # make (small) example
    f = np.random.randint(1,4,(2,3))
    yxf = np.c_[(*map(np.ravel,(*np.indices(f.shape),f)),)]
    yxf
    # array([[0, 0, 1],
    #        [0, 1, 3],
    #        [0, 2, 3],
    #        [1, 0, 2],
    #        [1, 1, 2],
    #        [1, 2, 2]])
    
    # process 
    yxf[:,:2].repeat(yxf[:,2],axis=0)
    # array([[0, 0],
    #        [0, 1],
    #        [0, 1],
    #        [0, 1],
    #        [0, 2],
    #        [0, 2],
    #        [0, 2],
    #        [1, 0],
    #        [1, 0],
    #        [1, 1],
    #        [1, 1],
    #        [1, 2],
    #        [1, 2]])
    

    【讨论】:

      【解决方案2】:

      如果您安装了 scikit 模块,那么您可以使用 rgb2grey(或 rgb2gray)制作从彩色到灰色(从 3D 到 2D)的照片

      from skimage import io, color
      
      lina_color = io.imread(path+img)
      lina_gray = color.rgb2gray(lina_color)
      
      In [33]: lina_color.shape
      Out[33]: (1920, 1280, 3)
      
      In [34]: lina_gray.shape
      Out[34]: (1920, 1280)
      

      【讨论】:

        猜你喜欢
        • 2022-06-15
        • 2022-06-29
        • 2018-07-22
        • 2020-06-06
        • 1970-01-01
        • 2015-11-28
        • 1970-01-01
        • 2016-11-01
        • 2021-05-23
        相关资源
        最近更新 更多