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