Mercurial > repos > bgruening > imagej2_bunwarpj_convert_to_raw
annotate imagej2_make_binary_jython_script.py @ 0:191d574ddd8d draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
author | bgruening |
---|---|
date | Sat, 18 Mar 2017 09:43:20 -0400 |
parents | |
children |
rev | line source |
---|---|
0
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
1 import jython_utils |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
2 import sys |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
3 from ij import IJ |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
4 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
5 # Fiji Jython interpreter implements Python 2.5 which does not |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
6 # provide support for argparse. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
7 error_log = sys.argv[ -8 ] |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
8 input = sys.argv[ -7 ] |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
9 iterations = int( sys.argv[ -6 ] ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
10 count = int( sys.argv[ -5 ] ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
11 black_background = jython_utils.asbool( sys.argv[ -4 ] ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
12 pad_edges_when_eroding = jython_utils.asbool( sys.argv[ -3 ] ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
13 tmp_output_path = sys.argv[ -2 ] |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
14 output_datatype = sys.argv[ -1 ] |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
15 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
16 # Open the input image file. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
17 input_image_plus = IJ.openImage( input ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
18 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
19 # Create a copy of the image. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
20 input_image_plus_copy = input_image_plus.duplicate() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
21 image_processor_copy = input_image_plus_copy.getProcessor() |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
22 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
23 try: |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
24 # Set binary options. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
25 options = jython_utils.get_binary_options( black_background=black_background, |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
26 iterations=iterations, |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
27 count=count, |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
28 pad_edges_when_eroding=pad_edges_when_eroding ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
29 IJ.run( input_image_plus_copy, "Options...", options ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
30 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
31 # Run the command. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
32 IJ.run( input_image_plus_copy, "Make Binary", "" ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
33 |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
34 # Save the ImagePlus object as a new image. |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
35 IJ.saveAs( input_image_plus_copy, output_datatype, tmp_output_path ) |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
36 except Exception, e: |
191d574ddd8d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b'7e5cd452018ae9507c2d1cd13dd688a747550393\n'
bgruening
parents:
diff
changeset
|
37 jython_utils.handle_error( error_log, str( e ) ) |