繁体   English   中英

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

[英]How to convert .tif image to .jpg using skimage

我正在尝试使用模块skimage在python中转换.tif图像。 它无法正常工作。

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

这是错误:

/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py in get_writer(uri, format, mode, **kwargs)
 if format is None:
   raise ValueError(
     "Could not find a format to write the specified file " "in mode %r" % mode)

ValueError: Could not find a format to write the specified file in mode 'i'

编辑1:

我发现执行此操作的一种方法是使用skimage打开,将其转换为8bit,然后将其另存为png。 无论如何,我无法将其另存为.jpg

img = io.imread('/content/IMG_0007_4.tif',as_gray=True)
img8 = (img/256).astype('uint8')
matplotlib.image.imsave('/content/name.png', img8)

您尚未在save命令中提供图像插件。 请参阅https://scikit-image.org/docs/dev/api/skimage.io.html#skimage.io.imsave ,其中显示:

保存JPEG时,可以使用quality关键字参数控制压缩率,该参数是一个整数,值为[1,100],其中1是最差质量和最小文件大小,而100是最佳质量和最大文件大小(默认为75) )。 仅在使用PIL和imageio插件时可用。

我发现了一个名为ImageMagick的好工具,可以在linux中安装它。 要在python代码中调用它,我只是这样做了。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM