[Nipy-devel] Visualization code refactor
Tue Jan 12 10:26:32 CST 2010
On Mon, Jan 11, 2010 at 4:49 PM, Matthew Brett <firstname.lastname@example.org> wrote:
> Hi Mike,
>>> Absolutely. This is planned. I just wanted to sort out the simple cases
>>> first. The difficulty with the resampling is that a bounding box needs to
>>> calculated so as not to crop the image when doing the resampling. Nothing
>>> to hard to do, but I like to go slowly.
>> FYI, here is some code which is supposed to do that. I hope I handled
>> the bounding box issue correctly, as well as the localization of the
>> origin in the resampled image.
>> Check out "resample_to_ortho_grid"
> Thanks - was just about to type something in when your message came
> up, and you are doing more or less what I was thinking of. Oh,
> except the translations... Where you have:
> ortho_affine[:3,3] = -np.abs(T[:3,3])
> I think you need something like this (it's late here, please correct
> me if I'm wrong):
> world_exts = np.array(maximum_world_extents(img))
> box_extents = -np.diff(world_extents)
> new_dims = np.ceil(box_extents / vox_sizes)
> ortho_affine[:3,3] = world_exts[:,0]
> I noticed 'fix_analyze_image'; is it for fixing image (Analyze or
> otherwise) that are 4D with axis length 1 for the 4th dimension? Did
> you see drop_io_dim in nipy.core.reference.coordinate_map.drop_io_dim
> (no reason why you should, I think I should promote it to
> nipy.core.api) ?
> The use would be something like:
> img = nipy.load_image('somefile.nii')
> shape = img.shape
> if img.ndim == 4 and shape ==1:
> arr = np.asarray(img).reshape(shape[:3])
> cmap = drop_io_dim(img.coordmap)
> img = Image(arr, cmap)
> Won't you run into trouble using np.squeeze on images of shape
> [2,1,1,1] for example?
Thanks very much Matthew. Even sleepy, you're correct about the
translation, and the drop_io_dim is MUCH nicer than my hacks. Those
were some points I'd been worried about. Will fix later today.
> See you,
> Nipy-devel mailing list
More information about the Nipy-devel