-
Notifications
You must be signed in to change notification settings - Fork 260
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
BUG: wrong origin location in orthoview, update OrthoSlicer3D._set_position in viewers.py #1319
Conversation
wrong indices to original data leading to weird selection of voxels for weird affine transforms and weird volumes this bug is also related to strange behavior with special acquisition, for example with small animal settings such as rodents leading to wrong location of origin (0,0,0) with image.orthoview()
19ebfa8
to
47ea032
Compare
Thanks for this! Would it be possible to get a test that clearly demonstrates the error before and is fixed after? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1319 +/- ##
=======================================
Coverage 95.34% 95.35%
=======================================
Files 207 207
Lines 29481 29504 +23
Branches 4981 4982 +1
=======================================
+ Hits 28110 28133 +23
Misses 930 930
Partials 441 441 ☔ View full report in Codecov by Sentry. |
Hi Chris, import matplotlib
matplotlib.use('Qt5Agg') # or any functional backend.
import matplotlib.pyplot as plt
import nibabel as nib
import numpy as np
data1 = np.random.rand(10, 20, 40)
data1[5, 10, :] = 0
data1[5, :, 30] = 0
data1[:, 10, 30] = 0
aff1 = np.array([[1, 0, 0, -5], [0, 0, 1, -30], [0, 1, 0, -10], [0, 0, 0, 1]])
o1 = nib.viewers.OrthoSlicer3D(data1, aff1)
o1.show() This creates a 3D array containing random values, with more elements in the third dimension than in the others dimensions. using OrthoSlicer3D the referential in green should override the black lines in the volume. Fig.1It seems to have other bugs in the OrthoSlicer3D that I try to fix. This will be proposed in other pull requests. |
Hi @gjpcbecq! I'm going to try to turn your MRE into a test. Apologies for taking so long to get back to this. I'm commenting here to try to pressure myself to spend some time on it. :-) |
Okay, so I've had a go at reproducing this, and your fix resolves the initial placement at the origin, but if you attempt to click around to other locations with the mouse, you no longer go the place you click. Removing your patch makes the mouse work. So I think there's something more fundamentally wrong here. It's possible that we just need to do the inverse of this in the |
Thank you Chris for working on this. |
correct a bug with image.orthoview() from class nibabel.viewers.OrthoSlicer3D
There is a wrong selection of indices from original data using the inverse affine transform, leading to weird selection of voxels
This bug is also related to strange behavior with special acquisition, for example with small animal settings such as rodents where PA and IS axis are transposed (LSA system), leading to wrong location of origin (0,0,0) with image.orthoview()
For example, this small example will generate wrong localization of the referential with the main code and will result in good representation with the proposed correction: