我试图从我的图像中删除某种颜色,但它没有像我希望的那样好用.我尝试做同样的事情使用PIL使所有白色像素透明?然而,图像质量有点损失,因此它会在被移除的地方留下一些奇怪的彩色像素.如果所有三个值都低于100,我尝试做像更改像素这样的事情但由于图像质量差,周围的像素甚至都不是黑色.
有没有人知道用Python中的PIL更好的方法来替换它周围的颜色和任何东西?这可能是我能想到的完全移除物体的唯一确定的火力方式,但我想不出办法做到这一点.
图片为白色背景,文字为黑色.我们只想说我想从图像中完全删除文本而不留下任何文物.
非常感谢别人的帮助!谢谢
我正在寻找一个命令,它将使用PIL在现有图像上绘制一个圆圈.
im = Image.open(path)
Run Code Online (Sandbox Code Playgroud)
我想要一个能绘制半径r和中心的彩色圆圈的功能(x,y)
目前我正在将PIL安装到我的虚拟环境中,如下所示:
pip install -E . -r ./releases/%s/requirements.txt
Run Code Online (Sandbox Code Playgroud)
其中requirements.txt包含:
pil
Run Code Online (Sandbox Code Playgroud)
我现在可以上传png图片但不能上传jpeg图片.从网上阅读看来我可能需要libjpeg解码器?我安装pil不正确吗?使用libjpeg在虚拟环境中安装django的正确方法是什么?
我对在Mac OS X 10.6上安装PIL(Python Imaging Library)感到非常恼火.有没有人安装它,可以在这里发布食谱?我已经尝试了很多这些在这个网站上发布了很多来自谷歌,但总是缺少一些部分而且无法正常使用PIL ......
提前致谢.Ignas
我有一个RGB三元组列表,我想以这样的方式绘制它们,使它们形成像光谱一样的东西.
我把它们转换成了人们似乎推荐的HSV.
from PIL import Image, ImageDraw
import colorsys
def make_rainbow_rgb(colors, width, height):
"""colors is an array of RGB tuples, with values between 0 and 255"""
img = Image.new("RGBA", (width, height))
canvas = ImageDraw.Draw(img)
def hsl(x):
to_float = lambda x : x / 255.0
(r, g, b) = map(to_float, x)
h, s, l = colorsys.rgb_to_hsv(r,g,b)
h = h if 0 < h else 1 # 0 -> 1
return h, s, l
rainbow = sorted(colors, key=hsl)
dx = width / …Run Code Online (Sandbox Code Playgroud) 我发现了如何使用PIL来获取图像尺寸,而不是文件大小(以字节为单位).我需要知道文件大小来决定文件是否太大而无法上传到数据库.
出于某种原因,当我尝试从BytesIO蒸汽制作图像时,它无法识别图像.这是我的代码:
from PIL import Image, ImageGrab
from io import BytesIO
i = ImageGrab.grab()
i.resize((1280, 720))
output = BytesIO()
i.save(output, format = "JPEG")
output.flush()
print(isinstance(Image.open(output), Image.Image))
Run Code Online (Sandbox Code Playgroud)
它抛出的错误的堆栈跟踪:
Traceback (most recent call last):
File "C:/Users/Natecat/PycharmProjects/Python/test.py", line 9, in <module>
print(isinstance(Image.open(output), Image.Image))
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2126, in open
% (filename if filename else fp))
IOError: cannot identify image file <_io.BytesIO object at 0x02394DB0>
Run Code Online (Sandbox Code Playgroud)
我正在使用PIL的Pillow实现.
任何人都可以帮助我阅读.tiff图像并转换为jpeg格式?
from PIL import Image
im = Image.open('test.tiff')
im.save('test.jpeg')
Run Code Online (Sandbox Code Playgroud)
上面的代码无效.
我喜欢制作高质量的地块,因此尽可能避免光栅化的图形.
我正在尝试将svg文件导入到matplotlib图中:
import matplotlib.pyplot as plt
earth = plt.imread('./gfx/earth.svg')
fig, ax = plt.subplots()
im = ax.imshow(earth)
plt.show()
Run Code Online (Sandbox Code Playgroud)
这与png完美配合.有人可以告诉我如何使用svg或至少指出我的正确文档.
我知道有一个类似的问题已经被问到(但没有回答):这里.从那以后有什么变化吗
PS我知道我可以导出高分辨率的png并实现类似的效果.这不是我要找的解决方案.
这是我要导入的图像:Earth_from_above.
任何提示都表示赞赏.谢谢!
我正在尝试使用PIL /枕头的ImageDraw模块在图像上绘制粗矩形.
我试过使用draw.rectangle([x1, y1, x2, y2], outline='yellow', width=3)但它似乎不喜欢width参数.
我可以用一堆线来模仿我想做的事情,但我想知道是否有一种正确的方法.
'''
coordinates = [(x1, y1), (x2, y2)]
(x1, y1)
*--------------
| |
| |
| |
| |
| |
| |
--------------*
(x2, y2)
'''
def draw_rectangle(drawing, xy, outline='yellow', width=10):
top_left = xy[0]
bottom_right = xy[1]
top_right = (xy[1][0], xy[0][1])
bottom_left= (xy[0][0], xy[1][1])
drawing.line([top_left, top_right], fill=outline, width=width)
drawing.line([top_right, bottom_right], fill=outline, width=width)
drawing.line([bottom_right, bottom_left], fill=outline, width=width)
drawing.line([bottom_left, top_left], fill=outline, width=width)
Run Code Online (Sandbox Code Playgroud) python ×7
django ×2
color-space ×1
colors ×1
draw ×1
filesize ×1
hsv ×1
image ×1
jpeg ×1
macos ×1
matplotlib ×1
pillow ×1
pip ×1
python-2.7 ×1
replace ×1
spectrum ×1
svg ×1
tiff ×1
tornado ×1
virtualenv ×1