代码之家  ›  专栏  ›  技术社区  ›  hatmatrix

在python中将图像转换为矩阵

  •  24
  • hatmatrix  · 技术社区  · 14 年前

    我想用Python做一些图像处理。

    有什么简单的方法可以导入吗 .png 作为灰度/RGB值矩阵的图像(可能使用PIL)?

    5 回复  |  直到 9 年前
        1
  •  33
  •   ptomato    14 年前

    scipy.misc.imread()

        2
  •  12
  •   Salvador Dali    9 年前

    到目前为止还没有人告诉我 matplotlib.image

    import matplotlib.image as img
    image = img.imread(file_name)
    

    现在图像将是一个3D numpy数组

    print image.shape
    

    (317, 504, 3)

        3
  •  6
  •   Katriel    14 年前

    im.load 在里面 PIL 返回类似于矩阵的对象。

        4
  •  5
  •   anon    6 年前

    scipy.misc.imread() imageio.imread 而不是把它读作Numpy数组

        5
  •  2
  •   Nikolaus Gradwohl    14 年前

    你可以用 PyGame image 使用 PixelArray 访问像素数据

        6
  •  1
  •   FellerRock    5 年前

    from matplotlib.image import imread
    
    image  = imread(filename)  
    

    文件名最好是 形象。 然后,试试看

    image.shape
    

    这将返回:

    • 对于黑白或灰度图像 矩阵,其中n表示图像的尺寸(像素),矩阵内的值范围为0到255。

    • 对于彩色或RGB图像 (不,不) 矩阵,其中每个条目分别表示图像内部实际位置的红色、绿色或蓝色级别。