Mercurial > repos > bgruening > imagej2_crop
annotate imagej2_binary_to_edm_jython_script.py @ 0:018144807556 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
author | bgruening |
---|---|
date | Tue, 24 Sep 2024 17:12:52 +0000 |
parents | |
children |
rev | line source |
---|---|
0
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
1 import sys |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
2 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
3 from ij import IJ |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
4 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
5 # Fiji Jython interpreter implements Python 2.5 which does not |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
6 # provide support for argparse. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
7 input_file = sys.argv[-7] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
8 iterations = int(sys.argv[-6]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
9 count = int(sys.argv[-5]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
10 black_background = sys.argv[-4] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
11 pad_edges_when_eroding = sys.argv[-3] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
12 output_filename = sys.argv[-2] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
13 output_datatype = sys.argv[-1] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
14 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
15 # Open the input image file. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
16 input_image_plus = IJ.openImage(input_file) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
17 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
18 # Create a copy of the image. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
19 input_image_plus_copy = input_image_plus.duplicate() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
20 image_processor_copy = input_image_plus_copy.getProcessor() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
21 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
22 # Set binary options. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
23 options_list = ["edm=Overwrite", "iterations=%d" % iterations, "count=%d" % count] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
24 if black_background: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
25 options_list.append("black") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
26 if pad_edges_when_eroding: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
27 options_list.append("pad") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
28 options = " ".join(options_list) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
29 IJ.run(input_image_plus_copy, "Options...", options) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
30 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
31 # Convert image to binary if necessary. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
32 if not image_processor_copy.isBinary(): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
33 # Convert the image to binary grayscale. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
34 IJ.run(input_image_plus_copy, "Make Binary", "") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
35 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
36 # Run the command. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
37 IJ.run(input_image_plus_copy, "Distance Map", "") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
38 # Save the ImagePlus object as a new image. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
39 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename) |