Search code examples
pythonscikit-image

How to convert .tif image to .jpg using skimage


I'm trying to convert a .tif image in python using the module skimage. It's not working properly.

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

Here is the error:

/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'

EDIT 1:

A method I found to do this was to open using skimage, convert it to 8bits and then save it as png. Anyway I can't save it as .jpg

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

Solution

  • I found a good tool called ImageMagick it can be installed in linux. To call it inside python code i just did this.

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