annotate jython_utils.py @ 7:be709f819445 draft

planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
author iuc
date Fri, 19 Jun 2015 16:57:16 -0400
parents
children 8a14f00234e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
1 import imagej2_base_utils
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
2 from ij import IJ
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
3
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
4 def convert_before_saving_as_tiff( image_plus ):
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
5 # The bUnwarpJ plug-in produces TIFF image stacks consisting of 3
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
6 # slices which can be viewed in ImageJ. The 3 slices are: 1) the
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
7 # registered image, 2) the target image and 3) the black/white warp
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
8 # image. When running bUnwarpJ from the command line (as these
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
9 # Galaxy wrappers do) the initial call to IJ.openImage() (to open the
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
10 # registered source and target images produced by bUnwarpJ) in the
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
11 # tool's jython_script.py returns an ImagePlus object with a single
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
12 # slice which is the "generally undesired" slice 3 discussed above.
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
13 # However, a call to IJ.saveAs() will convert the single-slice TIFF
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
14 # into a 3-slice TIFF image stack (as described above) if the selected
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
15 # format for saving is TIFF. Galaxy supports only single-layered
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
16 # images, so to work around this behavior, we have to convert the
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
17 # image to something other than TIFF so that slices are eliminated.
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
18 # We can then convert back to TIFF for saving. There might be a way
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
19 # to do this without converting twice, but I spent a lot of time looking
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
20 # and I have yet to discover it.
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
21 tmp_dir = imagej2_base_utils.get_temp_dir()
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
22 tmp_out_png_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, 'png' )
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
23 IJ.saveAs( image_plus, 'png', tmp_out_png_path )
be709f819445 planemo upload commit 7195716d447effc5bc32154279de4b84369eccdb-dirty
iuc
parents:
diff changeset
24 return IJ.openImage( tmp_out_png_path )