Page 1 of 1

how to tie up multiple images into one OME-TIFF?

PostPosted: Mon Jun 07, 2010 3:30 pm
by bhcho
Hi all,

I'd like to tie up multiple images into one OME-TIFF file, such as multiple channel image and multiple time-series image.
In this case, it should be able to handle the meta data correctly.
for instance, for multiple channel image (protein channel and DNA channel for the same cell).
almost every the meta information is the same, except the channel names (and/or the channel settings).

Is there any sample java code to do this?
(especially how to handle the "savebytes" function fro loci.formats.IFormatWriter.)

And I think there are lots of discrepancies between the actual library and the javadoc for loci_tools.jar.
for example, the "setPixelsSizeX" method from "loci.formats.meta.IMetadta", the javadoc says it needs two integer arguments, but in the code I need three arcuments to compile correctly.
I'm currently looking at http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/.
Am I looking at an old version of javadoc or something?

Thanks in advance.

BK

Re: how to tie up multiple images into one OME-TIFF?

PostPosted: Mon Jun 07, 2010 7:57 pm
by mlinkert
I'd like to tie up multiple images into one OME-TIFF file, such as multiple channel image and multiple time-series image.


A simple example using the 4.1.1 API, assuming that you have already created an IMetadata object named 'metadata':

Code: Select all
metadata.createRoot();
// populate metadata for the first image (multi-channel)
metadata.setPixelsBigEndian(Boolean.TRUE, 0, 0);
metadata.setPixelsDimensionOrder("XYCZT", 0, 0);
metadata.setPixelsPixelType("uint8", 0, 0);
metadata.setPixelsSizeX(512, 0, 0);
metadata.setPixelsSizeY(512, 0, 0);
metadata.setPixelsSizeC(3, 0, 0);
metadata.setPixelsSizeZ(1, 0, 0);
metadata.setPixelsSizeT(1, 0, 0);
// populate metadata for the second image (timelapse)
metadata.setPixelsBigEndian(Boolean.TRUE, 0, 0);
metadata.setPixelsDimensionOrder("XYCZT", 0, 0);
metadata.setPixelsPixelType("uint8", 0, 0);
metadata.setPixelsSizeX(512, 0, 0);
metadata.setPixelsSizeY(512, 0, 0);
metadata.setPixelsSizeC(1, 0, 0);
metadata.setPixelsSizeZ(1, 0, 0);
metadata.setPixelsSizeT(5, 0, 0);

// initialize the writer
ImageWriter writer = new ImageWriter();
writer.setMetadataRetrieve(metadata);
writer.setId("/path/to/output/file.ome.tiff");
for (int image=0; image<metadata.getImageCount(); image++) {
  int sizeZ = metadata.getPixelsSizeZ(image, 0);
  int sizeC = metadata.getPixelsSizeC(image, 0);
  int sizeT = metadata.getPixelsSizeT(image, 0);
  int planeCount = sizeZ * sizeC * sizeT;
  for (int plane=0; plane<planeCount; plane++) {
    byte[] pixelBuffer = new byte[]; // replace this with your own image retrieval code
    boolean lastInSeries = plane == planeCount - 1;
    writer.saveBytes(pixelBuffer, image, lastInSeries, image == metadata.getImageCount() - 1 && lastInSeries);
  }
}
writer.close();


Note that in the upcoming 4.2 release, the saveBytes signature used above will be deprecated. Updated example code will be available on the Bio-Formats website once 4.2 is released.

And I think there are lots of discrepancies between the actual library and the javadoc for loci_tools.jar.
for example, the "setPixelsSizeX" method from "loci.formats.meta.IMetadta", the javadoc says it needs two integer arguments, but in the code I need three arcuments to compile correctly.
I'm currently looking at http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/.


Those Javadocs correspond to the latest trunk build, and as such will not necessarily correspond to the API for any given stable release. We do not currently have pre-built Javadocs for the stable releases; however, you can easily generate them yourself. To generate the docs for the 4.1.1 release, make sure that you have Apache Ant and Subversion installed, and then do this:

Code: Select all
svn co https://skyking.microscopy.wisc.edu/svn/java/tags/loci-tools-4.1.1/ bio-formats-4.1.1/
cd bio-formats-4.1.1/
ant docs

Re: how to tie up multiple images into one OME-TIFF?

PostPosted: Wed Jun 09, 2010 3:29 pm
by bhcho
Thanks.

And I think the code needs to be modified a little bit for the argument of image index. (especially for the second image)

Code: Select all
metadata.createRoot();
// populate metadata for the first image (multi-channel)
metadata.setPixelsBigEndian(Boolean.TRUE, 0, 0);
metadata.setPixelsDimensionOrder("XYCZT", 0, 0);
metadata.setPixelsPixelType("uint8", 0, 0);
metadata.setPixelsSizeX(512, 0, 0);
metadata.setPixelsSizeY(512, 0, 0);
metadata.setPixelsSizeC(3, 0, 0);
metadata.setPixelsSizeZ(1, 0, 0);
metadata.setPixelsSizeT(1, 0, 0);
// populate metadata for the second image (timelapse)
metadata.setPixelsBigEndian(Boolean.TRUE, 1, 0);
metadata.setPixelsDimensionOrder("XYCZT", 1, 0);
metadata.setPixelsPixelType("uint8", 1, 0);
metadata.setPixelsSizeX(512, 1, 0);
metadata.setPixelsSizeY(512, 1, 0);
metadata.setPixelsSizeC(1, 1, 0);
metadata.setPixelsSizeZ(1, 1, 0);
metadata.setPixelsSizeT(5, 1, 0);

// initialize the writer
ImageWriter writer = new ImageWriter();
writer.setMetadataRetrieve(metadata);
writer.setId("/path/to/output/file.ome.tiff");
for (int image=0; image<metadata.getImageCount(); image++) {
  int sizeZ = metadata.getPixelsSizeZ(image, 0);
  int sizeC = metadata.getPixelsSizeC(image, 0);
  int sizeT = metadata.getPixelsSizeT(image, 0);
  int planeCount = sizeZ * sizeC * sizeT;
  for (int plane=0; plane<planeCount; plane++) {
    byte[] pixelBuffer = new byte[]; // replace this with your own image retrieval code
    boolean lastInSeries = plane == planeCount - 1;
    writer.saveBytes(pixelBuffer, image, lastInSeries, image == metadata.getImageCount() - 1 && lastInSeries);
  }
}
writer.close();


Anyway, I did what you said.
svn co https://skyking.microscopy.wisc.edu/svn ... ols-4.1.1/ bio-formats-4.1.1/
cd bio-formats-4.1.1/
ant docs


But I dont know where I can find the javadocs.
Right now, I need some API java functions which set the Name, Color, Wavelength, ... for each channel.
Those setChannelName and setChannelColor does not work with my loci_tools.jar library (which I downloaded from a Trunk Build several weeks ago).
Could you tell me about those API functions?

Re: how to tie up multiple images into one OME-TIFF?

PostPosted: Wed Jun 09, 2010 8:04 pm
by mlinkert
And I think the code needs to be modified a little bit for the argument of image index. (especially for the second image)


You're right; the image index should have been 1 for the second image.

But I dont know where I can find the javadocs.


They will be in the build/docs/api/ subdirectory of your SVN checkout after 'ant docs' has completed.

Right now, I need some API java functions which set the Name, Color, Wavelength, ... for each channel.
Those setChannelName and setChannelColor does not work with my loci_tools.jar library (which I downloaded from a Trunk Build several weeks ago).


setChannelName and setChannelColor were previously:

setLogicalChannelName(String name, int imageIndex, int channelIndex) and
setChannelComponentColorDomain(String color, int imageIndex, int channelIndex, int channelComponentIndex)

Note that 'channelComponentIndex' must be less than the value passed to setLogicalChannelSamplesPerPixel.

Re: how to tie up multiple images into one OME-TIFF?

PostPosted: Wed Jun 09, 2010 8:27 pm
by bhcho
Thanks Mellisa,

Could you please tell me more about the arguments of
setChannelComponentColorDomain(String color, int imageIndex, int channelIndex, int channelComponentIndex)

Especially, If I want to set the color as green, red, blue, or yellow, how to set the "String color"?
And what's the "int channelComponentIndex"?



And for the javadoc,
svn co https://skyking.microscopy.wisc.edu/svn ... ols-4.1.1/ bio-formats-4.1.1/
cd bio-formats-4.1.1/
ant docs


it was okay in the "svn" part, but after I do "ant docs", I got
"BUILD FAILED",
/bio-formats-4.1.1/build.xml:796: Basedir /home/bhcho/bio-formats-4.1.1/components/visbio does not exist

Could you tell me what's wrong with me?

Many Thanks,