Python TypeError:不支持*:';JPEG图像文件';和';浮动';
我试着运行这段代码它显示错误-Python TypeError:不支持*:';JPEG图像文件';和';浮动';,python,image-processing,Python,Image Processing,我试着运行这段代码它显示错误- Traceback (most recent call last): File "C:\Python36-32\test1.py", line 13, in <module> img_tinted = img * [1, 0.95, 0.9] TypeError: unsupported operand type(s) for *: 'JpegImageFile' and 'float' 好的,但是你打算代码做什么?消除错误很容易——只需
Traceback (most recent call last):
File "C:\Python36-32\test1.py", line 13, in <module>
img_tinted = img * [1, 0.95, 0.9]
TypeError: unsupported operand type(s) for *: 'JpegImageFile' and 'float'
好的,但是你打算代码做什么?消除错误很容易——只需删除有问题的代码行。修复错误更加困难,如果您不告诉我们有关代码用途的任何信息,则无法完成。请尝试
img[:,:,1]*=0.95
和img[:,:,2]*=0.9
。如何img=(img*np.array([1,0.95,0.9])。astype('uint8')
?您是否阅读过此imread已弃用!在SciPy 1.0.0中不推荐使用imread,并将在1.2.0中删除。改用imageio.imread。
from?img\u tinted=img*[1,0.95,0.9]
对我有用。。在您阅读/创建了type(img)
之后,您会得到什么?
from scipy.misc import imread, imsave, imresize
# Read an JPEG image into a numpy array
img = imread('assets/cat.jpg')
print(img.dtype, img.shape) # Prints "uint8 (400, 248, 3)"
img_tinted = img * [1, 0.95, 0.9]
# Resize the tinted image to be 300 by 300 pixels.
img_tinted = imresize(img_tinted, (300, 300))
# Write the tinted image back to disk
imsave('assets/cat_tinted.jpg', img_tinted)