PIL无法将模式F写入jpeg [英] PIL cannot write mode F to jpeg

查看:112
本文介绍了PIL无法将模式F写入jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在拍摄jpg图片,并使用numpy的fft2创建/保存新图片.但是,它将引发此错误

I am taking a jpg image and using numpy's fft2 to create/save a new image. However it throws this error

"IOError: cannot write mode F as JPEG" 

PIL中的CMYK和JPEG文件是否存在问题?

Is there an issue with CMYK and JPEG files in PIL???

p = Image.open('kibera.jpg')
bw_p = p.convert('L')
array_p = numpy.asarray(bw_p)
fft_p = abs(numpy.fft.rfft2(array_p))
new_p = Image.fromarray(fft_p)
new_p.save('kibera0.jpg')
new_p.histogram()

推荐答案

尝试将图像转换为RGB:

Try convert the image to RGB:

...
new_p = Image.fromarray(fft_p)
if new_p.mode != 'RGB':
    new_p = new_p.convert('RGB')
...

这篇关于PIL无法将模式F写入jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆