comparison auto_local_threshold.py @ 3:be2d3ce89c0f draft default tip

"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_local_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
author imgteam
date Sat, 19 Feb 2022 15:17:19 +0000
parents 497dcd834bb3
children
comparison
equal deleted inserted replaced
2:497dcd834bb3 3:be2d3ce89c0f
1 import argparse 1 import argparse
2 import sys 2 import sys
3
4 import numpy as np
5 import skimage.filters
3 import skimage.io 6 import skimage.io
4 import skimage.filters
5 import skimage.util 7 import skimage.util
6 import numpy as np
7 8
8 threshOptions = { 9 threshOptions = {
9 'gaussian': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='gaussian'), 10 'gaussian': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='gaussian'),
10 'mean': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='mean'), 11 'mean': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='mean'),
11 'median': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='median') 12 'median': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='median')
22 23
23 img_in = skimage.io.imread(args.input_file.name) 24 img_in = skimage.io.imread(args.input_file.name)
24 img_in = np.reshape(img_in, [img_in.shape[0], img_in.shape[1]]) 25 img_in = np.reshape(img_in, [img_in.shape[0], img_in.shape[1]])
25 thresh = threshOptions[args.thresh_type](img_in, args.block_size) 26 thresh = threshOptions[args.thresh_type](img_in, args.block_size)
26 27
27 if args.dark_background: 28 if args.dark_background:
28 res = img_in > thresh 29 res = img_in > thresh
29 else: 30 else:
30 res = img_in <= thresh 31 res = img_in <= thresh
31 32
32 res = skimage.util.img_as_uint(res) 33 res = skimage.util.img_as_uint(res)