有没有一种方法可以将作为二进制字符串加载的图像转换为大小为 (im_height, im_width, 3) 的 numpy 数组?像这样的东西:
# read image as binary string
with open(img_path, "rb") as image_file:
image_string = image_file.read()
# convert image string to numpy
image_np = convert_binary_string_to_numpy(image_string)
Run Code Online (Sandbox Code Playgroud)
那个转换函数会是什么样子?我正在处理解密,因此我需要处理二进制字符串。谢谢!
我在virtualenv中使用Wagtail(Django变种CMS),在FastCGI + Apache +共享主机上.
通过内置的Wagtail Image Uploader上传图像时,某些图像可以正常工作和编译,而某些上传会导致500内部服务器错误.
尝试在导致错误但无法发现任何相似之处的图像类型中寻找模式.
我可以上传各种JPG,GIF,PNG,尺寸从88KB到236KB不等,最大尺寸为1000px x 950px

导致错误的文件也是各种JPG,GIF,PNG.我不能上传大于300KB的任何内容,尽管一些只有100KB或更少的文件也会导致500错误.通过django-admin上传会导致相同的问题.
当我通过sftp和cpanel上传时图像工作,所以那里没有问题.
Wagtail Pillow用于图像处理.
我不知道从哪里开始寻找这个.它是枕头还是Django错误?
我尝试了所有的程序安装的Django-CMS,之后,当我尝试运行演示页我提示以下错误.
(djvenv2)shan@shan:~/workspace/projects/djvenv$ pip freeze
Django==1.6.2
PIL==1.1.7
Pillow==2.4.0
South==0.8.4
argparse==1.2.1
dj-database-url==0.3.0
django-classy-tags==0.5.1
django-cms==3.0
django-mptt==0.6.0
django-sekizai==0.7
djangocms-admin-style==0.2.2
djangocms-installer==0.4.1
html5lib==0.999
six==1.6.1
wsgiref==0.1.2
(djvenv2)shan@shan:~/workspace/projects/djvenv$ djangocms -p . my_demo
Database configuration (in URL format) [default sqlite://localhost/project.db]:
django CMS version (choices: 2.4, 3.0, stable, develop) [default stable]:
Django version (choices: 1.4, 1.5, 1.6, stable) [default 1.5]:
Activate Django I18N / L10N setting (choices: yes, no) [default yes]:
Install and configure reversion support (choices: yes, no) [default yes]:
Languages to enable. Option can be provided multiple times, …Run Code Online (Sandbox Code Playgroud) 我不能安装枕头.
(env)noah:cupalensic2 broinjc$ which cc
/usr/bin/cc
(env)noah:cupalensic2 broinjc$ cc --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)
我跑了pip install mezzanine,当它满足枕头时它搞砸了......
cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -arch x86_64 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Versions/8.5/Headers -I/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/opt/X11/include/freetype2 -I/Users/broinjc/cupalensic2/env/build/pillow/libImaging -I/Users/broinjc/cupalensic2/env/include -I/usr/local/include -I/opt/X11/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.9-intel-2.7/_imaging.o
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will …Run Code Online (Sandbox Code Playgroud) 我收到一个错误,在两台不同的计算机上读取相同的lena.jpg文件会产生两个不同的校验和.
甚至更奇怪的是,当我运行md5sum lena.jpg时,我在两台机器上获得相同的md5总和,因此文件是相同的.
此外,当我加载png而不是jpeg时,数字似乎匹配.这让我相信Pillow在两台不同的机器上,或者至少是用于读取jpeg文件的库之间存在脱节.
有没有办法检查Pillow正在使用哪个版本的libjpeg(最好是在Python中)?
两台计算机都是Ubuntu,虽然一台是12.04,一台是14.04(我也在Mac上测试了它,并且得到了与14.04盒子相同的值)
我正在尝试创建一个python程序,它采用灰度,24*24像素图像文件(我还没有决定类型,所以欢迎建议)并将其转换为从0(白色)到255的像素值列表(黑色).
我计划使用这个数组来创建一个类似 MNIST的图像字节文件,可以通过Tensor-Flow手写识别算法识别.
通过迭代每个像素并将其值附加到PIL导入图像中的数组,我发现Pillow库在此任务中最有用.
img = Image.open('eggs.png').convert('1')
rawData = img.load()
data = []
for y in range(24):
for x in range(24):
data.append(rawData[x,y])
Run Code Online (Sandbox Code Playgroud)
然而,该解决方案存在两个问题(1)像素值不是作为整数存储,而是像素对象不能进一步在数学上被操纵并因此是无用的.(2)即使Pillow文件说明:
访问单个像素相当慢.如果您循环遍历图像中的所有像素,则使用> Pillow API的其他部分可能会更快.
我有一个完美运行的网站设计在django,但不小心我卸载自制软件,因此所有包postgres,枕头等,已经丢失,因此再次安装所有这些,但当我运行django runserver我得到以下错误
Unhandled exception in thread started by <function wrapper at 0x1071c11b8>
Traceback (most recent call last):
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
self.validate(display_num_errors=True)
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/shivakrishna/.virtualenvs/project/lib/python2.7/site-packages/django/utils/importlib.py", …Run Code Online (Sandbox Code Playgroud) 我想在表格中显示图像样本和一些相关的文本信息。
在jupyter笔记本中可以这样做吗?
我尝试混合pandas和PIL,但是没有用:
import pandas as pd
d = {
'band1': data.to_images(band_1[random_indices]),
'band2': data.to_images(band_2[random_indices]),
'is_iceberg': is_iceberg[random_indices]
}
pd.DataFrame(data=d)
Run Code Online (Sandbox Code Playgroud)
输出是
即它显示的__str__是图像,而不是图像本身。
如何克服?
在我拥有的项目中,我试图在一些文本上创建轮廓。总体思路是使黑色文本与原始白色文本之间略微透明。
由于某些原因,我得到了黑色文本,但透明了。这是MCVE:
image = Image.open("spongebob.gif").convert("RGBA")
draw = ImageDraw.Draw(image, "RGBA")
font = ImageFont.truetype("impact.ttf", 25)
draw.text((0, 0), "This text should be 5% alpha", fill=(0, 0, 0, 15), font=font)
image.save("foo.gif")
Run Code Online (Sandbox Code Playgroud)
结果:
我错过了什么?