comparison measure_image_quality.xml @ 0:26945c55ddff draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 6d73056a625002d0275b5a9a90a9fae329ce47f1"
author bgruening
date Thu, 26 Mar 2020 16:47:42 -0400
parents
children 4dcd464c22ff
comparison
equal deleted inserted replaced
-1:000000000000 0:26945c55ddff
1 <tool id="cp_measure_image_quality" name="MeasureImageQuality" version="@CP_VERSION@">
2 <description>measures features that indicate image quality</description>
3
4 <macros>
5 <import>macros.xml</import>
6 <xml name="macro_calc_threshold">
7 <conditional name="con_use_all_methods">
8 <param name="use_all_methods" type="select" display="radio" label="Use all thresholding methods?">
9 <option value="Yes">Yes</option>
10 <option value="No">No</option>
11 </param>
12 <when value="Yes" />
13 <when value="No">
14 <repeat name="rpt_threshold_method" title="Add another threshold method">
15 <conditional name="con_threshold_methods">
16 <param name="select_threshold_method" type="select" label="Select a thresholding method">
17 <option value="Otsu">Otsu</option>
18 <option value="MoG">MoG</option>
19 <option value="Background">Background</option>
20 <option value="RobustBackground">RobustBackground</option>
21 <option value="RidlerCalvard">RidlerCalvard</option>
22 <option value="Kapur">Kapur</option>
23 <option value="MCT">MCT</option>
24 </param>
25 <when value="Otsu">
26 <expand macro="otsu_method" />
27 </when>
28 <when value="MoG">
29 <expand macro="mog_method" />
30 </when>
31 <when value="Background" />
32 <when value="RobustBackground" />
33 <when value="RidlerCalvard" />
34 <when value="Kapur" />
35 <when value="MCT" />
36 </conditional>
37 </repeat>
38 </when>
39 </conditional>
40 </xml>
41
42 <xml name="otsu_method">
43 <param name="otsu_weighted_entropy" label="Minimize the weighted variance or the entropy?" type="select">
44 <option value="Weighted variance">Weighted variance</option>
45 <option value="Entropy">Entropy</option>
46 </param>
47 <conditional name="con_threshold_classes">
48 <param name="threshold_classes" label="Two-class or three-class thresholding?" type="select">
49 <option value="Two classes">Two classes</option>
50 <option value="Three classes">Three classes</option>
51 </param>
52 <when value="Three classes">
53 <param name="pixel_foreground_or_background" label="Assign pixels in the middle intensity class to the foreground or the background?" type="select">
54 <option value="Foreground">Foreground</option>
55 <option value="Background">Background</option>
56 </param>
57 </when>
58 <when value="Two classes" />
59 </conditional>
60 </xml>
61
62 <xml name="mog_method">
63 <param name="mog_fraction_cover" label="Typical fraction of the image covered by objects" type="float" value="0.1" min="0.0" max="1.0"/>
64 </xml>
65 </macros>
66
67 <expand macro="py_requirements"/>
68 <expand macro="cmd_modules" />
69
70 <configfiles>
71 <inputs name="inputs" />
72
73 <configfile name="script_file">
74 import json
75 import sys
76 import os
77
78 FOURSPACES=@SPACES@
79
80 input_json_path = sys.argv[1]
81 input_pipeline= sys.argv[2]
82
83 params = json.load(open(input_json_path, "r"))
84
85 def writemiq():
86 _str = "\nMeasureImageQuality:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:5|show_window:False|notes:\\x5B\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count
87
88 for_images = params['calc_for_images']
89 selected_images = ""
90
91 if for_images == "All loaded images":
92 _str += FOURSPACES + "Calculate metrics for which images?:%s\n" % for_images
93 else:
94 _str += FOURSPACES + "Calculate metrics for which images?:Select...\n"
95 selected_images = params['calc_for_images']
96
97 image_count = 1
98 _str += FOURSPACES + "Image count:%d\n" % image_count
99
100 if 'rpt_blur_measurements' in params['con_calc_blur_metrics']:
101 scale_count = len(params['con_calc_blur_metrics']['rpt_blur_measurements'])
102 else:
103 scale_count = 1
104
105 _str += FOURSPACES + "Scale count:%d\n" % scale_count
106
107 calc_threshold = params['con_calc_threshold']['calc_threshold']
108 if calc_threshold == "No":
109 threshold_count = 1
110 all_method = "No"
111 else:
112 all_method = params['con_calc_threshold']['con_use_all_methods']['use_all_methods']
113 if all_method == "No":
114 threshold_count = 1
115 else:
116 threshold_count = len(params['con_calc_threshold']['con_use_all_methods']['rpt_threshold_method'])
117
118 _str += FOURSPACES + "Threshold count:%d\n" % threshold_count
119
120 _str += FOURSPACES + "Select the images to measure:%s\n" % selected_images
121
122 include_rescaling = params['include_rescaling_value']
123 _str += FOURSPACES + "Include the image rescaling value?:%s\n" % include_rescaling
124
125 calc_blur_metrics = params['con_calc_blur_metrics']['calc_blur_metrics']
126 _str += FOURSPACES + "Calculate blur metrics?:%s\n" % calc_blur_metrics
127
128 if calc_blur_metrics == "Yes" and 'rpt_blur_measurements' in params['con_calc_blur_metrics']:
129 for bm in params['con_calc_blur_metrics']['rpt_blur_measurements']:
130 _str += FOURSPACES + "Spatial scale for blur measurements:%d\n" % bm['blur_measurements']
131
132 calc_saturation = params['calc_saturation_metrics']
133 _str += FOURSPACES + "Calculate saturation metrics?:%s\n" % calc_saturation
134
135 calc_intensity = params['calc_intensity_metrics']
136 _str += FOURSPACES + "Calculate intensity metrics?:%s\n" % calc_intensity
137
138 calc_threshold = params['con_calc_threshold']['calc_threshold']
139 _str += FOURSPACES + "Calculate thresholds?:%s\n" % calc_threshold
140 _str += FOURSPACES + "Use all thresholding methods?:%s\n" % all_method
141
142 if all_method == "No":
143 for method in params['con_calc_threshold']['con_use_all_methods']['rpt_threshold_method']:
144 _str += FOURSPACES + "Select a thresholding method:%s\n" % method['con_threshold_methods']['select_threshold_method']
145
146 fraction_cover = method['con_threshold_methods']['mog_fraction_cover'] if 'mog_fraction_cover' in method[
147 'con_threshold_methods'] else 0.1
148
149 tt_classes = method['con_threshold_methods']['con_threshold_classes'][
150 'threshold_classes'] if 'con_threshold_classes' in method['con_threshold_methods'] else 'Two classes'
151
152 minimize = method['con_threshold_methods']['otsu_weighted_entropy'] if 'otsu_weighted_entropy' in method[
153 'con_threshold_methods'] else 'Entropy'
154
155 if tt_classes == "Three classes":
156 pixel_intensity = method['con_threshold_methods']['con_threshold_classes'][
157 'pixel_foreground_or_background']
158 else:
159 pixel_intensity = "Foreground"
160
161 _str += FOURSPACES + "Typical fraction of the image covered by objects:%.1f\n" % fraction_cover
162
163 _str += FOURSPACES + "Two-class or three-class thresholding?:%s\n" % tt_classes
164
165 _str += FOURSPACES + "Minimize the weighted variance or the entropy:%s\n" % minimize
166
167 _str += FOURSPACES + "Assign pixels in the middle intensity class to the foreground or the background?:%s\n" % pixel_intensity
168
169 return _str
170
171 with open(input_pipeline) as fin:
172 lines = fin.readlines()
173
174 k, v = lines[4].strip().split(':')
175
176 module_count = int(v)
177 new_count = module_count + 1
178 lines[4] = k + ":%d\n" % new_count
179
180 with open("output", "w") as f:
181 f.writelines(lines)
182 f.write(writemiq())
183
184 f.close()
185 </configfile>
186 </configfiles>
187
188 <inputs>
189 <expand macro="input_pipeline_macro" />
190 <param name="calc_for_images" type="text" label="Calculate metrics for which images?" value="All loaded images">
191 <expand macro="text_validator" />
192 </param>
193 <param name="include_rescaling_value" type="select" display="radio" label="Include the image rescaling value?">
194 <option value="Yes">Yes</option>
195 <option value="No">No</option>
196 </param>
197
198 <conditional name="con_calc_blur_metrics">
199 <param name="calc_blur_metrics" type="select" display="radio" label="Calculate blur metrics?">
200 <option value="Yes">Yes</option>
201 <option value="No">No</option>
202 </param>
203 <when value="Yes">
204 <repeat name="rpt_blur_measurements" title="Add another scale">
205 <param name="blur_measurements" label="Spatial scale for blur measurements" type="integer" value="20"/>
206 </repeat>
207 </when>
208 <when value="No" />
209 </conditional>
210
211 <param name="calc_intensity_metrics" type="select" display="radio" label="Calculate intensity metrics?">
212 <option value="Yes">Yes</option>
213 <option value="No">No</option>
214 </param>
215 <param name="calc_saturation_metrics" type="select" display="radio" label="Calculate saturation metrics">
216 <option value="Yes">Yes</option>
217 <option value="No">No</option>
218 </param>
219
220 <conditional name="con_calc_threshold">
221 <param name="calc_threshold" type="select" display="radio" label="Calculate thresholds?">
222 <option value="Yes">Yes</option>
223 <option value="No">No</option>
224 </param>
225 <when value="Yes">
226 <expand macro="macro_calc_threshold" />
227 </when>
228 <when value="No" />
229 </conditional>
230
231 </inputs>
232
233 <outputs>
234 <expand macro="output_pipeline_macro" />
235 </outputs>
236
237 <tests>
238 <test>
239 <expand macro="test_input_pipeline_param" />
240
241 <param name="calc_for_images" value="All loaded images" />
242 <param name="include_rescaling_value" value="Yes" />
243
244 <conditional name="con_calc_blur_metrics">
245 <param name="calc_blur_metrics" value="Yes" />
246 <repeat name="rpt_blur_measurements">
247 <param name="blur_measurements" value="20" />
248 </repeat>
249 </conditional>
250
251 <param name="calc_intensity_metrics" value="Yes" />
252 <param name="calc_saturation_metrics" value="Yes" />
253 <conditional name="con_calc_threshold">
254 <param name="calc_threshold" value="Yes" />
255 </conditional>
256
257 <conditional name="con_use_all_methods">
258 <param name="use_all_methods" value="No" />
259 <repeat name="rpt_threshold_method">
260 <conditional name="con_threshold_methods">
261 <param name="select_threshold_method" value="Otsu" />
262 <param name="otsu_weighted_entropy" value="Weighted variance" />
263 <conditional name="con_threshold_classes">
264 <param name="threshold_classes" value="Two classes" />
265 </conditional>
266 </conditional>
267 </repeat>
268 </conditional>
269
270 <expand macro="test_out_file" file="measure_image_quality.txt" />
271 </test>
272 </tests>
273
274 <expand macro="help" module="MeasureImageQuality" />
275 <expand macro="citations" />
276 </tool>