Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on using empirical noise scans with NORDIC #4

Open
tsalo opened this issue Oct 1, 2024 · 8 comments
Open

Documentation on using empirical noise scans with NORDIC #4

tsalo opened this issue Oct 1, 2024 · 8 comments

Comments

@tsalo
Copy link
Contributor

tsalo commented Oct 1, 2024

The actual math goes way over my head, but it doesn't seem like patch-denoising includes a way to use noise scans with the NORDIC denoiser. The documentation mentions "pre processing the image and dividing it by an externally available g-map". Does that mean that calculating the g-map is outside the scope of this package?

@paquiteau
Copy link
Owner

Hi again,

If you look closely at the NORDIC MATLAB code, they have routines to estimate the noise level per patch in the absence of g-map (I tried to reproduce this in Nordic_Raw in patch-denoise).

G-map estimation goes beyond the scope of this package indeed, but our team is tackling this challenge in another repository with https://github.com/mbertrait/ggrappa (cc @mbertrait)

@paquiteau
Copy link
Owner

Actually, the maths are not that hard. I will soon write my thesis, and patch-denoise will be a chapter of it, I will take this opportunity to detail the maths more (and add it here in the documentation)

@tsalo
Copy link
Contributor Author

tsalo commented Oct 2, 2024

That would be amazing. For context, I would really like to get NORDIC added to fMRIPrep, but using the MATLAB version would dramatically increase the size of the container per @bpinsard, and there are also license and code quality issues. Being able to use the noise scans within patch-denoise or having solid documentation so we could write an interface to do that on fMRIPrep's side would be awesome.

@paquiteau
Copy link
Owner

Turns out, I have some code in place to estimate the noise statistics from noisy scans 🥳 !

https://github.com/paquiteau/patch-denoising/blob/master/src/patch_denoise/space_time/utils.py#L206

And even better, I have nipype bindings (which fMRIprep uses IIRC) for it

https://github.com/paquiteau/patch-denoising/blob/master/src/patch_denoise/bindings/nipype.py

For the documentation, I have no ETA yet, but contributions are welcome to improve it ;)

https://paquiteau.github.io/patch-denoising/denoisers.html

@bpinsard
Copy link

bpinsard commented Oct 2, 2024

Amazing, thanks for the nice package! I am glad that this interesting MRI filtering technique won't die as an old, barely-readable MATLAB code with restrictive license.

@tsalo
Copy link
Contributor Author

tsalo commented Dec 21, 2024

I've been reviewing the MATLAB code in detail and it turns out that the measured noise is a single scalar, not something calculated on a patch-wise basis. Also, in the MATLAB code they only use the first noise scan. It's clearly a bug, but the author doesn't think it merits fixing.

@paquiteau
Copy link
Owner

Hi @tsalo, that's a good catch, this might explain the discrepency between the result of the python vs MATLAB implementation (note that in the benchmark paper, I used the MATLAB NORDIC for fair comparison 1). The NORDIC authors are still using their implementation as is (and apparently with good results 2), so maybe the Python version should also use this "bug".

Footnotes

  1. It was a PITA to make MATLAB, Nipype and NORDIC to work together smoothly: https://github.com/paquiteau/retino-pypeline/blob/master/src/retino_pypeline/interfaces/nordic.py

  2. https://mitp.silverchair-cdn.com/mitp/content_public/journal/imag/jam/10.1162_imag_a_00426/2/imag_a_00426.pdf?Expires=1738316200&Signature=QTQ5ZQtxBjopglXJYziw1tBv2EkodPPlRvAhXUcpp~0ArnI-zVOGPo7CdWik4kwYRwpS6Hasdkk0IU-lwgUStqRFG0DhuazrrIdbS0YtjCn-sQ747B64pDcni2WxO~Y-wwsnpl7hNckBVVRJQGtd1KkRvuUjhcCFM36jMczibQMv4-r6GBGGwcktgbqugE47Wb1QE7xuqq9gWBNUIyo5EYo8ADFsoFzQfgu94J-CGdoEjOuQZp0EWEncaqb0MfmfRji8jDfNnWqbiPu3goqJmvHBc45-Egq3PEu9D0UDgXZUZhVYmbafSVunq7iEvyVaHqhSKcmzEBHv9lpiZVWRWQ__&Key-Pair-Id=APKAIE5G5CRDK6RD3PGA

@tsalo
Copy link
Contributor Author

tsalo commented Dec 30, 2024

I don't think the bug (using just the first noise volume) will have much of an effect, but it is definitely a bug that should be fixed. Even if only so that people aren't acquiring multiple noise volumes for no reason.

I have a line-by-line Python translation that seems to work pretty well. I still need to write unit tests for it, but I'm optimistic. My ultimate goal is to incorporate it into dwidenoise, but I'd love to do what I can to bring the patch-denoising implementation in line with the MATLAB implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants