13

I want to turn off skimage UserWarning: I used this code but they are still enabled.

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    skimage.io.imsave
LearnToGrow
  • 1,656
  • 6
  • 30
  • 53

2 Answers2

25

I found in the documentation that there is a dedicated option "check_contrast" when imsave is called: https://scikit-image.org/docs/dev/api/skimage.io.html?#imsave

If you want to disable imsave warnings indicating a low contrast image you should set this option to False: check_contrast=False

from skimage import io

io.imsave(filename, image, check_contrast=False)
jmb_louis
  • 1,055
  • 2
  • 13
  • 15
5

Apparently skimage uses imageio as his first plugin option to save an image.

Try to:

import imageio.core.util

def ignore_warnings(*args, **kwargs):
    pass

imageio.core.util._precision_warn = ignore_warnings

After that, you can save your image without the warnings:

imsave(filename, image)