numpy with python: convert 3d array to 2d

前端 未结 3 565
一生所求
一生所求 2020-12-03 01:23

Say that I have a color image, and naturally this will be represented by a 3-dimensional array in python, say of shape (n x m x 3) and call it img.

I want a new 2-d

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 02:18

    If you have the scikit module installed, then you can use the rgb2grey (or rgb2gray) to make a photo from color to gray (from 3D to 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)
    

提交回复
热议问题