标签: python-imaging-library

将图像保存为字节并上传到boto3返回内容-MD5不匹配

我正在尝试从s3中提取图像,量化它/操纵它,然后将其存储回s3而不将任何内容保存到磁盘(完全在内存中).我曾经做过一次,但是在返回代码并再次尝试它之后就没用了.代码如下:

import boto3
import io
from PIL import Image

client = boto3.client('s3',aws_access_key_id='',
        aws_secret_access_key='')
cur_image = client.get_object(Bucket='mybucket',Key='2016-03-19 19.15.40.jpg')['Body'].read()

loaded_image = Image.open(io.BytesIO(cur_image))
quantized_image = loaded_image.quantize(colors=50)
saved_quantized_image = io.BytesIO()
quantized_image.save(saved_quantized_image,'PNG')
client.put_object(ACL='public-read',Body=saved_quantized_image,Key='testimage.png',Bucket='mybucket')
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

botocore.exceptions.ClientError: An error occurred (BadDigest) when calling the PutObject operation: The Content-MD5 you specified did not match what we received.
Run Code Online (Sandbox Code Playgroud)

如果我只是拉一个图像然后把它放回去而不操纵它,它工作正常.我不太确定这里发生了什么.

amazon-s3 python-imaging-library python-3.x pillow boto3

15
推荐指数
2
解决办法
7839
查看次数

如何将 Matplotlib 图转换为 PIL Image 对象(不保存图像)

正如标题所述,我正在尝试将 a 转换fig为 a PIL.Image。我目前可以通过首先将fig文件保存到磁盘然后使用打开该文件来做到这一点,Image.open()但该过程花费的时间比预期的要长,我希望通过跳过本地保存步骤会快一点。

这是我到目前为止所拥有的:

# build fig
figsize, dpi = self._calc_fig_size_res(img_height)
fig = plt.Figure(figsize=figsize)
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.imshow(torch.from_numpy(S).flip(0), cmap = cmap)
fig.subplots_adjust(left = 0, right = 1, bottom = 0, top = 1)
ax.axis('tight'); ax.axis('off')

# export
fig.savefig(export_path, dpi = dpi)

# open image as PIL object
img = Image.open(export_path)
Run Code Online (Sandbox Code Playgroud)

我在构建无花果之后尝试这样做(它会在导出阶段之前):

pil_img = Image.frombytes('RGB', canvas.get_width_height(), canvas.tostring_rgb())
Run Code Online (Sandbox Code Playgroud)

但它没有显示整个图像。它看起来像是左上角的一部分,但它可能只是数据的一种奇怪表示——我正在使用频谱图,因此图像相当抽象。

python numpy matplotlib python-imaging-library python-3.x

15
推荐指数
2
解决办法
1万
查看次数

如何使用PIL减少调色板

我不确定如何减少PIL图像的调色板.我想将图像的调色板缩小为该图像中的5种突出颜色.我的总体目标是做一些基本的颜色采样.

python image colors palette python-imaging-library

14
推荐指数
2
解决办法
2万
查看次数

使用PIL和NumPy将图像转换为Lab数组,修改值然后转换回来

我正在尝试使用NumPy将PIL图像转换为数组.然后,我想将该数组转换为Lab值,修改值,然后将数组转换回图像并保存图像.我有以下代码:

import Image, color, numpy

# Open the image file
src = Image.open("face-him.jpg")

# Attempt to ensure image is RGB
src = src.convert(mode="RGB")

# Create array of image using numpy
srcArray = numpy.asarray(src)

# Convert array from RGB into Lab
srcArray = color.rgb2lab(srcArray)

# Modify array here

# Convert array back into Lab
end = color.lab2rgb(srcArray)

# Create image from array
final = Image.fromarray(end, "RGB")

# Save
final.save("out.jpg")
Run Code Online (Sandbox Code Playgroud)

此代码取决于PIL,NumPy和颜色.颜色可以在SciPy主干中找到.我下载了color.py文件以及某些colordata .txt文件.我修改了color.py,以便它可以从SciPy的源独立运行,这一切似乎来做工精细-数组中值改变,当我运行转换.

我的问题是,当我运行上面的代码只是将图像转换为Lab,然后回到RGB并保存它我得到以下图像:

替代文字

出了什么问题?这是我使用color.py函数的事实吗? …

python numpy colors color-space python-imaging-library

14
推荐指数
2
解决办法
2万
查看次数

使用Python Imaging Library(PIL),如何使用alpha通道组合图像而不是另一个图像?

我有两个图像,都有alpha通道.我想将一个图像放在另一个图像上,从而生成带有alpha通道的新图像,就像它们在图层中呈现一样.我想用Python Imaging Library做到这一点,但是其他系统中的建议会很棒,即使原始数学也是一个好处; 我可以使用NumPy.

python image-processing python-imaging-library

14
推荐指数
3
解决办法
2万
查看次数

在Tkinter中调整PIL中的图片大小

我目前正在使用PIL在Tkinter中显示图像.我想暂时调整这些图像的大小,以便更容易地查看它们.我怎么能这样做?

片段:

self.pw.pic = ImageTk.PhotoImage(Image.open(self.pic_file))
self.pw.pic_label = TK.Label(self.pw , image=self.pw.pic,borderwidth=0)         
self.pw.pic_label.grid(column=0,row=0)
Run Code Online (Sandbox Code Playgroud)

python tkinter windows-7 python-imaging-library

14
推荐指数
2
解决办法
6万
查看次数

我应该使用哪些处理步骤来清理线条图的照片?

我通常使用100%对比度和一些亮度调整以调整截止点的方法通常可以很好地清理小子电路的照片或方程式以便在E&R.SE上发布,但有时它并不是那么好,就像这张图片一样:

替代文字

除了对比(或代替)之外还有哪些其他方法可以用来给我一个更一致的输出?

我期待一个相当普遍的答案,但我可能会使用ImageMagick和/或PIL(Python)在脚本中实现它(我可以将文件转储到其中),所以如果你有任何特定的东西,那将是受欢迎的.

理想情况下,更好的源图像会很好,但我偶尔会在其他民间图像上使用它来添加一些润色.

imagemagick image-processing python-imaging-library

14
推荐指数
2
解决办法
4905
查看次数

PIL的色彩空间转换YCbCr - > RGB

PIL v1.1.7使用的算法给出了"褪色"的结果.使用ffmpeg它转换相同的源数据时看起来是正确的.使用mplayer给出相同的结果ffmpeg(也许他们使用下面的相同库).这让我相信PIL可能会填充色彩空间转换.转换似乎来自libImaging/ConvertYCbCr.c:

/*  JPEG/JFIF YCbCr conversions

    Y  = R *  0.29900 + G *  0.58700 + B *  0.11400
    Cb = R * -0.16874 + G * -0.33126 + B *  0.50000 + 128
    Cr = R *  0.50000 + G * -0.41869 + B * -0.08131 + 128

    R  = Y +                       + (Cr - 128) *  1.40200
    G  = Y + (Cb - 128) * -0.34414 + (Cr - 128) …
Run Code Online (Sandbox Code Playgroud)

c python rgb yuv python-imaging-library

14
推荐指数
1
解决办法
2万
查看次数

是否有Python PIL的抗锯齿方法?

对于PIL中的线条和椭圆,图像很粗糙.

我只在resize和缩略图中找到了抗锯齿.

绘制直线或椭圆时有没有办法做抗锯齿?

python antialiasing python-imaging-library

14
推荐指数
2
解决办法
1万
查看次数

Python Pillow不在OSX下安装

我正在尝试安装Python Pillow库,我收到以下错误:

ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting
Run Code Online (Sandbox Code Playgroud)

我跟着线程尝试修复它:在Linux中安装Pillow(Python模块)时失败

问题是它似乎仍然无法找到我通过自制软件安装的zlib.

我检查了它是否已安装:

> brew search zlib
homebrew/dupes/zlib ?                                        lzlib
Run Code Online (Sandbox Code Playgroud)

我注意到它与标准brew安装位置不同("homebrew/dupes/zlib").我尝试进行卸载/重新安装,然后将其放回到同一个地方("homebrew/dupes/zlib").问题似乎是安装程序/编译器在该位置找不到它.

我的问题是,有没有办法为lib路径设置别名,将安装程序指向此lib位置,或者将其从home-brew中彻底清除,以便像zlib一样重新安装它?最好的路线是什么?

谢谢,RB

python macos homebrew python-imaging-library pillow

14
推荐指数
3
解决办法
5366
查看次数