comparison auto_threshold.py @ 8:699a5e9146b3 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
author imgteam
date Wed, 24 Apr 2024 08:11:33 +0000
parents e5c8e7e72373
children
comparison
equal deleted inserted replaced
7:e5c8e7e72373 8:699a5e9146b3
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
6 """ 6 """
7 7
8 import argparse 8 import argparse
9 9
10 import giatools.io
10 import numpy as np 11 import numpy as np
11 import skimage.filters 12 import skimage.filters
12 import skimage.io
13 import skimage.util 13 import skimage.util
14 import tifffile 14 import tifffile
15
15 16
16 th_methods = { 17 th_methods = {
17 'manual': lambda thres, **kwargs: thres, 18 'manual': lambda thres, **kwargs: thres,
18 19
19 'otsu': lambda img_raw, **kwargs: skimage.filters.threshold_otsu(img_raw), 20 'otsu': lambda img_raw, **kwargs: skimage.filters.threshold_otsu(img_raw),
26 'loc_mean': lambda img_raw, bz, **kwargs: skimage.filters.threshold_local(img_raw, bz, method='mean') 27 'loc_mean': lambda img_raw, bz, **kwargs: skimage.filters.threshold_local(img_raw, bz, method='mean')
27 } 28 }
28 29
29 30
30 def do_thresholding(in_fn, out_fn, th_method, block_size, offset, threshold, invert_output=False): 31 def do_thresholding(in_fn, out_fn, th_method, block_size, offset, threshold, invert_output=False):
31 img = skimage.io.imread(in_fn) 32 img = giatools.io.imread(in_fn)
32 img = np.squeeze(img) 33 img = np.squeeze(img)
33 assert img.ndim == 2 34 assert img.ndim == 2
34 35
35 th = offset + th_methods[th_method](img_raw=img, bz=block_size, thres=threshold) 36 th = offset + th_methods[th_method](img_raw=img, bz=block_size, thres=threshold)
36 res = img > th 37 res = img > th