Mercurial > repos > iuc > imagej2_convert_format
comparison imagej2_convert_format.py @ 0:312e8ce708b1 draft
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
| author | iuc |
|---|---|
| date | Tue, 09 Jun 2015 12:21:40 -0400 |
| parents | |
| children | 14d09b0ab9e1 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:312e8ce708b1 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # Galaxy wrapper for use with Imagej2 via bioformats and javabridge by Greg Von Kuster | |
| 3 """ | |
| 4 A wrapper script for running ImageJ2 commands via bioformats and javabridge. | |
| 5 """ | |
| 6 import argparse | |
| 7 import imagej2_base_utils | |
| 8 import imagej2_utils | |
| 9 | |
| 10 if __name__=="__main__": | |
| 11 # Parse Command Line. | |
| 12 parser = argparse.ArgumentParser() | |
| 13 parser.add_argument( '--in_fname', dest='in_fname', help='Path to the input file' ) | |
| 14 parser.add_argument( '--input_datatype', dest='input_datatype', help='Input image datatype' ) | |
| 15 parser.add_argument( '--max_heap_size_type', dest='max_heap_size_type', help='Type (default or megabytes) of max_heap_size value' ) | |
| 16 parser.add_argument( '--max_heap_size', dest='max_heap_size', help='Maximum size of the memory allocation pool used by the JVM.' ) | |
| 17 parser.add_argument( '--output_datatype', dest='output_datatype', help='Output image datatype' ) | |
| 18 parser.add_argument( '--out_fname', help='Path to the output file' ) | |
| 19 args = parser.parse_args() | |
| 20 # Set the size of the memory allocation pool used by the JVM. | |
| 21 max_heap_size = imagej2_base_utils.get_max_heap_size_value( args.max_heap_size_type, args.max_heap_size ) | |
| 22 # Start the JVM via the Javabridge. | |
| 23 imagej2_utils.start_vm( args=None, class_path=None, max_heap_size=max_heap_size, run_headless=True ) | |
| 24 try: | |
| 25 tmp_dir = imagej2_base_utils.get_temp_dir() | |
| 26 in_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.in_fname, args.input_datatype ) | |
| 27 # Load the input image. | |
| 28 image, scale = imagej2_utils.load_image( in_image_path, rescale=False, wants_max_intensity=True ) | |
| 29 # Write the output image. | |
| 30 out_image_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype ) | |
| 31 imagej2_utils.write_image( image_path=out_image_path, pixels=image, pixel_type=str( image.dtype ), move_to=args.out_fname ) | |
| 32 except Exception, e: | |
| 33 imagej2_base_utils.stop_err( str( e ) ) | |
| 34 finally: | |
| 35 imagej2_utils.kill_vm() | |
| 36 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |
