Skip to content

add (projection) z stitching to nabu

payno requested to merge add_z_stitching into master

Context

Add application to handle stitching in nabu. First use case is to handle the the z_stitching in pre processing. Because the simplest is to not to work on volume as we need to include some metadata that will be added to the NXtomo from this PR or associated PR.

must be integrated before:

to fix

  • in config file: <bound method Enum.values of <enum 'StitchingType'>>
  • start thinking about tilt issue (for post processing to)
  • handle case were stitching height is a ratio (post pone with % for example ? )
  • add an example of a configuration file in the documentation

TODO

  • add volume bounding box when save it so it can be used back for stitching
  • add low level function to stich frames together
  • add entry points
    • nabu-stitching-config: CLI to generate a configuration file for stitching (for now by default for a pre-processing z-stitching)
    • nabu-stitching: CLI to execute the stitching configuration file and generate a NXtomo.
  • add documentation
    • general one
    • notebooks to ease processing, understand behavior and debug
  • add tests
  • speed up ?
    • read a bunch of frame instead of one frame by one
    • write into several hdf5 and create a virtual data set from it ?: is it worth it ? for now this does not looks like a bottleneck (on a 13' stitch we spend ~1' writing).
    • profile execution and discuss about it.
      • result from 13/06/22 execution: profile_out.prof (can be read with snakeviz profile_out.prof) -> bottleneck is the horizontal shift (skip it if 0...). This part could be done in parallel or / and we could use something faster than scipy.shift
      • second result when no shift needs to be done: profile_out.prof
  • do we want to add an option "avoid_copy" to create virtual dataset if x shift == 0 ? Could really improve speed and reduce memory print if done should be in another PR anyway
  • use real_pixel_size instead of magnification + pixel_size when possible

special case handled:

  • x and / or y frame shift
  • inverted rotation angle from one scan to the other.

How to

create a configuration file

nabu-stitching-config [-h] [--stitching_type STITCHING_TYPE] [--level LEVEL] [--output OUTPUT]

The idea is to have as close as possible configuration files between preprocessed z-stitch (on projections) and post-processed z-stitch (on volume)

call a z-stitch

nabu-stitching [-h] [--loglevel LOGLEVEL] input_file

extra

info: mostly tested on the STYLO and WGN_01_0000_P_119_0065_D_138 datasets

generated documentation is temporary available here: http://www.edna-site.org/pub/doc/tmp_doc_stitching/

this PR raises #307

screenshot

output file

image

example of a complete configuration file

[stitching]
# section dedicated to stich parameters

# Which type of stitching to do. Must be in <bound method Enum.values of <enum 'StitchingType'>>
type = z-preproc
# Overlap area between two scans in pixel. Can be an int or a list of int. If 'auto' will try to deduce it from the magnification and z_translations value
vertical_overlap_area_in_px = auto
# Height of the stich to apply on the overlap region. If set to 'auto' then will take the largest one possible (equal overlap height)
stitching_height_in_px = auto
# Policy to apply to compute the overlap area. Must be in ('mean', 'cosinus weights', 'linear weights', 'closest').
stitching_strategy = cosinus weights
# relative shift between two set of frames or volumes.
x_relative_shifts_in_px = 0
# options to find shift automatically
auto_relative_shifts_params = do_slice_index_correlation_from_slice=middle;x_cross_correlation_function=None;y_cross_correlation_function=skimage


[output]
# section dedicated to output parameters

# HDF5 file to save the generated NXtomo (.nx extension recommanded).
location = /tmp_14_days/payno/test_stitching/stylo/stitched.nx
# File prefix. Optional, by default it is inferred from the scanned dataset.
file_prefix = 
# Output file format. Available are: hdf5, tiff, jp2, edf
file_format = hdf5
# What to do in the case where the output file exists.
# By default, the output data is never overwritten and the process is interrupted if the file already exists.
# Set this option to 1 if you want to overwrite the output files.
overwrite_results = 1
# output NXtomo version to use for saving stitched NXtomo. If not provided will take the latest version available.
nexus_version = 


[inputs]
# section dedicated to inputs

# Dataset to stitch together. Must be volume for z-preproc and NXtomo for z-postproc
input_dataset = (
	"hdf5:scan:/tmp_14_days/payno/z_serie/STYLO/SYS01S101/SYS01S101_SYS01S101_3scans_0000.nx?file_path=entry0000",
	"hdf5:scan:/tmp_14_days/payno/z_serie/STYLO/SYS01S101/SYS01S101_SYS01S101_3scans_0001.nx?file_path=entry0001",
	"hdf5:scan:/tmp_14_days/payno/z_serie/STYLO/SYS01S101/SYS01S101_SYS01S101_3scans_0002.nx?file_path=entry0002",
)
Edited by payno

Merge request reports