<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Curtis,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">It has been a while, but now I am coming back to the matter of creating OME TIFFs from within LabView. I am writing a very minimal ome-xml in the beginning of
 the file, and point the imagedescription of  each IFD to that position. What I get out is a BigTiff file, but the ome-part doesn’t work. The xmlvalidator tells me there is a premature end of file in any tiff I create (which I checked and it shouldn’t be the
 case), and importing the image via the BioFormats importer to Fiji shows the correct planes, but the dimensions CZT are collapsed into one third dimension. Also, the ome-xml that I get is not the one I write in the file.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I am attaching a small sample image – it should have dimension sizes x=6, y=5, c=2, z=3, t=4.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Would it be possible for you to have a look at it and see where my mistake is?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">   Heinrich<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> ctrueden.wisc@gmail.com [mailto:ctrueden.wisc@gmail.com]
<b>On Behalf Of </b>Curtis Rueden<br>
<b>Sent:</b> 6 April, 2015 6:33 PM<br>
<b>To:</b> Grabmayr, Heinrich<br>
<b>Cc:</b> OME-devel mailing list<br>
<b>Subject:</b> Re: [ome-devel] using LabView to write ome-tiff? with java4cpp?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Heinrich,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">> I see you have the exact same omexml metadata string for every IFD.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Nope, you only put the OME-XML string into the first IFD of each TIFF file. Not subsequent IFDs.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">> I was under the impression that you needed to specify the ZCT position<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> for every plane separately.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">You refer to the TiffData elements, right? If so, you do _not_ need a separate TiffData element per plane. You only need to define the mapping from IFD to ZCT coordinates in an unambiguous way. For full details, see:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://openmicroscopy.org/site/support/ome-model/ome-tiff/specification.html#the-tiffdata-element">http://openmicroscopy.org/site/support/ome-model/ome-tiff/specification.html#the-tiffdata-element</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">That said, you _would_ need to have one Plane element per plane if you want to include plane-specific metadata such as timings or plane-specific stage positions.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">> However, as it is the same string for every plane, couldn’t you just<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> write it once into the file and point at that position from every<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> IFD’s ImageDescription?<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Again, you do not need to populate the ImageDescription of any IFD other than the first.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hope that helps,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Curtis<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Mar 25, 2015 at 12:17 PM, Grabmayr, Heinrich <<a href="mailto:Heinrich.Grabmayr@ph.tum.de" target="_blank">Heinrich.Grabmayr@ph.tum.de</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Curtis</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks for this insight!</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I have one more question left regarding the WiscScan code. As I see you have the exact same omexml
 metadata string for every IFD. From my earlier work on this, I was under the impression that you needed to specify the ZCT position for every plane separately. But I just read that this is optional.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">However, as it is the same string for every plane, couldn’t you just write it once into the file and
 point at that position from every IFD’s ImageDescription?</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Cheers</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">   Heinrich</span><span style="color:#888888"><o:p></o:p></span></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">[Resending to the actual ome-devel list, since that address got mangled in the reply chain before.]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> Could you elaborate a bit on how you do the OmeXML injection into the<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> completed tiff? And why can't the stub description be longer than 4<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> chars?<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">According to the TIFF specification [1], an IFD Directory Entry has a type, a length and a value/offset. The length and value/offset are each 4 bytes. The clever thing is if the
 value fits into 4 bytes or less, it is inlined, but if the value is longer than 4 bytes, then those 4 bytes are treated as an offset into the file where the value is actually stored.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">So, you tell libtiff to write "xx" into the ImageDescription field, which will cause it to create a directory entry for ImageDescription when writing the TIFF header. Then later,
 after libtiff has closed out the TIFF file and considers it done, you can append your actual OME-XML string to the file, then seek back to the ImageDescription directory entry and change the length from 2 (which was the length of "xx") to your actual OME-XML
 string length, and change the _value_ field to an _offset_ to the previous file length (since that is now the byte offset of the OME-XML string due to the append).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I pasted the C++ code we use in WiscScan to do this. Find it here:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">   <a href="https://gist.github.com/ctrueden/6a91656fa9804d1a874a" target="_blank">https://gist.github.com/ctrueden/6a91656fa9804d1a874a</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">(In general that project is closed-source, so I cannot link you to the repository proper, unfortunately.)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">We also have Java code in Bio-Formats that does this, which you could study:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> 
<a href="https://github.com/openmicroscopy/bioformats/blob/v5.1.0-m4/components/formats-bsd/src/loci/formats/tiff/TiffSaver.java#L736-L866" target="_blank">
https://github.com/openmicroscopy/bioformats/blob/v5.1.0-m4/components/formats-bsd/src/loci/formats/tiff/TiffSaver.java#L736-L866</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">That code is actually a little more sophisticated that what I described above, since it does not _always_ overwrite the comment, depending on a few factors. But the overall approach is
 the same.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">One other thing: be careful of TIFF files over 4GB. Those need to be written a little differently, as BigTIFF, which uses 64-bit offsets. The libtiff library _does_ currently handle
 this properly, but the code I linked here would need to change to handle that case, too.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> For 64bit, I cannot find them, and I am not familiar (and don't have<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> the infractructure set up) for makefile processing. Might you have a<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">> libtiff for 64bit to send me or a link?<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Here is an SO question someone asked about that, with a self-answer using Visual Studio 2008:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> 
<a href="http://stackoverflow.com/q/13496980" target="_blank">http://stackoverflow.com/q/13496980</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Maybe you could do something similar with a more recent version MSVS, assuming you are using that tool chain?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Curtis<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">[1]
<a href="https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf" target="_blank">
https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf</a><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">On Thu, Mar 19, 2015 at 8:01 PM, Grabmayr, Heinrich <<a href="mailto:Heinrich.Grabmayr@ph.tum.de" target="_blank">Heinrich.Grabmayr@ph.tum.de</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi Curtis,<br>
<br>
Thanks very much for all these options. I think that 4) sounds most practicable for me now. Could you elaborate a bit on how you do the OmeXML injection into the completed tiff? And why can't the stub description be longer than 4 chars?<br>
Also, for my old project, I used the precompiled 32bit libtiff dll (I think I got it via GnuWin32). For 64bit, I cannot find them, and I am not familiar (and don't have the infractructure set up) for makefile processing. Might you have a libtiff for 64bit to
 send me or a link?<br>
<br>
Thanks, Heinrich<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><br>
><br>
> > I am currently developing a microscope that is controlled by a LabView<br>
> > program and generates a massive amount of data output. As I like<br>
> > ome-tiff, I'd like to save my images in that format.<br>
><br>
> Your major options are:<br>
><br>
> 1) Wait for the native Bio-Formats C++ implementation [1], slated for OME<br>
> version 5.1 (and subject to change until 5.2).<br>
>  - Pro: No more need for Java on the acquisition machine!<br>
>  - Con: Non-trivial to build and deploy due to required dependencies.<br>
>  - Con: Not actually ready yet. ;-)<br>
><br>
> 2) Use the Bio-Formats C++ bindings [2], available now.<br>
>  - Pro: Provides access to the entire Bio-Formats API.<br>
>  - Con: Non-trivial to build and deploy due to required dependencies.<br>
><br>
> 3) Use an interprocess solution such as:<br>
>  - Subimager [3] -- used by CellProfiler<br>
>  - A pipes-based bridge [4] -- used by ITK<br>
>  - Pro: As fast as in-process solutions, with fewer dependencies.<br>
>  - Con: Requires some coding to conform to your project's requirements.<br>
><br>
> 4) Write TIFF using libtiff, injecting your own OME-XML at the end. General<br>
> approach:<br>
><br>
> - Write a stub ImageDescription comment (four chars or less; e.g., "xx")<br>
> using libtiff.<br>
><br>
> - Generate your own OME-XML, maybe using a C++ XML library of your<br>
> choice.<br>
><br>
> - Inject the XML string by appending it to the TIFF (fast), then seeking to the<br>
> ImageDescription offset and length fields of the TIFF and updating them<br>
> accordingly (also fast).<br>
><br>
> - This approach avoids needing to rewrite the entire TIFF file just to add<br>
> OME-XML later. This is how we do it in WiscScan, although we do use the<br>
> Bio-Formats C++ bindings (see option 2 above) for actually building the<br>
> OME-XML string itself using the Bio-Formats MetadataStore API.<br>
><br>
> Further reading:<br>
> <a href="http://loci.wisc.edu/software/interfacing-non-java-code" target="_blank">
http://loci.wisc.edu/software/interfacing-non-java-code</a><br>
><br>
> Regards,<br>
> Curtis<br>
><br>
> [1] <a href="http://openmicroscopy.org/site/support/bio-" target="_blank">http://openmicroscopy.org/site/support/bio-</a><br>
> formats5.1/developers/cpp.html<br>
> [2] <a href="http://openmicroscopy.org/site/support/bio-formats5.0/developers/c-" target="_blank">
http://openmicroscopy.org/site/support/bio-formats5.0/developers/c-</a><br>
> bindings.html<br>
> [3] <a href="https://github.com/CellProfiler/subimager" target="_blank">https://github.com/CellProfiler/subimager</a><br>
> [4] <a href="https://github.com/scifio/scifio-itk-bridge" target="_blank">https://github.com/scifio/scifio-itk-bridge</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>