Mercurial > repos > iuc > imagej2_make_binary
comparison jython_script.py @ 0:66d9e595dff2 draft
planemo upload commit 98c34e070343a117019ffd25a3af117808159bf5-dirty
| author | iuc |
|---|---|
| date | Tue, 04 Aug 2015 13:20:29 -0400 |
| parents | |
| children | d26f11339f08 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:66d9e595dff2 |
|---|---|
| 1 import jython_utils | |
| 2 import sys | |
| 3 from ij import IJ | |
| 4 from ij import ImagePlus | |
| 5 | |
| 6 # Fiji Jython interpreter implements Python 2.5 which does not | |
| 7 # provide support for argparse. | |
| 8 error_log = sys.argv[ -8 ] | |
| 9 input = sys.argv[ -7 ] | |
| 10 iterations = sys.argv[ -6 ] | |
| 11 count = sys.argv[ -5 ] | |
| 12 black_background = sys.argv[ -4 ] | |
| 13 pad_edges_when_eroding = sys.argv[ -3 ] | |
| 14 tmp_output_path = sys.argv[ -2 ] | |
| 15 output_datatype = sys.argv[ -1 ] | |
| 16 | |
| 17 # Open the input image file. | |
| 18 input_image_plus = IJ.openImage( input ) | |
| 19 bit_depth = input_image_plus.getBitDepth() | |
| 20 image_type = input_image_plus.getType() | |
| 21 | |
| 22 # Create a copy of the image. | |
| 23 input_image_plus_copy = input_image_plus.createImagePlus() | |
| 24 image_processor_copy = input_image_plus.getProcessor().duplicate() | |
| 25 input_image_plus_copy.setProcessor( "iCopy", image_processor_copy ) | |
| 26 | |
| 27 try: | |
| 28 options = [ "iterations=&iterations" "count=&count" ] | |
| 29 if black_background == "yes": | |
| 30 options.append( "black" ) | |
| 31 if pad_edges_when_eroding == "yes": | |
| 32 options.append( "pad" ) | |
| 33 # The following have no affect within this tool, but are necessary. | |
| 34 options.append( "edm=Overwrite" ) | |
| 35 options.append( "do=Nothing" ) | |
| 36 # Run the command. | |
| 37 IJ.run( input_image_plus_copy, "Make Binary", " ".join( options ) ) | |
| 38 # Save the ImagePlus object as a new image. | |
| 39 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) | |
| 40 except Exception, e: | |
| 41 jython_utils.handle_error( error_log, str( e ) ) |
