I’m trying to rotate a volume and then get the corresponding (rotated) array. I thought hardening and then using util.arrayFromVolume would do it, but it doesn’t (if I transform further, get again the array and compare, obtain the same result). My code is as follows:
a = getTransformedVolume()
# modify the global transformNode
b = getTransformedVolume()
(a == b).all() # expect to get False, but it's actually True
How can I achieve this? Let me further note that I’m actually interested in the 2D array corresponding to a particular (transformed) slice, not actually the whole transformed volume, but was trying this approach because I couldn’t find a way to do that either. Thanks in advance for your support!
If you harden a linear transform it only changes the IJKToRAS matrix, so the pixels you get in the numpy array will be unchanged. You’ll need to resample the data through the transform to do this. There are several ways to do this, but calling this CLI might be the easiest, or there might be a convenience method I’m not thinking of at the moment.
OK. If I understand correctly, I should see that module under “all modules”, but I actually don’t have that sub-menu… I don’t have either one that, if I remember correctly, should be called “examples”, where I should be able to see the modules that the module wizard creates for me to code. What should I do to see those?
It sounds like you are using an older version of slicer. We suggest updating to the most recent version and using the script repository and programming tutorials to get comfortable with the system to simplify the process of developing your own code.
So, I tried version 5.3.0 and my UI looks identical. I realized though that I can use the module finder and I was able to resample the volume using the “Resample Scalar/Vector/DWI Volume” module that you suggested. I just looked at the code, but alas it’s C++ (not python). Any hint as to how I could invoke the module using python? Thanks again!