我试图通过粘贴许多较小的图像来创建一个非常大的图像(25000x25000).在调用具有如此大尺寸的Image.new()时,python会耗尽内存并且我得到一个MemoryError.
有没有办法逐步写出这样的图像,而没有整个东西驻留在RAM中?
编辑:使用ImageMagick的montage命令,似乎可以创建任意大小的图像.看起来它并没有尝试将最终映像加载到RAM中(它在进程中使用的内存很少),而是将其流式传输到磁盘,这是理想的选择.
我需要使用PIL将此图像切割成三个部分并选择中间部分.我该怎么做?
http://thedilbertstore.com/images/periodic_content/dilbert/dt110507dhct.jpg
python image-manipulation image-segmentation python-imaging-library
我正在尝试在我的项目中使用PIL,但pydev似乎无法在我的项目中找到它.首先,当我进入python shell时,我可以看到它,我可以导入它,我在python sys.path中看到它.其次,我把它添加到日食中的PYTHONPATH.
我重新启动了eclipse,但是,当我尝试"从PIL导入图像"时,我得到:"未解决的导入".
任何人都可以在这里帮助我,我使用的所有其他包直到现在以相同的方式工作....我真的需要使用PIL
我有8位灰度TIFF图像,我想使用75%白色(十进制190)阈值转换为单色.在Image.convert(模式)方法部分,PIL手册说:
"将灰度图像转换为位级图像(模式"1")时,所有非零值都设置为255(白色).要使用其他阈值,请使用点法."
Image.point(table)方法表示它通过给定的表映射每个像素.
im.point(table,mode)=> image
im.point(function,mode)=> image"通过表格映射图像,并在飞行中进行转换.在当前版本的PIL中,这只能用于在一步中将'L'和'P'图像转换为'1',例如对图像进行阈值处理."
如何创建与我需要的75%阈值相对应的表(或函数)?
我在使用PIL绘制多语言文本时遇到问题.让我们说我想画文字 - "ひらがな - 平假名,히라가나".但是PIL的ImageDraw.text()函数一次只能使用一种字体,因此我无法正确绘制该文本,因为它需要英文,日文和韩文字体.
到目前为止,我没有找到一个简单的解决方案,比如将多个字体传递给PIL,这样它就可以为每个Unicode字符选择合适的字体(就像现代SDK或Web浏览器一样).
我在想的是,我应该遍历每个角色,并确定自己为每个角色使用哪种字体.但我不禁想到必须有一个更简单的方法来做到这一点.
我正朝着正确的方向前进吗?是不是有更简单的方法?
PS)如果有更好的解决方案,可以使用其他语言或其他成像库.
我试图绘制一个简单的圆圈并使用Python Imaging Library将其保存到文件中:
import Image, ImageDraw
image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
draw.ellipse((20, 180, 180, 20), fill = 'blue', outline ='blue')
draw.point((100, 100), 'red')
image.save('test.png')
Run Code Online (Sandbox Code Playgroud)
该点draw.point出现在图像上,但椭圆本身不会出现.我尝试将模式更改为just RGB(我认为模式可能会影响显示的内容),但这并没有解决它.
我怎样才能解决这个问题?谢谢!
我正在使用Mac OS x 10.10.3 Yosemite和Python 2.7.9 | Anaconda 2.2.0(x86_64)来处理很多python的东西.我正在使用eclipse和谷歌应用引擎.
我已经没有堆栈溢出帖子来读取很多人都有的这个错误,然后通过某种方式解决这个问题对我来说不起作用.
我收到这个错误:
import Image ImportError:没有名为Image的模块
从这段代码:
try:
from PIL import Image
except:
import Image
Run Code Online (Sandbox Code Playgroud)
在我尝试了以下之后:
conda install pillow
sudo pip install pillow
pip install pillow
pip install pil
Run Code Online (Sandbox Code Playgroud)
一些堆栈溢出帖子建议查看该路径是否适用于其他用户,所以我在终端中尝试了这个:
python
Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org …Run Code Online (Sandbox Code Playgroud) 我是Python的新手,并尝试运行以下代码.我收到以下错误"IOError: cannot open resource".这是因为某些图像特征不再存在(例如Coval.otf),还是由于写入/读取限制?请让我知道 - 非常感谢,W
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from skimage import transform as tf
def create_captcha(text, shear=0, size=(100,24)):
im = Image.new("L", size, "black")
draw = ImageDraw.Draw(im)
font = ImageFont.truetype(r"Coval.otf", 22)
draw.text((2, 2), text, fill=1, font=font)
image = np.array(im)
affine_tf = tf.AffineTransform(shear=shear)
image = tf.warp(image, affine_tf)
return image / image.max()
%matplotlib inline
from matplotlib import pyplot as plt
image = create_captcha("GENE", shear=0.5)
Run Code Online (Sandbox Code Playgroud) 我有一个应该改变对比度的程序,但我觉得它并没有真正改变对比度.它将某些区域变为红色而我不希望它.如果你能告诉我如何删除它们,谢谢.这是代码:
from PIL import Image
def change_contrast(img, level):
img = Image.open("C:\\Users\\omar\\Desktop\\Site\\Images\\obama.png")
img.load()
factor = (259 * (level+255)) / (255 * (259-level))
for x in range(img.size[0]):
for y in range(img.size[1]):
color = img.getpixel((x, y))
new_color = tuple(int(factor * (c-128) + 128) for c in color)
img.putpixel((x, y), new_color)
return img
result = change_contrast('C:\\Users\\omar\\Desktop\\Site\\Images\\test_image1.jpg', 100)
result.save('C:\\Users\\omar\\Desktop\\Site\\Images\\test_image1_output.jpg')
print('done')
Run Code Online (Sandbox Code Playgroud)
这是图像及其结果:
如果这是实际的对比方法,请随时告诉我
我正在尝试将html5视频转换为mp4视频,并且我是通过PhantomJS随着时间的推移进行屏幕拍摄
我也使用PIL裁剪图像,所以最终我的代码大致是:
while time() < end_time:
screenshot_list.append(phantom.get_screenshot_as_base64())
.
.
for screenshot in screenshot_list:
im = Image.open(BytesIO(base64.b64decode(screenshot)))
im = im.crop((left, top, right, bottom))
Run Code Online (Sandbox Code Playgroud)
现在我正在保存以删除所有这些图像并使用保存文件中的ffmpeg:
os.system('ffmpeg -r {fps} -f image2 -s {width}x{height} -i {screenshots_dir}%04d.png -vf scale={width}:-2 '
'-vcodec libx264 -crf 25 -vb 20M -pix_fmt yuv420p {output}'.format(fps=fps, width=width,
screenshots_dir=screenshots_dir,
height=height, output=output))
Run Code Online (Sandbox Code Playgroud)
但我想要而不是使用那些保存的文件,能够将PIL.Images直接传递给ffmpeg,我该怎么做?