diff --git a/tools/2d_auto_threshold/auto_threshold.py b/tools/2d_auto_threshold/auto_threshold.py
index 428547e7..4eec3297 100644
--- a/tools/2d_auto_threshold/auto_threshold.py
+++ b/tools/2d_auto_threshold/auto_threshold.py
@@ -7,12 +7,14 @@
import argparse
+import giatools
import numpy as np
import skimage.filters
import skimage.io
import skimage.util
import tifffile
+
th_methods = {
'manual': lambda thres, **kwargs: thres,
@@ -28,7 +30,7 @@
def do_thresholding(in_fn, out_fn, th_method, block_size, offset, threshold, invert_output=False):
- img = skimage.io.imread(in_fn)
+ img = giatools.imread(in_fn)
img = np.squeeze(img)
assert img.ndim == 2
diff --git a/tools/2d_auto_threshold/auto_threshold.xml b/tools/2d_auto_threshold/auto_threshold.xml
index 20042c52..9206b3a7 100644
--- a/tools/2d_auto_threshold/auto_threshold.xml
+++ b/tools/2d_auto_threshold/auto_threshold.xml
@@ -4,7 +4,7 @@
creators.xml
tests.xml
0.18.1
- 2
+ 3
diff --git a/tools/2d_auto_threshold/giatools.py b/tools/2d_auto_threshold/giatools.py
new file mode 100644
index 00000000..db6a543c
--- /dev/null
+++ b/tools/2d_auto_threshold/giatools.py
@@ -0,0 +1,30 @@
+"""
+Copyright 2017-2024 Leonid Kostrykin, Biomedical Computer Vision Group, Heidelberg University.
+
+Distributed under the MIT license.
+See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
+"""
+
+import contextlib
+
+import skimage.io
+
+
+def imread(*args, **kwargs):
+ """
+ Wrapper around ``skimage.io.imread`` which mutes non-fatal errors.
+
+ When using ``skimage.io.imread`` to read an image file, sometimes errors can be reported although the image file will be read successfully.
+ In those cases, Galaxy might detect the errors and assume that the tool has failed: https://docs.galaxyproject.org/en/latest/dev/schema.html#error-detection
+ To prevent this, this wrapper around ``skimage.io.imread`` will mute non-fatal all errors.
+ """
+ try:
+
+ # Mute stderr unless an error occurs
+ with contextlib.redirect_stderr(None):
+ return skimage.io.imread(*args, **kwargs)
+
+ except: # noqa: E722
+
+ # Raise the error outside of the contextlib redirection
+ raise