abria / TeraStitcher

A tool for fast automatic 3D-stitching of teravoxel-sized microscopy images
http://abria.github.io/TeraStitcher/
Other
78 stars 32 forks source link

Terastitcher ignoring some xml fields? #63

Open chrisroat opened 4 years ago

chrisroat commented 4 years ago

I am running teraconverter on the command line with an XML containing the following stanza at the top:

    <stacks_dir value="."/>
    <ref_sys ref1="-2" ref2="1" ref3="3"/>
    <voxel_dims D="1.81" H="0.3" V="-0.3"/>
    <origin D="0.0" H="0.0" V="0.0"/>
    <mechanical_displacements H="611.4" V="-611.4"/>
    <dimensions stack_columns="4" stack_rows="4" stack_slices="-1"/>

The layout given by the file is below, based on the ROW and COL fields for each stack. Note that if I layout the images like this, it is not the right layout. I assume the ref_sys and voxel_dims above is indicating how to re-arrange and flip the tiles to get the correct pattern.

15 08 07 00
14 09 06 01
13 10 05 02
12 11 04 03

The images are 2048x2048. The xml files have ABS_H and ABS_V in multiples of 2028 (~1% overlap).

Terastitcher seems to fail (but does produce exit code 0 -- is that a bug?), and produce results with reliability of 0 and offset the files by 2038 (not 2028). In addition, the output file it generates is in the order shown above, not rotated/flipped.

Does terastitcher use the ref_sys and voxel_dims in the xml file?

iannellog commented 4 years ago

I apologize because it is likely I already asked this. In the import step are you using an externally generated xml or do you rely on the two-level hierarchy of folders organization so that TeraStitcher generates itself the file xml_import.xml?

In the former case the tag 'ref_sys' it is not used to re-arrange the tile matrix. The tile matrix is arranged according to the indices, folders names and file names specified in the attributes of the 'Stack' tags.Moreover, in this case 'ref_sys' should always be: ref1="1" ref2="2" ref3="3" and the quantities in tags 'voxel_dims' and 'mechanical_displacements' should be all positive.

In the latter case 'ref-sys' can be used to rotate and/or flip the tile matrix if vertical and horizontal dimensions are inverted in the two-level hierarchy of folders and/or physical coordinates have verse different from indices in the matrix of pixels.

Let me know if this can help.

chrisroat commented 4 years ago

It is the former -- an externally generated xml file. That is how I was able to copy in the XML shown above. So it sounds like the XML arguments are ignored in this case. Are command-line arguments similarly ignored?

If so, then based on the ref_sys shown, I can take care of the intended rotation by changing the row/col indices. This seems to make things look aligned (sometimes -- it is failing with 1% overlap on a 2k x 2k image). But I think there is a mirror flip I'd need to do after the fact, unless there is a way to ask terastitcher to do that.

iannellog commented 4 years ago

If an externally generated xml is used, most command line options are ignored.

With 1% overlap (about 20 voxels) it is likely that alignment computation fails (i.e. it has 0 reliability). Overlap has to be chosen based on typical mechanical errors of microscopy stages.

I do not understand your problem about flipping. If tiles indices are correctly specified in the xml no further transformation should be needed.

chrisroat commented 4 years ago

The flipping I'm referencing is the negative values for voxel_dims in the xml in my initial message. (This is different than the negative values in the ref values, which are part of the xy rotation that is needed.)

If the xml values are not used, and the command line options are ignored if xml is used, then should I conclude that I have to rewrite the xml to do the rotation and make ref_sys "standard", and then do the vertical reflection separately?

I believe the overlap ends up being much greater than 20 pixels -- more like 45-50. There looks to be enough overlap for some algorithms -- I can use FFT methods to do registration in the overlap region, and SIFT features seem to work in some cases. But perhaps terastitcher is doing something that needs more data.

iannellog commented 4 years ago

Please have a look to section 1.3 of the attached guide. Let me know if this answer your questions.

As to the tile overlap, when you generate the xml import file, the nominal positions of tile (attributes ABS_D, ABS_H, ABS_V of tag Stack) must reflect the nominal overlap between tiles to make the task of the align algorithm easier. For instance, if tiles are 2048x2048 with an overlap of 50 pixels both in V and in H, and first tile (ROW="0" COL="0") is placed at indices 0,0,0 (ABS_D="0" ABS_H="0" ABS_V="0"), the adjacent tile along H ((ROW="0" COL="1") must be initially placed at indices 0,1998,0 ((ABS_D="0" ABS_H="1998" ABS_V="0").

For what is concerned with the align algorithm, TeraStitcher currently uses a kind of normalized cross correlation, which does not perform well if the overlapping region contains quite uniform tissue. Indeed, it has been designed having in mind relatively sparse structures like cells or neurites. If is possible for you let me download a couple of tiles where the problem happens I an interest in understand if something can be done to achieve a better alignment.

TeraTools documentation (draft 190922).pdf

chrisroat commented 4 years ago

I should not have populated this issue with concerns about the overlap calculation until I'm sure I'm running the program correctly. I would like to stick to understanding how I can deal with my xml file.

Given the xml header shown above, where there is an xy rotation (via the ref_sys changes) and the vertical direction is flipped (via the voxel sizes), it is correct that I need to do the following:

Can you indicate what command-line options are ignored when using xml? I also believe my xml file has incorrect overlaps (the microscope seems to overlap a bit more than we configure it), so should I also update the ABS_H and ABS_V by to reflect this or can I pass in a command-line value?

iannellog commented 4 years ago

I apologize, but I fear that I did not understand which is your real problem, because I have got confused by your last comment. Could you please tell me as precisely as possible how your tiles are stored (directory structure and names, if tiles are series of 2D files or other format, names of these files, etc.) and which position each tile should have in the tile matrix in terms of row, column with indices starting from 0 for a correct reconstruction? If your test dataset is not too big you could also let me download it somehow. This way I can send you an example of how the xml should be written together with a detailed explanation.

chrisroat commented 4 years ago

I'll send you a private email with links to a subset of our data.