如何使用skimag将.tif图像转换为.jpg

2024-04-20 13:01:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用skimage模块转换python中的.tif图像。 它不能正常工作。在

from skimage import io
img = io.imread('/content/IMG_0007_4.tif')
io.imsave('/content/img.jpg', img)

错误如下:

^{pr2}$

编辑1:

我发现了一种方法,用skimage打开,将其转换为8位,然后将其保存为png。 无论如何,我不能将它保存为.jpg

^{3}$

Tags: 模块fromio图像importimg错误content
2条回答

您没有在save命令中提供图像插件。请参见https://scikit-image.org/docs/dev/api/skimage.io.html#skimage.io.imsave,其中写道:

When saving a JPEG, the compression ratio may be controlled using the quality keyword argument which is an integer with values in [1, 100] where 1 is worst quality and smallest file size, and 100 is best quality and largest file size (default 75). This is only available when using the PIL and imageio plugins.

我发现了一个很好的工具,叫做ImageMagick,它可以安装在linux上。 为了在python代码中调用它,我就这样做了。在

os.system("convert image.png -colorspace RGB image.jpg ")

相关问题 更多 >