Images return images
Images, when sliced, should always return images.
Proposal for reslicing interface.
from numpy import asarray from image import resample, Image, coordinates from algorithms.register import register, SimpleRegister from image.resamplers import resample, BsplineResampler img1 = load('an_image.nii') assert img1.shape == (64,64,40) img2 = load('another_image.nii') assert img2.shape == (128,128,64) img1_slice1 = img1[1] assert img1_slice1.shape == (64,64) # An image always returns an image, even when this seems # pretty dumb assert(isinstance(img[0,0,0], Image)) # In fact usually, to get the data point, you'd do asarray(img)[0,0,0] # Which has annoying consequences for delayed resampling, see below # This returns the world to world transform for img1 to img2 img1_img2_transform = register(moving=img1, static=img2) # Can also use class interface registrator = SimpleRegister() img1_img2_transform = registrator.register(moving=img1, static=img2) # Note method kw to resample convenience function img1_resampled = resample(sourceimage=img1, destination=img2.transform, transform=img1_img2_transform, method='linear') # Can also use class interface resampler = BsplineResampler(order=3) img1_resampled = resampler.resample(sourceimage=img1, destination=img2.transform, transform=img1_img2_transform) # This will raise an error if img1_to_img2 is not invertible img2_resampled = resample(sourceimage=img2, destination=img1.transform, transform=img1_img2_transform.inverse) # If you give the wrong transform direction, it should raise an error img2_resampled = resample(sourceimage=img2, destination=img1.transform, transform=img1_img2_transform) assert img1_resampled.shape == (128,128,64) # Actual resampling done here array1 = asarray(img1_resampled) img1_coregistered_slice1 = img1_resampled[1] # Force reslicing img1_reslice.update() # Here are the annoying consequences of img[0]->Image # for delayed resampling (see above) asarray(img)[0,0,0] # Causes resampling of the whole image # And you'd usually do point_value = resample_values(sourceimage=img1, transform=img1_img2_transform, coordinates([0 0 0])) # This syntax made unnecessary by delayed resampling img1_coregistered_slice1 = resample(sourceimage=img1, transform=img1_img2_transform, outputindices=[1]) assert img1_coregistered_slice1.shape == (128,128)
