comparison auto_local_threshold.py @ 1:c90b91f4a07b draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_local_threshold/ commit 8a2a5763d1ac38b3c7974bd7c2da4d5c1101a0a9
author imgteam
date Tue, 23 Jul 2019 05:09:04 -0400
parents a20c14eb5f98
children 497dcd834bb3
comparison
equal deleted inserted replaced
0:a20c14eb5f98 1:c90b91f4a07b
1 import argparse 1 import argparse
2 import sys 2 import sys
3 import skimage.io 3 import skimage.io
4 import skimage.filters 4 import skimage.filters
5 import skimage.util 5 import skimage.util
6 import numpy as np
6 7
7 threshOptions = { 8 threshOptions = {
8 'gaussian': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='gaussian'), 9 'gaussian': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='gaussian'),
9 'mean': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='mean'), 10 'mean': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='mean'),
10 'median': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='median') 11 'median': lambda img_raw, bz: skimage.filters.threshold_local(img_raw, bz, method='median')
18 parser.add_argument('thresh_type', choices=threshOptions.keys(), help='thresholding method') 19 parser.add_argument('thresh_type', choices=threshOptions.keys(), help='thresholding method')
19 parser.add_argument('dark_background', default=True, type=bool, help='True if background is dark') 20 parser.add_argument('dark_background', default=True, type=bool, help='True if background is dark')
20 args = parser.parse_args() 21 args = parser.parse_args()
21 22
22 img_in = skimage.io.imread(args.input_file.name) 23 img_in = skimage.io.imread(args.input_file.name)
24 img_in = np.reshape(img_in, [img_in.shape[0], img_in.shape[1]])
23 thresh = threshOptions[args.thresh_type](img_in, args.block_size) 25 thresh = threshOptions[args.thresh_type](img_in, args.block_size)
24 26
25 if args.dark_background: 27 if args.dark_background:
26 res = img_in > thresh 28 res = img_in > thresh
27 else: 29 else: