# HG changeset patch # User imgteam # Date 1712244198 0 # Node ID e5c8e7e72373669790e094e5427945bda8e1af5e # Parent 8bccb36e055a68538c98c30fb9c98b94ce10709a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_auto_threshold/ commit c045f067a57e8308308cf6329060c7ccd3fc372f 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) 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 @@ -1,9 +1,17 @@ with scikit-image + creators.xml + tests.xml 0.18.1 - 1 + 2 + + + + + + operation_3443 @@ -12,7 +20,7 @@ scikit-image - scikit-image + scikit-image tifffile @@ -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 @@ + + + + + + + + @@ -78,36 +95,50 @@ + - - + + + + + + + + + + - - + - + + + + + - 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. + 10.1016/j.jbiotec.2017.07.019 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 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out.tif Binary file test-data/out.tif has changed diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out1.tif Binary file test-data/out1.tif has changed diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out2.tif Binary file test-data/out2.tif has changed diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out3.tif Binary file test-data/out3.tif has changed diff -r 8bccb36e055a -r e5c8e7e72373 test-data/out4.tif Binary file test-data/out4.tif has changed diff -r 8bccb36e055a -r e5c8e7e72373 test-data/rgb.png Binary file test-data/rgb.png has changed 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 @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +