我想通过从给定图像中删除前30行和最后30行来裁剪图像.我搜索过但没有得到确切的解决方案.有人有什么建议吗?
我正在使用PIL.如何将EXIF数据转换为字典?
我有一个简单的问题,但无法找到一个好的解决方案.
我想拍摄一个代表灰度图像的numpy 2D数组,并在应用一些matplotlib色彩图时将其转换为RGB PIL图像.
我可以使用以下pyplot.figure.figimage命令获得合理的PNG输出:
dpi = 100.0
w, h = myarray.shape[1]/dpi, myarray.shape[0]/dpi
fig = plt.figure(figsize=(w,h), dpi=dpi)
fig.figimage(sub, cmap=cm.gist_earth)
plt.savefig('out.png')
Run Code Online (Sandbox Code Playgroud)
虽然我可以调整它以获得我想要的东西(可能使用StringIO来获取PIL图像),我想知道是否有更简单的方法来做到这一点,因为它似乎是一个非常自然的图像可视化问题.让我们说,像这样:
colored_PIL_image = magic_function(array, cmap)
Run Code Online (Sandbox Code Playgroud)
谢谢阅读!
python numpy matplotlib color-mapping python-imaging-library
我刚刚使用Python图像库(PIL)完成了一些图像处理,使用我之前发现的一个帖子来执行图像的傅里叶变换,我无法使用保存功能.整个代码工作正常,但它不会保存生成的图像:
from PIL import Image
import numpy as np
i = Image.open("C:/Users/User/Desktop/mesh.bmp")
i = i.convert("L")
a = np.asarray(i)
b = np.abs(np.fft.rfft2(a))
j = Image.fromarray(b)
j.save("C:/Users/User/Desktop/mesh_trans",".bmp")
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
save_handler = SAVE[string.upper(format)] # unknown format
KeyError: '.BMP'
Run Code Online (Sandbox Code Playgroud)
如何使用Pythons PIL保存图像?
我试图在Python中水平组合一些JPEG图像.
我有3个图像 - 每个是148 x 95 - 见附件.我只是制作了3张相同的图像 - 这就是为什么它们是相同的.



我正在尝试使用以下代码水平加入它们:
import sys
from PIL import Image
list_im = ['Test1.jpg','Test2.jpg','Test3.jpg']
new_im = Image.new('RGB', (444,95)) #creates a new empty image, RGB mode, and size 444 by 95
for elem in list_im:
for i in xrange(0,444,95):
im=Image.open(elem)
new_im.paste(im, (i,0))
new_im.save('test.jpg')
Run Code Online (Sandbox Code Playgroud)
但是,这会产生附加的输出test.jpg.

有没有办法水平连接这些图像,使test.jpg中的子图像没有显示额外的部分图像?
我正在寻找一种水平连接n个图像的方法.我想一般使用这个代码所以我更愿意:
我试图用scipy读取图像.但是它不接受这scipy.misc.imread部分.可能是什么原因造成的?
>>> import scipy
>>> scipy.misc
<module 'scipy.misc' from 'C:\Python27\lib\site-packages\scipy\misc\__init__.pyc'>
>>> scipy.misc.imread('test.tif')
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
scipy.misc.imread('test.tif')
AttributeError: 'module' object has no attribute 'imread'
Run Code Online (Sandbox Code Playgroud) python installation dependencies scipy python-imaging-library
我使用PIL生成了一个图像.如何将其保存到内存中的字符串?该Image.save()方法需要一个文件.
我想在字典中存储几个这样的图像.
我正在使用PIL将使用Django上传的透明PNG图像转换为JPG文件.输出看起来很糟糕.

Image.open(object.logo.path).save('/tmp/output.jpg', 'JPEG')
Run Code Online (Sandbox Code Playgroud)
要么
Image.open(object.logo.path).convert('RGB').save('/tmp/output.png')
Run Code Online (Sandbox Code Playgroud)
两种方式,生成的图像如下所示:

有没有办法来解决这个问题?我想要有透明背景的白色背景.
感谢很棒的答案,我想出了以下函数集合:
import Image
import numpy as np
def alpha_to_color(image, color=(255, 255, 255)):
"""Set all fully transparent pixels of an RGBA image to the specified color.
This is a very simple solution that might leave over some ugly edges, due
to semi-transparent areas. You should use alpha_composite_with color instead.
Source: http://stackoverflow.com/a/9166671/284318
Keyword Arguments:
image -- PIL RGBA Image object
color -- Tuple r, g, b (default 255, 255, 255)
""" …Run Code Online (Sandbox Code Playgroud) 是否可以使用PIL获得像素的RGB颜色?我正在使用此代码:
im = Image.open("image.gif")
pix = im.load()
print(pix[1,1])
Run Code Online (Sandbox Code Playgroud)
但是,它仅输出一个数字(例如0或1)而不是三个数字(例如,60,60,60对于R,G,B).我想我不了解这个功能.我喜欢一些解释.
非常感谢.
我有一个加载图像的应用程序,当用户单击它时,会显示此图像的文本区域(使用jquery),用户可以在图像上写入一些文本.应该在Image上添加哪个.
在做了一些研究后,我认为PIL(Python Imaging Library)可以帮助我做到这一点.所以我尝试了几个例子来看它是如何工作的,我设法在图像上写文字.但我认为当我Python Shell在网络环境中使用它时会有一些区别.我的意思是textarea上的文字在px中非常大.当使用PIL作为textarea上的PIL时,如何获得相同大小的文本?
文字是Multiline.我怎样才能在图像中使用多线PIL?
有没有比使用PIL更好的方法?我不完全确定,如果这是最好的实施.
HTML:
<img src="images/test.jpg"/>
Run Code Online (Sandbox Code Playgroud)
正在编辑的图像
var count = 0;
$('textarea').autogrow();
$('img').click(function(){
count = count + 1;
if (count > 1){
$(this).after('<textarea />');
$('textarea').focus();
}
});
Run Code Online (Sandbox Code Playgroud)
添加textarea的jquery.文本区域也是位置:绝对大小和固定大小.
我应该把它放在一个表格中,这样我就可以在图像上得到textarea的坐标吗?我想在用户点击时在图像上写文字并将其保存在图像上.
python ×9
image ×3
crop ×1
dependencies ×1
django ×1
exif ×1
installation ×1
jpeg ×1
matplotlib ×1
numpy ×1
paste ×1
pixel ×1
png ×1
python-2.7 ×1
rgb ×1
rgba ×1
save ×1
scipy ×1