We're Hiring!

Exporting TIF image with single layer

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Exporting TIF image with single layer

Postby pjk » Sun Jul 08, 2012 10:56 pm

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
pjk
 
Posts: 16
Joined: Wed May 09, 2012 1:35 am

Re: Exporting TIF image with single layer

Postby cxallan » Mon Jul 09, 2012 8:08 am

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)
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: Exporting TIF image with single layer

Postby pjk » Mon Jul 09, 2012 9:54 am

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
pjk
 
Posts: 16
Joined: Wed May 09, 2012 1:35 am

Re: Exporting TIF image with single layer

Postby wmoore » Mon Jul 09, 2012 10:18 am

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).
Attachments
CSFVg-INr01_R3D.tif
Tiff from Insight
CSFVg-INr01_R3D.tif (770.25 KiB) Viewed 4717 times
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Exporting TIF image with single layer

Postby pjk » Mon Jul 09, 2012 11:22 am

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
pjk
 
Posts: 16
Joined: Wed May 09, 2012 1:35 am

Re: Exporting TIF image with single layer

Postby wmoore » Mon Jul 09, 2012 11:35 am

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?
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Exporting TIF image with single layer

Postby pjk » Mon Jul 09, 2012 12:14 pm

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 4713 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.
pjk
 
Posts: 16
Joined: Wed May 09, 2012 1:35 am

Re: Exporting TIF image with single layer

Postby wmoore » Mon Jul 09, 2012 12:39 pm

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.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Exporting TIF image with single layer

Postby pjk » Tue Jul 10, 2012 6:45 am

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.
pjk
 
Posts: 16
Joined: Wed May 09, 2012 1:35 am

Re: Exporting TIF image with single layer

Postby cxallan » Tue Jul 10, 2012 7:17 am

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.
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest