我需要将在黑色背景字母上绘制为白色的一系列图像转换为白色和黑色被反转的图像(作为负片).如何使用PIL实现这一目标?
我正在使用PIL库.
我试图使图像看起来更红,这就是我所拥有的.
from PIL import Image
image = Image.open('balloon.jpg')
pixels = list(image.getdata())
for pixel in pixels:
pixel[0] = pixel[0] + 20
image.putdata(pixels)
image.save('new.bmp')
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误: TypeError: 'tuple' object does not support item assignment
我不熟悉PIL,但我知道将一堆图像放入ImageMagick的网格中非常容易.
例如,我如何将16个图像放入4×4网格中,我可以指定行和列之间的间隙?
我试图拍摄大(巨大)图像(来自数码相机),并将它们转换成我可以在网络上显示的内容.这似乎很简单,也许应该是.但是,当我尝试使用PIL创建缩略图版本时,如果我的源图像高于它的宽度,则生成的图像旋转90度,使得源图像的顶部位于结果图像的左侧.如果源图像宽度高于高图像,则生成的图像是正确的(原始)方向.它可能与我发送的2元组大小有关吗?我正在使用缩略图,因为它似乎是为了保持纵横比.或者我只是完全失明,做一些愚蠢的事情?大小元组是1000,1000,因为我希望最长边缩小到1000像素,同时保持AR保持.
代码似乎很简单
img = Image.open(filename)
img.thumbnail((1000,1000), Image.ANTIALIAS)
img.save(output_fname, "JPEG")
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
我有一个PIL图像格式的图像.我需要将其转换为字节数组.
img = Image.open(fh, mode='r')
roiImg = img.crop(box)
Run Code Online (Sandbox Code Playgroud)
现在我需要roiImg作为字节数组.
我试图裁剪一个相当高的res图像并保存结果,以确保它完成.但是,无论我如何使用save方法,我都会收到以下错误:SystemError: tile cannot extend outside image
from PIL import Image
# size is width/height
img = Image.open('0_388_image1.jpeg')
box = (2407, 804, 71, 796)
area = img.crop(box)
area.save('cropped_0_388_image1', 'jpeg')
output.close()
Run Code Online (Sandbox Code Playgroud) 我有一个颜色是BGR的图像.如何转换我的PIL图像以有效的方式交换每个像素的B和R元素?
我正在做一个关于udacity的深入学习课程.对于第一次分配,当我试图运行低于问题1的脚本时,我收到了这个错误.所以我试图卸载PIL和枕头,然后单独安装,但我没有成功.我需要帮助的人.我正在使用与python笔记本的tensorflow docker图像.
# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import scipy
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline
url = 'http://commondatastorage.googleapis.com/books1000/' …Run Code Online (Sandbox Code Playgroud) 我最近的工作涉及以编程方式制作视频.在python中,典型的工作流程看起来像这样:
import subprocess, Image, ImageDraw
for i in range(frames_per_second * video_duration_seconds):
img = createFrame(i)
img.save("%07d.png" % i)
subprocess.call(["ffmpeg","-y","-r",str(frames_per_second),"-i", "%07d.png","-vcodec","mpeg4", "-qscale","5", "-r", str(frames_per_second), "video.avi"])
Run Code Online (Sandbox Code Playgroud)
此工作流程为视频中的每个帧创建一个图像并将其保存到磁盘.保存所有图像后,调用ffmpeg以构建来自所有图像的视频.
将图像保存到磁盘(而不是在内存中创建图像)会占用此处的大部分周期,并且似乎不需要.有没有办法执行相同的功能,但没有将图像保存到磁盘?因此,将调用ffmpeg并构建图像并在构造后立即将其提供给ffmpeg.
我正在尝试安装pip包PIL.但是安装不起作用会抛出以下错误.
Could not find a version that satisfies the requirement pil (from xhtml2pdf==0.0.4->-r virtualenv-reqs.txt (line 16)) (from versions: )
Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pil to allow).
No matching distribution found for pil (from xhtml2pdf==0.0.4->-r virtualenv-reqs.txt (line 16))
Run Code Online (Sandbox Code Playgroud)
当我有一个旧版本的pip时安装确实有效,但是使用当前版本的pip 7.1.2我无法下载该软件包.我使用以下命令来安装pip包
pip install --timeout=1000 -i http://pypi.ksjc.sh.colo/simple --trusted-host pypi.ksjc.sh.colo -r virtualenv-reqs.txt
Run Code Online (Sandbox Code Playgroud)
这有什么问题.我认为这可能是一个SSL问题,这就是我添加--trusted-host标志的原因.是否有任何方式将该--allow-external标志用于该virtualenv-reqs文件.