简体   繁体   English

使用Python的pillow / PIL库:

[英]Using Python's pillow/PIL library:

In the following code I am trying to do the following by using Python's pillow/PIL library: 在以下代码中,我尝试通过使用Python的pillow / PIL库执行以下操作:

  1. Read in an image file, store it as a matrix 读取图像文件,将其存储为矩阵
  2. Access the red, blue, green channel which is an unsigned integer unit8 and convert each channel to float64 访问红色,蓝色,绿色通道,该通道为无符号整数unit8,并将每个通道转换为float64

This is my first time using Python's pillow/PIL library and I just wanted to clarify if I have achieved these 2 things correctly. 这是我第一次使用Python的pillow / PIL库,我只是想澄清一下我是否正确实现了这两件事。

Here my is my code I have produced: 这是我产生的代码:

import numpy as np
from PIL import Image
img = Image.open('house.jpg')
image = np.array(img)
arr[20,30]
red = np.float64(image[:,:, 0])
green = np.float64(image[:,:,1])
blue = np.float64(image[:,:,2])

and for instance, when I use 例如,当我使用

print(red)

I get the following output: 我得到以下输出:

[[ 34.  41.  49. ...  22.  22.  22.]
 [ 28.  34.  41. ...  23.  23.  23.]
 [ 23.  26.  30. ...  24.  24.  24.]
 ...
 [ 32.  45.  57. ... 105.  97. 109.]
 [ 34.  32.  41. ... 100.  94. 113.]
 [ 33.  36.  52. ...  99.  90. 113.]]

You could, more simply, use: 您可以更简单地使用:

import numpy as np
from PIL import Image

img = Image.open('house.jpg')
image=np.array(img,dtype=np.float64)   
...
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM