Mercurial > repos > imgteam > imagej2_skeletonize3d
comparison imagej2_binary_to_edm_jython_script.py @ 1:768825d9034a draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
author | imgteam |
---|---|
date | Mon, 28 Sep 2020 17:01:19 +0000 |
parents | f6df6830d5ec |
children | 49b5288dcd8c |
comparison
equal
deleted
inserted
replaced
0:f6df6830d5ec | 1:768825d9034a |
---|---|
1 import jython_utils | |
2 import sys | 1 import sys |
2 | |
3 from ij import IJ | 3 from ij import IJ |
4 from ij import ImagePlus | |
5 from ij.plugin.filter import Analyzer | |
6 from ij.plugin.filter import EDM | |
7 | 4 |
8 # Fiji Jython interpreter implements Python 2.5 which does not | 5 # Fiji Jython interpreter implements Python 2.5 which does not |
9 # provide support for argparse. | 6 # provide support for argparse. |
10 error_log = sys.argv[ -8 ] | 7 error_log = sys.argv[-8] |
11 input = sys.argv[ -7 ] | 8 input_file = sys.argv[-7] |
12 iterations = int( sys.argv[ -6 ] ) | 9 iterations = int(sys.argv[-6]) |
13 count = int( sys.argv[ -5 ] ) | 10 count = int(sys.argv[-5]) |
14 black_background = jython_utils.asbool( sys.argv[ -4 ] ) | 11 black_background = sys.argv[-4] == "yes" |
15 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] ) | 12 pad_edges_when_eroding = sys.argv[-3] == "yes" |
16 tmp_output_path = sys.argv[ -2 ] | 13 output_filename = sys.argv[-2] |
17 output_datatype = sys.argv[ -1 ] | 14 output_datatype = sys.argv[-1] |
18 | 15 |
19 # Open the input image file. | 16 # Open the input image file. |
20 input_image_plus = IJ.openImage( input ) | 17 input_image_plus = IJ.openImage(input_file) |
21 | 18 |
22 # Create a copy of the image. | 19 # Create a copy of the image. |
23 input_image_plus_copy = input_image_plus.duplicate() | 20 input_image_plus_copy = input_image_plus.duplicate() |
24 image_processor_copy = input_image_plus_copy.getProcessor() | 21 image_processor_copy = input_image_plus_copy.getProcessor() |
25 | 22 |
26 try: | 23 # Set binary options. |
27 # Set binary options. | 24 options_list = ['edm=Overwrite', 'iterations=%d' % iterations, 'count=%d' % count] |
28 options = jython_utils.get_binary_options( black_background=black_background, | 25 if black_background: |
29 iterations=iterations, | 26 options_list.append("black") |
30 count=count, | 27 if pad_edges_when_eroding: |
31 pad_edges_when_eroding=pad_edges_when_eroding ) | 28 options_list.append("pad") |
32 IJ.run( input_image_plus_copy, "Options...", options ) | 29 options = " ".join(options_list) |
30 IJ.run(input_image_plus_copy, "Options...", options) | |
33 | 31 |
34 # Convert image to binary if necessary. | 32 # Convert image to binary if necessary. |
35 if not image_processor_copy.isBinary(): | 33 if not image_processor_copy.isBinary(): |
36 # Convert the image to binary grayscale. | 34 # Convert the image to binary grayscale. |
37 IJ.run( input_image_plus_copy, "Make Binary", "" ) | 35 IJ.run(input_image_plus_copy, "Make Binary", "") |
38 | 36 |
39 # Run the command. | 37 # Run the command. |
40 IJ.run( input_image_plus_copy, "Distance Map", "" ) | 38 IJ.run(input_image_plus_copy, "Distance Map", "") |
41 # Save the ImagePlus object as a new image. | 39 # Save the ImagePlus object as a new image. |
42 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) | 40 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) |
43 except Exception, e: | |
44 jython_utils.handle_error( error_log, str( e ) ) |