Mercurial > repos > iuc > imagej2_bunwarpj_align
annotate jython_script.py @ 0:7a96d686d380 draft
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
| author | iuc |
|---|---|
| date | Tue, 09 Jun 2015 12:22:23 -0400 |
| parents | |
| children | be709f819445 |
| rev | line source |
|---|---|
|
0
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
1 import sys |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
2 import imagej2_base_utils |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
3 from ij import IJ |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
4 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
5 # Fiji Jython interpreter implements Python 2.5 which does not |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
6 # provide support for argparse. |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
7 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
8 if sys.argv[ -1 ].lower() in [ 'true' ]: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
9 mono = True |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
10 else: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
11 mono = False |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
12 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
13 if mono: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
14 # bUnwarpJ has been called with the -mono param. |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
15 source_tiff_path = sys.argv[ -4 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
16 source_datatype = sys.argv[ -3 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
17 source_path = sys.argv[ -2 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
18 else: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
19 source_tiff_path = sys.argv[ -7 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
20 source_datatype = sys.argv[ -6 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
21 source_path = sys.argv[ -5 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
22 target_tiff_path = sys.argv[ -4 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
23 target_datatype = sys.argv[ -3 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
24 target_path = sys.argv[ -2 ] |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
25 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
26 def convert_before_saving_as_tiff( registered_image ): |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
27 # The bUnwarpJ macro produces tiff image stacks consisting of 3 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
28 # slices which can be viewed in ImageJ. The 3 slices are:: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
29 # 1) the registered image, 2) the target image and 3) the black/white |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
30 # warp image. Galaxy supports only single-layered images, so we have |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
31 # to convert the image to something other than tiff so that slices are |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
32 # eliminated and we can then convert back to tiff for saving. This is |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
33 # kind of a hack - there is probably a way to do this without converting |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
34 # twice. I messed around with the the ImageJ getSlice() method, but |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
35 # couldn't get it to produce what is needed here. |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
36 tmp_dir = imagej2_base_utils.get_temp_dir() |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
37 tmp_out_png_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'png' ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
38 IJ.saveAs( registered_image, 'png', tmp_out_png_path ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
39 return IJ.openImage( tmp_out_png_path ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
40 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
41 # Save the Registered Source Image. |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
42 registered_source_image = IJ.openImage( source_tiff_path ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
43 if source_datatype == 'tiff': |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
44 registered_source_image = convert_before_saving_as_tiff( registered_source_image ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
45 IJ.saveAs( registered_source_image, source_datatype, source_path ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
46 |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
47 if not mono: |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
48 # Save the Registered Target Image. |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
49 registered_target_image = IJ.openImage( target_tiff_path ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
50 if target_datatype == 'tiff': |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
51 registered_target_image = convert_before_saving_as_tiff( registered_target_image ) |
|
7a96d686d380
planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
iuc
parents:
diff
changeset
|
52 IJ.saveAs( registered_target_image, target_datatype, target_path ) |
