Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off skimage warnings

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
like image 386
LearnToGrow Avatar asked Sep 24 '18 19:09

LearnToGrow


2 Answers

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)
like image 187
jmb_louis Avatar answered Jan 03 '23 17:01

jmb_louis


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)
like image 26
just_a_student Avatar answered Jan 03 '23 17:01

just_a_student