如何使用 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打开,将其转换为8位,然后另存为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)
您没有在保存命令中提供图像插件。请参阅 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 ")
我正在尝试使用模块 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打开,将其转换为8位,然后另存为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)
您没有在保存命令中提供图像插件。请参阅 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 ")