[Nipy-devel] Visualization code refactor

M Trumpis mtrumpis@berkeley....
Tue Jan 12 18:28:59 CST 2010

On Mon, Jan 11, 2010 at 4:49 PM, Matthew Brett <matthew.brett@gmail.com> 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.
>> https://cirl.berkeley.edu/trac/browser/bic/scratch/nm/nutmeg/vis/image_slicer.py
>> 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[3] ==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 Matthew.. I wrote earlier saying you were right on all counts
(but sent through the wrong email again). My examples of resampling
code are changed, with other fixes too, and checked in now.

Gael, with respect to the your viz-refactor code in
/nipy/neurospin/viz/coord_tools.py, I tried your approach to finding
the full boundary of a box (array) in a new space, as in
get_bounds(shape, affine). I found that the correct way to do this is
to map each 8 corners of the box into the new space, and then find the
maxima/minima in each output axis.


> See you,
> Matthew
> _______________________________________________
> Nipy-devel mailing list
> Nipy-devel@neuroimaging.scipy.org
> http://mail.scipy.org/mailman/listinfo/nipy-devel

More information about the Nipy-devel mailing list