comparison jython_script.py @ 7:be709f819445 draft

planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
author iuc
date Fri, 19 Jun 2015 16:57:16 -0400
parents 7a96d686d380
children
comparison
equal deleted inserted replaced
6:3026e9b2bf77 7:be709f819445
1 import sys 1 import sys
2 import imagej2_base_utils 2 import jython_utils
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 7
21 source_path = sys.argv[ -5 ] 21 source_path = sys.argv[ -5 ]
22 target_tiff_path = sys.argv[ -4 ] 22 target_tiff_path = sys.argv[ -4 ]
23 target_datatype = sys.argv[ -3 ] 23 target_datatype = sys.argv[ -3 ]
24 target_path = sys.argv[ -2 ] 24 target_path = sys.argv[ -2 ]
25 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. 26 # Save the Registered Source Image.
42 registered_source_image = IJ.openImage( source_tiff_path ) 27 registered_source_image = IJ.openImage( source_tiff_path )
43 if source_datatype == 'tiff': 28 if source_datatype == 'tiff':
44 registered_source_image = convert_before_saving_as_tiff( registered_source_image ) 29 registered_source_image = jython_utils.convert_before_saving_as_tiff( registered_source_image )
45 IJ.saveAs( registered_source_image, source_datatype, source_path ) 30 IJ.saveAs( registered_source_image, source_datatype, source_path )
46 31
47 if not mono: 32 if not mono:
48 # Save the Registered Target Image. 33 # Save the Registered Target Image.
49 registered_target_image = IJ.openImage( target_tiff_path ) 34 registered_target_image = IJ.openImage( target_tiff_path )
50 if target_datatype == 'tiff': 35 if target_datatype == 'tiff':
51 registered_target_image = convert_before_saving_as_tiff( registered_target_image ) 36 registered_target_image = jython_utils.convert_before_saving_as_tiff( registered_target_image )
52 IJ.saveAs( registered_target_image, target_datatype, target_path ) 37 IJ.saveAs( registered_target_image, target_datatype, target_path )