我找不到这样的功能(即 RGB_to_HSV())Scipy或Matplotlib's文档,谷歌没有显示指针,除了ActiveState展示rgb2hsv功能的配方,虽然不能在Numpy数组上使用.
有人知道捷径吗?
编辑:对不起,刚发现matplotlib.colors.rgb_to_hsv()这正是我想要的.我应该删除这个问题吗?
使用PIL(1.1.7)创建的JPEG图像质量非常差.这是一个例子:
输入:https://s23.postimg.cc/8bks3x5p7/cover_1.jpg
输出:https://s23.postimg.cc/68ey9zva3/cover_2.jpg
使用以下代码创建输出图像:
from PIL import Image
im = Image.open('/path/to/cover_1.jpg')
im.save('/path/to/cover_2.jpg', format='JPEG', quality=100)
Run Code Online (Sandbox Code Playgroud)
红色文字看起来非常糟糕.使用GIMP或Photoshop保存图像甚至不能接近PIL创建的质量差.有人知道为什么会发生这种情况以及如何解决这个问题?
我正在尝试使用Python Imaging Library将图像粘贴到backgorund上,如下所示:
card = Image.new("RGB", (220, 220), (255, 255, 255))
img = Image.open("/Users/paulvorobyev/test.png")
...
x, y = img.size
card.paste(img, (0, 0, x, y), img)
card.save("test.png")
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我得到:
"ValueError: bad transparency mask"
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我有一个(n,m)数组,我一直在想象matplotlib.pyplot.imshow.我想将这些数据保存在某种类型的光栅图形文件中(例如png),以便:
imshowinterpolation='nearest'的imshow).我怎样才能做到这一点?
我已经看到一些代码可以做到这一点,通过使用interpolation='nearest'和强制matplotlib(勉强)关闭轴,空格等.但是,必须有一些方法来更直接地做到这一点 - 也许与PIL?毕竟,我有基础数据.如果我可以为底层数组的每个元素获取RGB值,那么我可以使用PIL保存它.有没有办法从中提取RGB数据imshow?我可以编写自己的代码来将数组值映射到RGB值,但我不想重新发明轮子,因为matplotlib中已经存在该功能.
我需要python来改变图片上一个像素的颜色,我该怎么做呢?
我已经看过这个问题了:问题似乎已经实现了一种非常类似的技术来替换包括alpha值在内的单一颜色:
c = Image.open(f)
c = c.convert("RGBA")
w, h = c.size
cnt = 0
for px in c.getdata():
c.putpixel((int(cnt % w), int(cnt / w)), (255, 0, 0, px[3]))
cnt += 1
Run Code Online (Sandbox Code Playgroud)
但是,这很慢.我在互联网上发现了这个配方,但到目前为止还没有成功使用它:配方
我想要做的是拍摄由单一颜色,白色组成的各种PNG图像.每个像素都是100%白色,具有各种alpha值,包括alpha = 0.我想要做的是基本上使用新的设置颜色着色图像,例如#ff0000 <00-ff>.所以我的开始和结果图像看起来像这样,左边是我的起始图像,右边是我的结束图像(注意:背景已经变为浅灰色,所以你可以看到它,因为它实际上是透明的,你不会'能够看到左边的点.)

有更好的方法吗?
我需要在本地安装PIL以在我的本地环境中测试GAE的图像api.
我抓住了Mac的PIL 1.1.6安装程序,当我去选择目的地时(安装时),我收到错误:
You cannot install PIL 1.1.6 on this volume.
PIL requires System Python 2.5 to install.
Run Code Online (Sandbox Code Playgroud)
我在这台机器上有Python 2.5.x.
注意:
增加了赏金.我真的需要一种在Mac上本地测试图像API的方法.
python macos google-app-engine osx-leopard python-imaging-library
我有一张苹果的彩色照片,我怎样才能用python/PIL显示它的轮廓(白色内部,背景黑色)?
import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import urllib.request
with urllib.request.urlopen('http://pastebin.ca/raw/2311595') as in_file:
hex_data = in_file.read()
print(hex_data)
img = Image.frombuffer('RGB', (320,240), hex_data) #i have tried fromstring
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf",14)
draw.text((0, 220),"This is a test11",(255,255,0),font=font)
draw = ImageDraw.Draw(img)
img.save("a_test.jpg")
Run Code Online (Sandbox Code Playgroud)
即时尝试将二进制转换为图像,然后绘制文本.但我得到错误:
img = Image.frombuffer('RGB', (320,240), hex_data)
raise ValueError("not enough image data")
ValueError: not enough image data
Run Code Online (Sandbox Code Playgroud)
我已经在这里http://pastebin.ca/raw/2311595上传了字节字符串,
图片大小我可以肯定是320x240
这里是我可以肯定的图片字节字符串是来自320x240,只需运行代码就会从字节字符串中创建一个图像
import urllib.request
import binascii
import struct
# Download the data. …Run Code Online (Sandbox Code Playgroud) 我有一个a类型的numpy数组float64.如何使用高斯滤波器模糊此数据?
我试过了
from PIL import Image, ImageFilter
image = Image.fromarray(a)
filtered = image.filter(ImageFilter.GaussianBlur(radius=7))
Run Code Online (Sandbox Code Playgroud)
,但这会产生ValueError: 'image has wrong mode'.(它有模式F.)
我可以通过乘以a一些常数,然后舍入到整数来创建合适模式的图像.这应该有效,但我希望有一个更直接的方式.
(我正在使用Pillow 2.7.0.)