[英]PIL (Python 3.4) modifies RGV value
Here is a code that create a little 10×10 picture, all green, in jpg format: 这是一个代码,以jpg格式创建一个10×10的小图片,全部为绿色:
import PIL.Image as img
im = img.new('RGB', (10,10), (0,255,0))
print(np.array(im))
[[[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]
[ 0 255 0]]
...
So, it is ok. 所以,没关系。 But if the file is saved then opened: 但如果文件已保存,则打开:
im.save(chemin+"essai.jpg")
it = np.array(img.open(chemin+"essai.jpg"))
print(it)
array([[[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1],
[ 0, 255, 1]],
...
Why is there 1 in the Blue component? 为什么Blue组件中有1个?
It is the same if I do a red picture [255,0,0]
which gives after saving and opening: [254,0,0]
. 如果我在保存和打开后给出红色图片[255,0,0]
,则相同: [254,0,0]
。 So why 254? 那么为什么254?
It seems to be when saving and not when loading because if I open the saved file in a software like photoshop, the color is already modified. 它似乎是在保存时而不是在加载时,因为如果我在像photoshop这样的软件中打开保存的文件,颜色就已经被修改了。
If someone has an answer. 如果有人有答案。 (And sorry for my bad english). (抱歉我的英语不好)。 Thank you! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.