comparison jython_script.py @ 0:7a96d686d380 draft

planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
author iuc
date Tue, 09 Jun 2015 12:22:23 -0400
parents
children be709f819445
comparison
equal deleted inserted replaced
-1:000000000000 0:7a96d686d380
1 import sys
2 import imagej2_base_utils
3 from ij import IJ
4
5 # Fiji Jython interpreter implements Python 2.5 which does not
6 # provide support for argparse.
7
8 if sys.argv[ -1 ].lower() in [ 'true' ]:
9 mono = True
10 else:
11 mono = False
12
13 if mono:
14 # bUnwarpJ has been called with the -mono param.
15 source_tiff_path = sys.argv[ -4 ]
16 source_datatype = sys.argv[ -3 ]
17 source_path = sys.argv[ -2 ]
18 else:
19 source_tiff_path = sys.argv[ -7 ]
20 source_datatype = sys.argv[ -6 ]
21 source_path = sys.argv[ -5 ]
22 target_tiff_path = sys.argv[ -4 ]
23 target_datatype = sys.argv[ -3 ]
24 target_path = sys.argv[ -2 ]
25
26 def convert_before_saving_as_tiff( registered_image ):
27 # The bUnwarpJ macro produces tiff image stacks consisting of 3
28 # slices which can be viewed in ImageJ. The 3 slices are::
29 # 1) the registered image, 2) the target image and 3) the black/white
30 # warp image. Galaxy supports only single-layered images, so we have
31 # to convert the image to something other than tiff so that slices are
32 # eliminated and we can then convert back to tiff for saving. This is
33 # kind of a hack - there is probably a way to do this without converting
34 # twice. I messed around with the the ImageJ getSlice() method, but
35 # couldn't get it to produce what is needed here.
36 tmp_dir = imagej2_base_utils.get_temp_dir()
37 tmp_out_png_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'png' )
38 IJ.saveAs( registered_image, 'png', tmp_out_png_path )
39 return IJ.openImage( tmp_out_png_path )
40
41 # Save the Registered Source Image.
42 registered_source_image = IJ.openImage( source_tiff_path )
43 if source_datatype == 'tiff':
44 registered_source_image = convert_before_saving_as_tiff( registered_source_image )
45 IJ.saveAs( registered_source_image, source_datatype, source_path )
46
47 if not mono:
48 # Save the Registered Target Image.
49 registered_target_image = IJ.openImage( target_tiff_path )
50 if target_datatype == 'tiff':
51 registered_target_image = convert_before_saving_as_tiff( registered_target_image )
52 IJ.saveAs( registered_target_image, target_datatype, target_path )