Previous changeset 6:8bccb36e055a (2024-03-13) Next changeset 8:699a5e9146b3 (2024-04-24) |
Commit message:
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit c045f067a57e8308308cf6329060c7ccd3fc372f |
modified:
auto_threshold.py auto_threshold.xml test-data/out2.tif test-data/out3.tif |
added:
creators.xml test-data/out1.tif test-data/out4.tif test-data/rgb.png tests.xml |
removed:
test-data/out.tif |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 auto_threshold.py --- a/auto_threshold.py Wed Mar 13 06:15:54 2024 +0000 +++ b/auto_threshold.py Thu Apr 04 15:23:18 2024 +0000 |
[ |
@@ -27,23 +27,28 @@ } -def do_thresholding(in_fn, out_fn, th_method, block_size=5, threshold=0, invert_output=False): +def do_thresholding(in_fn, out_fn, th_method, block_size, offset, threshold, invert_output=False): img = skimage.io.imread(in_fn) - th = th_methods[th_method](img_raw=img, bz=block_size, thres=threshold) + img = np.squeeze(img) + assert img.ndim == 2 + + th = offset + th_methods[th_method](img_raw=img, bz=block_size, thres=threshold) res = img > th if invert_output: res = np.logical_not(res) + tifffile.imwrite(out_fn, skimage.util.img_as_ubyte(res)) if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Automatic Image Thresholding') + parser = argparse.ArgumentParser(description='Automatic image thresholding') parser.add_argument('im_in', help='Path to the input image') - parser.add_argument('im_out', help='Path to the output image (TIFF)') + parser.add_argument('im_out', help='Path to the output image (uint8)') parser.add_argument('th_method', choices=th_methods.keys(), help='Thresholding method') parser.add_argument('block_size', type=int, default=5, help='Odd size of pixel neighborhood for calculating the threshold') - parser.add_argument('threshold', type=float, default=0, help='Manual thresholding value') + parser.add_argument('offset', type=float, default=0, help='Offset of automatically determined threshold value') + parser.add_argument('threshold', type=float, default=0, help='Manual threshold value') 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') args = parser.parse_args() - do_thresholding(args.im_in, args.im_out, args.th_method, args.block_size, args.threshold, args.invert_output) + do_thresholding(args.im_in, args.im_out, args.th_method, args.block_size, args.offset, args.threshold, args.invert_output) |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 auto_threshold.xml --- a/auto_threshold.xml Wed Mar 13 06:15:54 2024 +0000 +++ b/auto_threshold.xml Thu Apr 04 15:23:18 2024 +0000 |
b |
@@ -1,9 +1,17 @@ <tool id="ip_threshold" name="Threshold image" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05"> <description>with scikit-image</description> <macros> + <import>creators.xml</import> + <import>tests.xml</import> <token name="@TOOL_VERSION@">0.18.1</token> - <token name="@VERSION_SUFFIX@">1</token> + <token name="@VERSION_SUFFIX@">2</token> + <xml name="inputs/offset"> + <param name="offset" type="float" value="0" label="Offset" help="Offset to be added to the automatically determined threshold value. Positive values will increase the threshold (and thus reduce the amount of values above the threshold)." /> + </xml> </macros> + <creator> + <expand macro="creators/bmcv"/> + </creator> <edam_operations> <edam_operation>operation_3443</edam_operation> </edam_operations> @@ -12,7 +20,7 @@ <xref type="biii">scikit-image</xref> </xrefs> <requirements> - <requirement type="package" version="0.18.1">scikit-image</requirement> + <requirement type="package" version="@TOOL_VERSION@">scikit-image</requirement> <requirement type="package" version="2020.10.1">tifffile</requirement> </requirements> <command detect_errors="aggressive"> @@ -22,6 +30,7 @@ ./out.tif '$th_method.method_id' '$th_method.block_size' + '$th_method.offset' '$th_method.threshold' $invert_output ]]> @@ -42,34 +51,42 @@ <when value="manual"> <param name="threshold" type="float" value="0" label="Threshold value" /> <param name="block_size" type="hidden" value="0" /> + <param name="offset" type="hidden" value="0" /> </when> <when value="otsu"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="hidden" value="0" /> + <expand macro="inputs/offset" /> </when> <when value="li"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="hidden" value="0" /> + <expand macro="inputs/offset" /> </when> <when value="isodata"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="hidden" value="0" /> + <expand macro="inputs/offset" /> </when> <when value="yen"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="hidden" value="0" /> + <expand macro="inputs/offset" /> </when> <when value="loc_gaussian"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="integer" value="5" label="Odd size of pixel neighborhood for determining the threshold" /> + <expand macro="inputs/offset" /> </when> <when value="loc_median"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="integer" value="5" label="Odd size of pixel neighborhood for determining the threshold" /> + <expand macro="inputs/offset" /> </when> <when value="loc_mean"> <param name="threshold" type="hidden" value="0" /> <param name="block_size" type="integer" value="5" label="Odd size of pixel neighborhood for determining the threshold" /> + <expand macro="inputs/offset" /> </when> </conditional> <param name="invert_output" type="boolean" checked="false" truevalue="--invert_output" falsevalue="" label="Invert output labels" help="Pixels are usually assigned the label 0 if the pixel value is below (or equal to) the threshold, and 255 if it is above the threshold. If this option is activated, pixels are assigned the label 255 if the pixel value is below (or equal to) the threshold, and 0 if it is above the threshold." /> @@ -78,36 +95,50 @@ <data format="tiff" name="output" from_work_dir="out.tif" /> </outputs> <tests> + <!-- Tests for single-channel images --> <test> <param name="input" value="sample.tif"/> - <output name="output" value="out.tif" ftype="tiff" compare="sim_size" delta="10"/> <param name="method_id" value="loc_gaussian"/> - <param name="block_size" value="3"/> + <param name="block_size" value="51"/> <param name="invert_output" value="False"/> + <expand macro="tests/binary_image_diff" name="output" value="out1.tif" ftype="tiff"/> + </test> + <test> + <param name="input" value="sample.tif"/> + <param name="method_id" value="loc_gaussian"/> + <param name="block_size" value="51"/> + <param name="offset" value="1"/> + <param name="invert_output" value="False"/> + <expand macro="tests/binary_image_diff" name="output" value="out2.tif" ftype="tiff"/> </test> <test> <param name="input" value="sample.tif"/> - <output name="output" value="out2.tif" ftype="tiff" compare="sim_size" delta="10"/> <param name="method_id" value="otsu"/> - <param name="block_size" value="5"/> <param name="invert_output" value="False"/> + <expand macro="tests/binary_image_diff" name="output" value="out3.tif" ftype="tiff"/> </test> <test> <param name="input" value="sample.tif"/> - <output name="output" value="out3.tif" ftype="tiff" compare="sim_size" delta="10"/> <param name="method_id" value="manual"/> <param name="threshold" value="64"/> <param name="invert_output" value="True"/> + <expand macro="tests/binary_image_diff" name="output" value="out4.tif" ftype="tiff"/> + </test> + <!-- Tests for multi-channel images --> + <test expect_failure="true"> + <param name="input" value="rgb.png"/> </test> </tests> <help> - Applies a standard thresholding algorithm to an image. + + **Applies a standard thresholding algorithm to a 2-D single-channel image. Yields a binary image.** The thresholding algorithm automatically determines a threshold value (unless manual thresholding is used). The input image is then thresholded, by assigning white (pixel value 255) to image regions above the determined threshold, and black (pixel value 0) to image regions below or equal to the determined threshold. The assignment of black and white to image regions below and above the threshold is inverted, if the corresponding option is set. + </help> <citations> <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 creators.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/creators.xml Thu Apr 04 15:23:18 2024 +0000 |
b |
@@ -0,0 +1,23 @@ +<macros> + + <xml name="creators/bmcv"> + <organization name="Biomedical Computer Vision Group, Heidelberg Universtiy" alternateName="BMCV" url="http://www.bioquant.uni-heidelberg.de/research/groups/biomedical_computer_vision.html" /> + <yield /> + </xml> + + <xml name="creators/alliecreason"> + <person givenName="Allison" familyName="Creason"/> + <yield/> + </xml> + + <xml name="creators/bugraoezdemir"> + <person givenName="Bugra" familyName="Oezdemir"/> + <yield/> + </xml> + + <xml name="creators/thawn"> + <person givenName="Till" familyName="Korten"/> + <yield/> + </xml> + +</macros> |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out.tif |
b |
Binary file test-data/out.tif has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out1.tif |
b |
Binary file test-data/out1.tif has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out2.tif |
b |
Binary file test-data/out2.tif has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out3.tif |
b |
Binary file test-data/out3.tif has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out4.tif |
b |
Binary file test-data/out4.tif has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 test-data/rgb.png |
b |
Binary file test-data/rgb.png has changed |
b |
diff -r 8bccb36e055a -r e5c8e7e72373 tests.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests.xml Thu Apr 04 15:23:18 2024 +0000 |
b |
@@ -0,0 +1,95 @@ +<macros> + + <!-- Macros for verification of image outputs --> + + <xml + name="tests/binary_image_diff" + tokens="name,value,ftype,metric,eps" + token_metric="mae" + token_eps="0.01"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0"> + <assert_contents> + <has_image_n_labels n="2"/> + <yield/> + </assert_contents> + </output> + + </xml> + + <xml + name="tests/label_image_diff" + tokens="name,value,ftype,metric,eps,pin_labels" + token_metric="iou" + token_eps="0.01" + token_pin_labels="0"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@"> + <assert_contents> + <yield/> + </assert_contents> + </output> + + </xml> + + <xml + name="tests/intensity_image_diff" + tokens="name,value,ftype,metric,eps" + token_metric="rms" + token_eps="0.01"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@"> + <assert_contents> + <yield/> + </assert_contents> + </output> + + </xml> + + <!-- Variants of the above for verification of collection elements --> + + <xml + name="tests/binary_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="mae" + token_eps="0.01"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0"> + <assert_contents> + <has_image_n_labels n="2"/> + <yield/> + </assert_contents> + </element> + + </xml> + + <xml + name="tests/label_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="iou" + token_eps="0.01" + token_pin_labels="0"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@"> + <assert_contents> + <yield/> + </assert_contents> + </element> + + </xml> + + <xml + name="tests/intensity_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="rms" + token_eps="0.01"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@"> + <assert_contents> + <yield/> + </assert_contents> + </element> + + </xml> + +</macros> |