daviddmc / NeSVoR

NeSVoR is a package for GPU-accelerated slice-to-volume reconstruction.
MIT License
72 stars 17 forks source link

nesvor segment-stack issue when using it standalone #19

Open GerardMJuan opened 8 months ago

GerardMJuan commented 8 months ago

Using "nesvor segment-stack" standalone command (https://nesvor.readthedocs.io/en/latest/commands/segment-stack.html) generates masks with different sform/qform and origin, which, in turn, makes the "nesvor reconstruct" fail with the error:

    2024-03-13 15:55:26 [INFO] Data loading starts ...
    2024-03-13 15:55:26 [INFO] loading stacks
    2024-03-13 15:55:26 [ERROR] Unhandled exception:
    Traceback (most recent call last):
      File "/usr/local/bin/nesvor", line 33, in <module>
        sys.exit(load_entry_point('nesvor', 'console_scripts', 'nesvor')())
      File "/usr/local/NeSVoR/nesvor/cli/main.py", line 23, in main
        run(args)
      File "/usr/local/NeSVoR/nesvor/cli/main.py", line 48, in run
        getattr(commands, command_class)(args).main()
      File "/usr/local/NeSVoR/nesvor/cli/commands.py", line 75, in main
        self.exec()
      File "/usr/local/NeSVoR/nesvor/cli/commands.py", line 160, in exec
        input_dict = self.preprocess()
      File "/usr/local/NeSVoR/nesvor/cli/commands.py", line 132, in preprocess
        input_dict, self.args = inputs(self.args)
      File "/usr/local/NeSVoR/nesvor/cli/io.py", line 24, in inputs
        stack = load_stack(
      File "/usr/local/NeSVoR/nesvor/image/image.py", line 651, in load_stack
        raise Exception(
    Exception: Error: the sizes/resolutions/affine transformations of the input stack and stack mask do not match!

Note that this does not happen when using just "nesvor reconstruct" without the previously computed masks. The error only happens when: 1) using nesvor segment-stack to generate masks and 2) using those masks as input to nesvor reconstruct.

I have replicated this with various stacks, but unsure if this is a problem in the qform/sform configuration of this specific data or a general thing. This is the header information and the origin of the original stack:

image And this is the one from the corresponding mask generated by nesvor segment-stack:

image This is bothersome if we want to use the various functions included in the library to run every step at a time.

A quick fix that work for me is just to copy the header from the mask to the original stack, and invert the x axis. This seems to make everything work, but it is dirty.

I believe the problem comes from the transformations on the affine matrix that nesvor performs when loading/saving a nifti file, so if you can take a look at it, that would be great. Thanks!