-
Notifications
You must be signed in to change notification settings - Fork 163
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
resample_image_to_target / images_to_matrix #641
Comments
That call is actually OK, I think. If interpolator_oldoptions = ("linear", "nearestNeighbor", "gaussian", "cosineWindowedSinc", "bSpline")
if isinstance(interp_type, int):
interpolator = interpolator_oldoptions[interp_type] Otherwise, I agree that there should be a way to catch errors on library calls. Perhaps when calling |
But yes that test looks incorrect: import ants
import numpy as np
img = ants.image_read(ants.get_data('r16'))
imglist = [img.clone(),img.clone(),img.clone()]
s = [65]*img.dimension
mask2 = ants.from_numpy(np.random.randn(*s))
mask2 = mask2 > mask2.mean()
imgmat = ants.images_to_matrix(imglist, mask=mask2)
print(imgmat.sum()) # equals 0, but shouldnt I guess? And tracing it more specifically: import ants
import numpy as np
img = ants.image_read(ants.get_data('r16'))
s = [65]*img.dimension
mask = ants.from_numpy(np.random.randn(*s))
mask = mask > mask.mean()
img2 = ants.resample_image_to_target(img, mask, 2)
print(img2.sum()) # all zero |
Thanks! Can't fix now but can look at it later |
No prob.. think it has to do with spacing. I removed that |
One more thought before I have to run, should this ANTsPy/ants/registration/apply_transforms.py Line 121 in cd2a4ac
be a clone of fixed, rather than moving? Since the output will be written to an image of dimension fixed. Not sure if it matters, seems like it would have been noticed by now if so. Just worried about these intermittent access violations in light of issues like #590 |
Answering my own question, it's fine to have
because the pointer will be reassigned to point to the output image created inside the C++ code, and it doesn't matter if the output image has more or less pixels. |
I also noticed resample_image_to_target (and ants.apply_transforms) will reset the output data type to the target type. So
I think this shouldn't cause the memory error because the values should get cast to the matrix type, but it is different to how the CLI behaves. Needs documenting if nothing else |
Fixed by #642 |
I looked again at the code vs the main apply_transforms, and one thing resample doesn't do is clone the input images to float, so I changed this in #647 |
Tracking down the Windows access exceptions
This line is implicated
ANTsPy/ants/utils/matrix_image.py
Line 151 in cd2a4ac
This call looks wrong to me, it doesn't match the function
ANTsPy/ants/ops/resample_image.py
Line 79 in cd2a4ac
also within resample_image.py, I don't think this will work
ANTsPy/ants/ops/resample_image.py
Line 157 in cd2a4ac
So why doesn't this fail everywhere? It's a problem I've come across before, where library functions are called and passed references to clones of the input. If the library function doesn't write to its output image for any reason, the cloned input is returned unmodified. I'd appreciate any ideas of how to address this problem systematically, because I think it can be the source of many quiet bugs.
The text was updated successfully, but these errors were encountered: