Mercurial > repos > imgteam > imagej2_skeletonize3d
comparison imagej2_bunwarpj_compose_raw_elastic.py @ 0:f6df6830d5ec draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
author | imgteam |
---|---|
date | Tue, 17 Sep 2019 16:57:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f6df6830d5ec |
---|---|
1 #!/usr/bin/env python | |
2 import argparse | |
3 import subprocess | |
4 import tempfile | |
5 import imagej2_base_utils | |
6 | |
7 # Parse Command Line. | |
8 parser = argparse.ArgumentParser() | |
9 parser.add_argument( '--source_image', dest='source_image', help='Source image' ) | |
10 parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) | |
11 parser.add_argument( '--target_image', dest='target_image', help='Target image' ) | |
12 parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) | |
13 parser.add_argument( '--source_elastic_transformation', dest='source_elastic_transformation', help='Direct source transformation matrix' ) | |
14 parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='Inverse target transformation matrix' ) | |
15 parser.add_argument( '--output', dest='output', help='Warping index' ) | |
16 | |
17 args = parser.parse_args() | |
18 | |
19 tmp_dir = imagej2_base_utils.get_temp_dir() | |
20 source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) | |
21 target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) | |
22 source_elastic_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_elastic_transformation, 'txt' ) | |
23 target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) | |
24 | |
25 # Define command response buffers. | |
26 tmp_out = tempfile.NamedTemporaryFile().name | |
27 tmp_stdout = open( tmp_out, 'wb' ) | |
28 tmp_err = tempfile.NamedTemporaryFile().name | |
29 tmp_stderr = open( tmp_err, 'wb' ) | |
30 | |
31 # Build the command line to compose the raw and elastic transformations. | |
32 cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) | |
33 if cmd is None: | |
34 imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) | |
35 cmd += ' -compose_raw_elastic' | |
36 # Target is sent before source. | |
37 cmd += ' %s' % target_image_path | |
38 cmd += ' %s' % source_image_path | |
39 cmd += ' %s' % target_raw_transformation_path | |
40 cmd += ' %s' % source_elastic_transformation_path | |
41 cmd += ' %s' % args.output | |
42 | |
43 # Compose the raw and elastic transformations into another raw transformation using bUnwarpJ. | |
44 proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) | |
45 rc = proc.wait() | |
46 if rc != 0: | |
47 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | |
48 imagej2_base_utils.stop_err( error_message ) | |
49 | |
50 imagej2_base_utils.cleanup_before_exit( tmp_dir ) |