Page 1 of 1

Exporting TIF image with single layer

PostPosted: Sun Jul 08, 2012 10:56 pm
by pjk
I'm using java client and I'm trying to export an image stored in Omero. I'm able to export the image but it has three gray-scale layers.
How do I convert the image to a single layer before exporting it, using omeroJava?
I had a look at the batch image export script. This script has options for 'export individual channels' and 'export merged image' but this not result in an merged TIF image

When I'm using Insight I'm able to use Save as function and that saves the image as a single layer image.

Thanks

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 8:08 am
by cxallan
You'll have to be a little more specific about the source data. How many channels does it have?

Code: Select all
$ bin/omero hql 'select count(c) from Channel c where c.pixels.id = 201'
Previous session expired for root on localhost:4064
Server: [localhost]
Username: [user]
Password:
Created session c5a73b32-f86b-4c47-baf0-ca57c86ffb1f (user@localhost:4064). Idle timeout: 10.0 min. Current group: user
# | Col1
---+------
0 | 1   
(1 row)

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 9:54 am
by pjk
cxallan wrote:You'll have to be a little more specific about the source data. How many channels does it have?

Code: Select all
$ bin/omero hql 'select count(c) from Channel c where c.pixels.id = 201'
Previous session expired for root on localhost:4064
Server: [localhost]
Username: [user]
Password:
Created session c5a73b32-f86b-4c47-baf0-ca57c86ffb1f (user@localhost:4064). Idle timeout: 10.0 min. Current group: user
# | Col1
---+------
0 | 1   
(1 row)


Hi,

Thanks for the fast response.
The number of channels is: 3 channels. Checked with above code

Peter

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 10:18 am
by wmoore
pjk wrote:I'm using java client and I'm trying to export an image stored in Omero. I'm able to export the image but it has three gray-scale layers.
How do I convert the image to a single layer before exporting it, using omeroJava?


So, you want your 3 channels merged into a single RGB image and saved as a tiff?

pjk wrote:I had a look at the batch image export script. This script has options for 'export individual channels' and 'export merged image' but this not result in an merged TIF image


If the Batch Image Export script had the option to save as TIFF (instead of png or jpeg), would that solve your problem?

pjk wrote:When I'm using Insight I'm able to use Save as function and that saves the image as a single layer image.
Thanks


When you say 'layer' do you mean Z-section or Channel? Insight can save a Z-section of multi-channel image as a single merged RGB tiff (see attachment).

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 11:22 am
by pjk
wmoore wrote:
pjk wrote:I'm using java client and I'm trying to export an image stored in Omero. I'm able to export the image but it has three gray-scale layers.
How do I convert the image to a single layer before exporting it, using omeroJava?


So, you want your 3 channels merged into a single RGB image and saved as a tiff?

pjk wrote:I had a look at the batch image export script. This script has options for 'export individual channels' and 'export merged image' but this not result in an merged TIF image


If the Batch Image Export script had the option to save as TIFF (instead of png or jpeg), would that solve your problem?

pjk wrote:When I'm using Insight I'm able to use Save as function and that saves the image as a single layer image.
Thanks


When you say 'layer' do you mean Z-section or Channel? Insight can save a Z-section of multi-channel image as a single merged RGB tiff (see attachment).



I have attached an example image which I import into Omero (size of 25kB). The code I use to export the image from Omero is following:

Code: Select all
   //generate tiff
        public static byte[] generateTif( long imageId ) throws Exception {
      ExporterPrx exporter = session.createExporter();
      exporter.addImage( imageId );
      
      long size = exporter.generateTiff();
      byte[] values = exporter.read( 0, (int) size );
      Logging.log( "Status ", "Image " + imageId + " generated" );
      exporter.close();
      return values;
   }

        //save as file
   public static void saveFile( String fullFilename, byte[] values ) {
      try {
         OutputStream output = null;
         try {
            output = new BufferedOutputStream(new FileOutputStream( fullFilename ));
            output.write(values);
         }
         catch( Exception e ) {
            System.out.println("Error writing file: " + e.toString() );
         }
         finally {
            System.out.println( "\tImage saved as " + fullFilename );
            output.close();
         }
      }
      catch(FileNotFoundException ex){
         ex.printStackTrace();
      }
      catch(IOException ex){
         ex.printStackTrace();
      }
   }


The output file has three gray scales layers. (I tried to attach it but the size is to big (760kB) ). Same result when I use batch export script with OME-TIFF format

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 11:35 am
by wmoore
OK, I now understand what you're doing currently, but I still don't know what you're trying to do, since you haven't answered ANY of my questions in my previous post. Please don't assume I know what you're trying to do.

Also, your image failed to attach (I don't see it anywhere). But that's OK - It's a 3-channel image, right (with Z-stack or T-stack?)

E.g. Do you want something like the TIFF I attached above?

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 12:14 pm
by pjk
wmoore wrote:OK, I now understand what you're doing currently, but I still don't know what you're trying to do, since you haven't answered ANY of my questions in my previous post. Please don't assume I know what you're trying to do.

Also, your image failed to attach (I don't see it anywhere). But that's OK - It's a 3-channel image, right (with Z-stack or T-stack?)


Trying again to attach the image:
testRotated (2).tif
testRotated (2).tif (24.62 KiB) Viewed 4704 times


So, you want your 3 channels merged into a single RGB image and saved as a tiff?

The image that I upload into Omero has no channels, no Z-stack, no T-stack, just a flat image. It seems to me that Omero generates the 3 channels when it stores it. When I export the image from Omero I want it back the same as my original which means that the three channels need to be merged into a single RGB image

If the Batch Image Export script had the option to save as TIFF (instead of png or jpeg), would that solve your problem?

The Batch Image Export already has the option to save as OME-TIFF format but this exports the image with the 3 gray scale layers. This doesn't solve my problem

When you say 'layer' do you mean Z-section or Channel? Insight can save a Z-section of multi-channel image as a single merged RGB tiff (see attachment).

With 'layers' I mend Channels. My images don't have Z-section or T-section.
I agree that when using Insight to save the image as TIFF it does merge the channels. But I'm not using Insight but I'm writing my own Java client.

Hope that this is more clear.

Re: Exporting TIF image with single layer

PostPosted: Mon Jul 09, 2012 12:39 pm
by wmoore
OK, thanks.

One thing that is confusing you here is the difference between OME-TIFF and .tiff. OME-TIFF is a multi-plane tiff format that represents (as closely as possible) what's in OMERO. So, if your image has multiple channels in OMERO, then it will have multiple channels in OME-TIFF.

So, you don't want to be using the Exporter Service to export the image, since that will be OME-TIFF.

You need to render the 3 channels and save as TIFF.

There is a rendering example for Java here: http://trac.openmicroscopy.org.uk/ome/w ... nderImages

I'm not a Java expert, so I can't tell you the best way to save a buffered image as .tiff. Maybe you know a nice way? Otherwise we could look / ask for how OMERO.insight saves as tiff.

Re: Exporting TIF image with single layer

PostPosted: Tue Jul 10, 2012 6:45 am
by pjk
Thanks for the explanation.

I'm not very familiar with the different image formats and I didn't realize that OME-TIFF is not TIFF

I going to dig into Insight 'save as' function.

Re: Exporting TIF image with single layer

PostPosted: Tue Jul 10, 2012 7:17 am
by cxallan
pjk wrote:Thanks for the explanation.

I'm not very familiar with the different image formats and I didn't realize that OME-TIFF is not TIFF

I going to dig into Insight 'save as' function.


OME-TIFF IS TIFF. Since OMERO's main use case is biological microscopy, channels are a first class concept. As far as OMERO is concerned an RGB image is just a three channel image and as part of the import process the red, green and blue "channels" are separated out. This is why when you export from OMERO into OME-TIFF you get three greyscale channels.