草庐IT

python - 如何将 RGB PIL 图像转换为具有 3 个 channel 的 numpy 数组?

我正在使用以下代码加载图像image=PIL.Image.open(file_path)image=np.array(image)有效,但数组的大小似乎是(X,X,4),即它有4层。我想要普通的RGB图层。可能吗?更新我发现仅删除第4个channel是不够的。需要以下代码:image=PIL.Image.open(file_path)image.thumbnail(resample_size)image=image.convert("RGB")image=np.asarray(image,dtype=np.float32)/255image=image[:,:,:3]为什么?

Python PIL ImageTk.PhotoImage() 给我一个总线错误?

所以我在macbookpro上运行python2.6并尝试用python编写代码以在tkintergui上的标签中显示文件中的图像。该图像称为image.png。当我使用这段代码时程序运行没有错误i=Image.open("image.png")但是当我执行这段代码时(我添加了一行):i=Image.open("image.png")photo=ImageTk.PhotoImage(i)程序将崩溃并在命令行中显示“总线错误”。我什至不知道那是什么意思。我认为PIL安装正确,因为Image可以工作,但ImageTk不工作这一事实让我感到困惑。谁能告诉我可能导致此总线错误的原因是什么?编辑

python - Django/PIL 错误 - 呈现 : The _imagingft C module is not installed 时捕获异常

我正在尝试在我的机器上运行一个网络应用程序/网站,它在OSX10.6.2上运行,但我遇到了一些问题:Caughtanexeptionwhilerending:The_imagingftCmoduleisnotinstalled在python中执行import_imagingft给我这个:>>>import_imagingftTraceback(mostrecentcalllast):File"",line1,inImportError:dlopen(/Library/Python/2.6/site-packages/PIL/_imagingft.so,2):Symbolnotfound

Python - 未检测到使用 easy_install 安装的包 (PIL 1.1.7)

我使用easy_install安装了PIL,但出于某种原因,当我运行一个使用它的文件时,我得到:ImportError:NomodulenamedPIL有人知道为什么会这样吗?我认为还值得一提的是,我通过easy_install安装了web.py,它工作正常。 最佳答案 我也遇到了同样的问题。对我来说,它看起来像是PILeasy_install过程中的错误。该库已安装,但您必须从导入中省略PIL(又名importImage作品),这显然是错误的。要解决,不要使用easy_install来执行安装。下载tar包并pythonsetup

python - PIL : PNG image as watermark for a JPG image

我正在尝试从JPEG照片(1600x900)和带有alphachannel(400x62)的PNGLogo制作合成图像。这是一个用图像魔法完成工作的命令:composite-geometry+25+25watermark.pngoriginal_photo.jpgwatermarked_photo.jpg现在我想在python脚本中做一些类似的事情,而不用从外部调用这个shell命令,使用PIL。这是我尝试过的:photo=Image.open('original_photo.jpg')watermark=Image.open('watermark.png')photo.paste(w

python - 使用 Python 的 PIL,如何增强图像的对比度/饱和度?

只是简单的对比度和饱和度增强。没什么特别的。 最佳答案 因为PIL大部分时间都死了。安装Pillowfork,sudopipinstallpillow,并使用其ImageEnhance模块http://pillow.readthedocs.org/en/3.0.x/reference/ImageEnhance.html>>>fromPILimportImage,ImageEnhance>>>image=Image.open('downloads/jcfeb2011.jpg')>>>contrast=ImageEnhance.Cont

python - 使用 SWIG 编码(marshal) Python PIL 图像

我有一个采用非常简单的C图像结构的库://Representsaone-channel8-bitimagetypedefstructsimple_image_t{uint32rows;uint32cols;uint8*imgdata;}simple_image;我没有创建这个库,也没有创建这个结构,所以我不能改变它。我负责使用SWIG为python包装这个库。Python包装器需要能够接收PIL图像并将其转换为该结构。这是我现在的做法(使用SWIG%inline%)://Allowspythontoeasilycreateandinitializethisstructuresimple

python - 如何在 PyPy 中使用 PIL?

我搜索了一下,但找不到将PIL与PyPy结合使用的教程。根据PyPy的博客,支持PIL。我在我的PYTHONPATH中使用pip安装了PIL。下载后,pip生成2个.pyd文件:_imaging.pyd和_imagingmath.pyd。安装后,我将%PYTHONPATH%/lib/site-packages/PIL复制到我的PyPy站点包目录。当我运行我的脚本(使用PIL)时,它说它无法导入_imagingC模块。我应该怎么做?编辑:我在Windows7x64(python2.7.132位)上运行它这是回溯(pypy1.4.1windows二进制文件):Traceback(mostr

python - Anaconda python、PIL 和 imagingtk

虽然这是相当不错的documented问题,我找不到解决方案。我无法导入PIL和ImageTK。最小的例子:importTkinterastkfromPILimportImage,ImageTkroot=tk.Tk()image=Image.open('live.ppm')photo=ImageTk.PhotoImage(image)这会产生错误:File"C:\Anaconda\lib\site-packages\PIL\ImageTk.py",line181,inpasteimport_imagingtkImportError:Nomodulenamed_imagingtk我试过:

python - 来自 pil 对象的 md5

如何在不保存到文件的情况下获取pil对象的md5?imq.save('out.png')hash=hashlib.md5(open('out.png','rb').read()).hexdigest() 最佳答案 其实还有更简单的解决方案:hashlib.md5(img.tostring()).hexdigest() 关于python-来自pil对象的md5,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c