我需要用Python编写一个图像处理程序。 有人知道如何将图像文件的类型从JPEG转换为TIFF吗?
我需要用Python编写一个图像处理程序。 有人知道如何将图像文件的类型从JPEG转换为TIFF吗?
可以查看Python Image Library (PIL)。参考教程,PIL 很容易使用。
要进行转换,您需要打开图像,然后使用新扩展名保存它(PIL 会根据扩展名确定要使用哪种格式进行保存)。
import Image
im = Image.open('test.jpg')
im.save('test.tiff') # or 'test.tif'
请注意,官方发行版目前不支持 Python 3.x (还没有?),但至少在 Windows 下,有一个可用的非官方版本与 v 3.x 兼容。
使用Python图像处理库(PIL)。
from PIL import Image
img = Image.open('image.jpeg')
img.save('image.tiff')
img.convert()
以避免文件转换中出现任何错误。 - pankaj我通常使用OpenCV(cv2)进行转换,例如:
import os
import cv2
path = r"D:\Folder"
i=0
for x in os.listdir(path):
image = cv2.imread(r"{}\{}".format(path,x))
cv2.imwrite(r'{}\{}.png'.format(path,i),image)
i+=1
(将“png”替换为您想要的任何扩展名,例如“.tiff”)