Skip to main content
 首页 » 编程设计

python之如何在 Python 中保存 HSV 转换后的图像

2025年01月19日9kenshinobiy

我正在读取 RGB 图像并使用 PIL 将其转换为 HSV 模式。现在我正在尝试保存此 HSV 图像,但出现错误。

filename = r'\trial_images\cat.jpg' 
img = Image.open(filename) 
img = img.convert('HSV') 
destination = r'\demo\temp.jpg' 
img.save(destination) 

我收到以下错误:

OSError: cannot write mode HSV as JPEG 

如何保存转换后的图像?请帮忙

请您参考如下方法:

简单的...保存为 numpy 数组。这工作正常,但文件可能非常大(对我来说它比 jpeg 图像大 7 倍)。你可以 numpy 的 savez_compressed 功能将其切成两半,大约是原始图像大小的 3-4 倍。不是很好,但是当你进行图像处理时,你可能没问题。