Mercurial > repos > imgteam > imagej2_find_maxima
annotate imagej2_watershed_binary_jython_script.py @ 3:4409f9eb9433 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 15:58:30 +0000 |
parents | 6a07f71806bb |
children |
rev | line source |
---|---|
0
29b39f5b0e69
"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
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
2 |
0
29b39f5b0e69
"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 |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
4 |
29b39f5b0e69
"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 |
29b39f5b0e69
"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
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
7 input = sys.argv[-4] |
2
6a07f71806bb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
imgteam
parents:
1
diff
changeset
|
8 black_background = sys.argv[-3] == "yes" |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
9 tmp_output_path = sys.argv[-2] |
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
10 output_datatype = sys.argv[-1] |
0
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
11 |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
12 # Open the input image file. |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
13 input_image_plus = IJ.openImage(input) |
0
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
14 |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
15 # Create a copy of the image. |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
16 input_image_plus_copy = input_image_plus.duplicate() |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
17 image_processor_copy = input_image_plus_copy.getProcessor() |
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
18 |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
19 # Set binary options. |
2
6a07f71806bb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
imgteam
parents:
1
diff
changeset
|
20 options = ["edm=Overwrite", "iterations=1", "count=1"] |
6a07f71806bb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
imgteam
parents:
1
diff
changeset
|
21 if black_background: |
6a07f71806bb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
imgteam
parents:
1
diff
changeset
|
22 options.append("black") |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
23 options = " ".join(options) |
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
24 IJ.run(input_image_plus_copy, "Options...", options) |
0
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
25 |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
26 # Convert image to binary if necessary. |
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
27 if not image_processor_copy.isBinary(): |
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
28 # Convert the image to binary grayscale. |
e2622ebb5ce4
"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, "Make Binary", "") |
0
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
30 |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
31 # Run the command. |
3
4409f9eb9433
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
imgteam
parents:
2
diff
changeset
|
32 IJ.run(input_image_plus_copy, "Watershed", "stack") |
0
29b39f5b0e69
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
imgteam
parents:
diff
changeset
|
33 |
1
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
34 # Save the ImagePlus object as a new image. |
e2622ebb5ce4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 2afb24f3c81d625312186750a714d702363012b5"
imgteam
parents:
0
diff
changeset
|
35 IJ.saveAs(input_image_plus_copy, output_datatype, tmp_output_path) |