Mercurial > repos > iuc > imagej2_analyze_skeleton
comparison jython_script.py @ 2:9631aab7da53 draft
planemo upload commit 18df9e67efd4adafcde4eb9b62cd815e4afe9733-dirty
| author | iuc |
|---|---|
| date | Wed, 26 Aug 2015 14:36:10 -0400 |
| parents | dd8e4e000d2f |
| children |
comparison
equal
deleted
inserted
replaced
| 1:dd8e4e000d2f | 2:9631aab7da53 |
|---|---|
| 1 import jython_utils | 1 import jython_utils |
| 2 import math | 2 import math |
| 3 import sys | 3 import sys |
| 4 from ij import IJ | 4 from ij import IJ |
| 5 from ij import ImagePlus | |
| 6 from skeleton_analysis import AnalyzeSkeleton_ | 5 from skeleton_analysis import AnalyzeSkeleton_ |
| 7 | 6 |
| 8 BASIC_NAMES = [ 'Branches', 'Junctions', 'End-point Voxels', | 7 BASIC_NAMES = [ 'Branches', 'Junctions', 'End-point Voxels', |
| 9 'Junction Voxels', 'Slab Voxels', 'Average branch length', | 8 'Junction Voxels', 'Slab Voxels', 'Average branch length', |
| 10 'Triple Points', 'Quadruple Points', 'Maximum Branch Length' ] | 9 'Triple Points', 'Quadruple Points', 'Maximum Branch Length' ] |
| 11 DETAIL_NAMES = [ 'Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x', | 10 DETAIL_NAMES = [ 'Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x', |
| 12 'V2 y', 'V2 z', 'Euclidean distance' ] | 11 'V2 y', 'V2 z', 'Euclidean distance' ] |
| 13 VALID_IMAGE_TYPES = [ ImagePlus.GRAY8 ] | |
| 14 | |
| 15 def asbool( val ): | |
| 16 return val == 'yes' | |
| 17 | 12 |
| 18 def get_euclidean_distance( vertex1, vertex2 ): | 13 def get_euclidean_distance( vertex1, vertex2 ): |
| 19 x1, y1, z1 = get_points( vertex1 ) | 14 x1, y1, z1 = get_points( vertex1 ) |
| 20 x2, y2, z2 = get_points( vertex2 ) | 15 x2, y2, z2 = get_points( vertex2 ) |
| 21 return math.sqrt( math.pow( ( x2 - x1 ), 2 ) + | 16 return math.sqrt( math.pow( ( x2 - x1 ), 2 ) + |
| 53 for index in range( num_trees ): | 48 for index in range( num_trees ): |
| 54 outf.write( '%d%s' % ( result.getBranches()[ index ], sep ) ) | 49 outf.write( '%d%s' % ( result.getBranches()[ index ], sep ) ) |
| 55 outf.write( '%d%s' % ( result.getJunctions()[ index ], sep ) ) | 50 outf.write( '%d%s' % ( result.getJunctions()[ index ], sep ) ) |
| 56 outf.write( '%d%s' % ( result.getEndPoints()[ index ], sep ) ) | 51 outf.write( '%d%s' % ( result.getEndPoints()[ index ], sep ) ) |
| 57 outf.write( '%d%s' % ( result.getJunctionVoxels()[ index ], sep ) ) | 52 outf.write( '%d%s' % ( result.getJunctionVoxels()[ index ], sep ) ) |
| 58 outf.write( '%d%s' % ( len( result.getListOfSlabVoxels() ), sep ) ) | 53 outf.write( '%d%s' % ( result.getSlabs()[ index ], sep ) ) |
| 59 outf.write( '%.3f%s' % ( result.getAverageBranchLength()[ index ], sep ) ) | 54 outf.write( '%.3f%s' % ( result.getAverageBranchLength()[ index ], sep ) ) |
| 60 outf.write( '%d%s' % ( result.getTriples()[ index ], sep ) ) | 55 outf.write( '%d%s' % ( result.getTriples()[ index ], sep ) ) |
| 61 outf.write( '%d%s' % ( result.getQuadruples()[ index ], sep ) ) | 56 outf.write( '%d%s' % ( result.getQuadruples()[ index ], sep ) ) |
| 62 outf.write( '%.3f' % result.getMaximumBranchLength()[ index ] ) | 57 outf.write( '%.3f' % result.getMaximumBranchLength()[ index ] ) |
| 63 if calculate_largest_shortest_path: | 58 if calculate_largest_shortest_path: |
| 99 outf.write( '\n' ) | 94 outf.write( '\n' ) |
| 100 outf.close() | 95 outf.close() |
| 101 | 96 |
| 102 # Fiji Jython interpreter implements Python 2.5 which does not | 97 # Fiji Jython interpreter implements Python 2.5 which does not |
| 103 # provide support for argparse. | 98 # provide support for argparse. |
| 104 error_log = sys.argv[ -7 ] | 99 error_log = sys.argv[ -8 ] |
| 105 input = sys.argv[ -6 ] | 100 input = sys.argv[ -7 ] |
| 101 black_background = jython_utils.asbool( sys.argv[ -6 ] ) | |
| 106 prune_cycle_method = sys.argv[ -5 ] | 102 prune_cycle_method = sys.argv[ -5 ] |
| 107 prune_ends = asbool( sys.argv[ -4 ] ) | 103 prune_ends = jython_utils.asbool( sys.argv[ -4 ] ) |
| 108 calculate_largest_shortest_path = asbool( sys.argv[ -3 ] ) | 104 calculate_largest_shortest_path = jython_utils.asbool( sys.argv[ -3 ] ) |
| 109 if calculate_largest_shortest_path: | 105 if calculate_largest_shortest_path: |
| 110 BASIC_NAMES.extend( [ 'Longest Shortest Path', 'spx', 'spy', 'spz' ] ) | 106 BASIC_NAMES.extend( [ 'Longest Shortest Path', 'spx', 'spy', 'spz' ] ) |
| 111 DETAIL_NAMES.extend( [ ' ', ' ', ' ', ' ' ] ) | 107 DETAIL_NAMES.extend( [ ' ', ' ', ' ', ' ' ] ) |
| 112 show_detailed_info = asbool( sys.argv[ -2 ] ) | 108 show_detailed_info = jython_utils.asbool( sys.argv[ -2 ] ) |
| 113 output = sys.argv[ -1 ] | 109 output = sys.argv[ -1 ] |
| 114 | 110 |
| 115 # Open the input image file. | 111 # Open the input image file. |
| 116 input_image_plus = IJ.openImage( input ) | 112 input_image_plus = IJ.openImage( input ) |
| 117 bit_depth = input_image_plus.getBitDepth() | |
| 118 image_type = input_image_plus.getType() | |
| 119 | 113 |
| 120 # Create a copy of the image. | 114 # Create a copy of the image. |
| 121 input_image_plus_copy = input_image_plus.createImagePlus() | 115 input_image_plus_copy = input_image_plus.duplicate() |
| 122 image_processor_copy = input_image_plus.getProcessor().duplicate() | 116 image_processor_copy = input_image_plus_copy.getProcessor() |
| 123 input_image_plus_copy.setProcessor( "iCopy", image_processor_copy ) | |
| 124 | 117 |
| 125 try: | 118 try: |
| 126 if image_type not in VALID_IMAGE_TYPES: | 119 # Set binary options. |
| 127 # Convert the image to binary grayscale. | 120 options = jython_utils.get_binary_options( black_background=black_background ) |
| 128 IJ.run( input_image_plus_copy, "Make Binary","iterations=1 count=1 edm=Overwrite do=Nothing" ) | 121 IJ.run( input_image_plus_copy, "Options...", options ) |
| 122 | |
| 123 # Convert image to binary if necessary. | |
| 124 if not image_processor_copy.isBinary(): | |
| 125 IJ.run( input_image_plus_copy, "Make Binary", "" ) | |
| 126 | |
| 129 # Run AnalyzeSkeleton | 127 # Run AnalyzeSkeleton |
| 130 analyze_skeleton = AnalyzeSkeleton_() | 128 analyze_skeleton = AnalyzeSkeleton_() |
| 131 analyze_skeleton.setup( "", input_image_plus_copy ) | 129 analyze_skeleton.setup( "", input_image_plus_copy ) |
| 132 if prune_cycle_method == 'none': | 130 if prune_cycle_method == 'none': |
| 133 prune_index = analyze_skeleton.NONE | 131 prune_index = analyze_skeleton.NONE |
