Mercurial > repos > imgteam > imagej2_watershed_binary
comparison imagej2_make_binary_jython_script.py @ 1:5b154339fd90 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 16:36:30 +0000 | 
| parents | b143159845b4 | 
| children | aeae7e29d525 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 0:b143159845b4 | 1:5b154339fd90 | 
|---|---|
| 1 import jython_utils | |
| 2 import sys | 1 import sys | 
| 2 | |
| 3 from ij import IJ | 3 from ij import IJ | 
| 4 | 4 | 
| 5 # Fiji Jython interpreter implements Python 2.5 which does not | 5 # Fiji Jython interpreter implements Python 2.5 which does not | 
| 6 # provide support for argparse. | 6 # provide support for argparse. | 
| 7 error_log = sys.argv[ -8 ] | 7 error_log = sys.argv[-8] | 
| 8 input = sys.argv[ -7 ] | 8 input = sys.argv[-7] | 
| 9 iterations = int( sys.argv[ -6 ] ) | 9 iterations = int(sys.argv[-6]) | 
| 10 count = int( sys.argv[ -5 ] ) | 10 count = int(sys.argv[-5]) | 
| 11 black_background = jython_utils.asbool( sys.argv[ -4 ] ) | 11 black_background = sys.argv[-4] == 'yes' | 
| 12 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] ) | 12 pad_edges_when_eroding = sys.argv[-3] == 'yes' | 
| 13 tmp_output_path = sys.argv[ -2 ] | 13 tmp_output_path = sys.argv[-2] | 
| 14 output_datatype = sys.argv[ -1 ] | 14 output_datatype = sys.argv[-1] | 
| 15 | 15 | 
| 16 # Open the input image file. | 16 # Open the input image file. | 
| 17 input_image_plus = IJ.openImage( input ) | 17 input_image_plus = IJ.openImage(input) | 
| 18 | 18 | 
| 19 # Create a copy of the image. | 19 # Create a copy of the image. | 
| 20 input_image_plus_copy = input_image_plus.duplicate() | 20 input_image_plus_copy = input_image_plus.duplicate() | 
| 21 image_processor_copy = input_image_plus_copy.getProcessor() | 21 image_processor_copy = input_image_plus_copy.getProcessor() | 
| 22 | 22 | 
| 23 try: | 23 # Set binary options. | 
| 24 # Set binary options. | 24 options = ['edm=Overwrite', 'iterations=%d' % iterations, 'count=%d' % count] | 
| 25 options = jython_utils.get_binary_options( black_background=black_background, | 25 if pad_edges_when_eroding: | 
| 26 iterations=iterations, | 26 options.append('pad') | 
| 27 count=count, | 27 if black_background: | 
| 28 pad_edges_when_eroding=pad_edges_when_eroding ) | 28 options.append('black') | 
| 29 IJ.run( input_image_plus_copy, "Options...", options ) | 29 options = ' '.join(options) | 
| 30 IJ.run(input_image_plus_copy, "Options...", options) | |
| 30 | 31 | 
| 31 # Run the command. | 32 # Run the command. | 
| 32 IJ.run( input_image_plus_copy, "Make Binary", "" ) | 33 IJ.run(input_image_plus_copy, "Make Binary", "") | 
| 33 | 34 | 
| 34 # Save the ImagePlus object as a new image. | 35 # Save the ImagePlus object as a new image. | 
| 35 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) | 36 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) | 
| 36 except Exception, e: | |
| 37 jython_utils.handle_error( error_log, str( e ) ) | 
