annotate auto_threshold.py @ 4:7d80eb2411fb draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
author imgteam
date Sat, 07 Jun 2025 18:38:16 +0000
parents 5224cc463a97
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
1 """
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
2 Copyright 2017-2024 Biomedical Computer Vision Group, Heidelberg University.
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
4 Distributed under the MIT license.
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
6 """
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
7
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
8 import argparse
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
9
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
10 import numpy as np
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
11 import skimage.filters
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
12 import skimage.util
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
13 from giatools.image import Image
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
14
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
15
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
16 class DefaultThresholdingMethod:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
17
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
18 def __init__(self, thres, accept: list[str] | None = None, **kwargs):
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
19 self.thres = thres
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
20 self.accept = accept if accept else []
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
21 self.kwargs = kwargs
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
22
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
23 def __call__(self, image, *args, offset=0, **kwargs):
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
24 accepted_kwargs = self.kwargs.copy()
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
25 for key, val in kwargs.items():
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
26 if key in self.accept:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
27 accepted_kwargs[key] = val
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
28 thres = self.thres(image, *args, **accepted_kwargs)
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
29 return image > thres + offset
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
30
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
31
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
32 class ManualThresholding:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
33
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
34 def __call__(self, image, thres1: float, thres2: float | None, **kwargs):
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
35 if thres2 is None:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
36 return image > thres1
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
37 else:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
38 thres1, thres2 = sorted((thres1, thres2))
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
39 return skimage.filters.apply_hysteresis_threshold(image, thres1, thres2)
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
40
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
41
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
42 th_methods = {
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
43 'manual': ManualThresholding(),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
44
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
45 'otsu': DefaultThresholdingMethod(skimage.filters.threshold_otsu),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
46 'li': DefaultThresholdingMethod(skimage.filters.threshold_li),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
47 'yen': DefaultThresholdingMethod(skimage.filters.threshold_yen),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
48 'isodata': DefaultThresholdingMethod(skimage.filters.threshold_isodata),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
49
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
50 'loc_gaussian': DefaultThresholdingMethod(skimage.filters.threshold_local, accept=['block_size'], method='gaussian'),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
51 'loc_median': DefaultThresholdingMethod(skimage.filters.threshold_local, accept=['block_size'], method='median'),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
52 'loc_mean': DefaultThresholdingMethod(skimage.filters.threshold_local, accept=['block_size'], method='mean'),
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
53 }
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
54
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
55
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
56 def do_thresholding(
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
57 input_filepath: str,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
58 output_filepath: str,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
59 th_method: str,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
60 block_size: int,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
61 offset: float,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
62 threshold1: float,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
63 threshold2: float | None,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
64 invert_output: bool,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
65 ):
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
66 assert th_method in th_methods, f'Unknown method "{th_method}"'
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
67
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
68 # Load image
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
69 img_in = Image.read(input_filepath)
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
70
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
71 # Perform thresholding
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
72 result = th_methods[th_method](
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
73 image=img_in.data,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
74 block_size=block_size,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
75 offset=offset,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
76 thres1=threshold1,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
77 thres2=threshold2,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
78 )
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
79 if invert_output:
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
80 result = np.logical_not(result)
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
81
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
82 # Convert to canonical representation for binary images
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
83 result = (result * 255).astype(np.uint8)
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
84
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
85 # Write result
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
86 Image(
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
87 data=skimage.util.img_as_ubyte(result),
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
88 axes=img_in.axes,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
89 ).normalize_axes_like(
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
90 img_in.original_axes,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
91 ).write(
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
92 output_filepath,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
93 )
3
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
94
5224cc463a97 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit b1b3c63ab021aa77875c3b04127f6836024812f9"
imgteam
parents: 2
diff changeset
95
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
96 if __name__ == "__main__":
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
97 parser = argparse.ArgumentParser(description='Automatic image thresholding')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
98 parser.add_argument('input', type=str, help='Path to the input image')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
99 parser.add_argument('output', type=str, help='Path to the output image (uint8)')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
100 parser.add_argument('th_method', choices=th_methods.keys(), help='Thresholding method')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
101 parser.add_argument('block_size', type=int, help='Odd size of pixel neighborhood for calculating the threshold')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
102 parser.add_argument('offset', type=float, help='Offset of automatically determined threshold value')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
103 parser.add_argument('threshold1', type=float, help='Manual threshold value')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
104 parser.add_argument('--threshold2', type=float, help='Second manual threshold value (for hysteresis thresholding)')
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
105 parser.add_argument('--invert_output', default=False, action='store_true', help='Values below/above the threshold are labeled with 0/255 by default, and with 255/0 if this argument is used')
0
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
106 args = parser.parse_args()
6fc65082d1e6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_auto_threshold/ commit bd6ef77515c4c15901b67f73738afbdd5faadae5
imgteam
parents:
diff changeset
107
4
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
108 do_thresholding(
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
109 args.input,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
110 args.output,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
111 args.th_method,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
112 args.block_size,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
113 args.offset,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
114 args.threshold1,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
115 args.threshold2,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
116 args.invert_output,
7d80eb2411fb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit 01343602708de3cc7fa4986af9000adc36dd0651
imgteam
parents: 3
diff changeset
117 )