users > Origins, Bounding boxes and voxel conventions
Showing 1-3 of 3 posts
Nov 16, 2009 11:11 PM | Greg Jefferis
Origins, Bounding boxes and voxel conventions
Reprising an email conversation
> Imagine I have a 2x2x2 voxel data set with the voxal dimensions of 4mm.
>
>>> --target-grid
>>> Define target grid for reformating as Nx,Ny,Nz:dX,dY,dZ[:Ox,Oy,Oz]
>>> (dims:pixel:origin)
>>>
> Does the origin 0,0,0 refer to the centre of the first voxel or the outer
> corner? Similarly, if I wanted to calculate a horizontal reflection should
> I be x -> 2-x or 4-x?
>
The way this works is as follows: for the given grid, you have pixel
coordinates
(0,0,0), (4,0,0), (0,4,0), (4,4,0), ....
These are the locations at which reformat (when called without explicit
coordinate transformation) will sample the floating image. The data in
the floating image are located at grid points that are defined
analogously. That means, if your floating image were the same as your
target (reference) image, then you would get a 1:1 mapping of the
floating onto the target pixels.
Regarding reflection: please do not use negative pixel size and non-zero
origin to get a reflection. That will not work. Instead, use a rigid
transformation.
The parameters of that transformation (in your example) should be:
scale x, y, z = -1, -1, -1
translation x, y, z = 4, 4, 4
Hope this clarifies things.
BTW -- please try to post these questions in the NITRC / CMTK forum ;)
TR
> Imagine I have a 2x2x2 voxel data set with the voxal dimensions of 4mm.
>
>>> --target-grid
>>> Define target grid for reformating as Nx,Ny,Nz:dX,dY,dZ[:Ox,Oy,Oz]
>>> (dims:pixel:origin)
>>>
> Does the origin 0,0,0 refer to the centre of the first voxel or the outer
> corner? Similarly, if I wanted to calculate a horizontal reflection should
> I be x -> 2-x or 4-x?
>
The way this works is as follows: for the given grid, you have pixel
coordinates
(0,0,0), (4,0,0), (0,4,0), (4,4,0), ....
These are the locations at which reformat (when called without explicit
coordinate transformation) will sample the floating image. The data in
the floating image are located at grid points that are defined
analogously. That means, if your floating image were the same as your
target (reference) image, then you would get a 1:1 mapping of the
floating onto the target pixels.
Regarding reflection: please do not use negative pixel size and non-zero
origin to get a reflection. That will not work. Instead, use a rigid
transformation.
The parameters of that transformation (in your example) should be:
scale x, y, z = -1, -1, -1
translation x, y, z = 4, 4, 4
Hope this clarifies things.
BTW -- please try to post these questions in the NITRC / CMTK forum ;)
TR
Nov 17, 2009 12:11 AM | Greg Jefferis
RE: Origins, Bounding boxes and voxel convent
Regarding reflection, I have always used rigid transformations in
the past to achieve that. eg:
Sx,y,z = -1, 1, 1 (why -1, -1, -1 above?)
Tx,y,z = 4, 4, 4
But my question was motivated by occasions where
1) I need to apply the same transformation to an independent model.
eg a traced neuron with nodes at arbitrary points with subvoxel accuracy
2) I need to downsample an existing grid.
What happens when I downsample from eg dim 20,20,20 data to dim 2,2,2 data with voxel dimension 8 x 8 x 8 mm? Does my origin effectively change?
Greg.
Sx,y,z = -1, 1, 1 (why -1, -1, -1 above?)
Tx,y,z = 4, 4, 4
But my question was motivated by occasions where
1) I need to apply the same transformation to an independent model.
eg a traced neuron with nodes at arbitrary points with subvoxel accuracy
2) I need to downsample an existing grid.
What happens when I downsample from eg dim 20,20,20 data to dim 2,2,2 data with voxel dimension 8 x 8 x 8 mm? Does my origin effectively change?
Greg.
Nov 17, 2009 12:11 AM | Torsten Rohlfing
RE: Origins, Bounding boxes and voxel convent
> Regarding reflection, I have always used rigid transformations
in the past to achieve that. eg:
>
> Sx,y,z = -1, 1, 1 (why -1, -1, -1 above?)
> Tx,y,z = 4, 4, 4
Sorry, I thought of a reflection in x,y, and z. In case of x only, that of course becomes
Sx,y,z = -1, 1, 1
Tx,y,z = 4, 0, 0
> But my question was motivated by occasions where
>
> 1) I need to apply the same transformation to an independent model.
In that case, why don't you use the convert tool with its "--flip-x" option. (There are also "--flip-y" and "--flip-z", just in case).
> 2) I need to downsample an existing grid.
>
> What happens when I downsample from eg dim 20,20,20 data to dim 2,2,2 data with voxel dimension 8 x 8 x 8 mm? Does my origin effectively change?
I guess what you mean is: SHOULD your origin change. If you do not give reformatx a non-zero origin, then it won't apply one, so by definition, the offset won't change.
What you need to keep in mind first of all is that reformat really does a downsampling in the purest sense of the word: it simply samples the input data at given locations. It does not average the input pixels that contribute to each output pixel. Actually, that's not quite correct: depending on your interpolation kernel it will "average" the pixels in the kernel neighborhood, but that really shouldn't be called averaging.
Now, if you want to average pixels locally when you resample, then you should again use the "convert" tool, this time with the "--downsample" option. You can provide either one or three downsample factors (if you provide one, it will downsample all dimensions with the same factor).
In this case, the offset of the resulting image will indeed be different from the input image's offset. Say, you sample a 1mm isotropic 4x4x4 volume (i.e.g, FOV = 3x3x3 mm) by a factor of 2. The result should be a 2x2x2 volume with 2mm isotropic pixel size, FOV = 2x2x2 mm, and offset = (1,1,1) mm. Now whether the offset will always make it into the output file, that depends on whether the file format supports offsets. There's a good chance for Nrrd, but for Analyze that wouldn't happen.
I hope this explanation makes sense and you find this behaviour reasonable.
>
> Sx,y,z = -1, 1, 1 (why -1, -1, -1 above?)
> Tx,y,z = 4, 4, 4
Sorry, I thought of a reflection in x,y, and z. In case of x only, that of course becomes
Sx,y,z = -1, 1, 1
Tx,y,z = 4, 0, 0
> But my question was motivated by occasions where
>
> 1) I need to apply the same transformation to an independent model.
In that case, why don't you use the convert tool with its "--flip-x" option. (There are also "--flip-y" and "--flip-z", just in case).
> 2) I need to downsample an existing grid.
>
> What happens when I downsample from eg dim 20,20,20 data to dim 2,2,2 data with voxel dimension 8 x 8 x 8 mm? Does my origin effectively change?
I guess what you mean is: SHOULD your origin change. If you do not give reformatx a non-zero origin, then it won't apply one, so by definition, the offset won't change.
What you need to keep in mind first of all is that reformat really does a downsampling in the purest sense of the word: it simply samples the input data at given locations. It does not average the input pixels that contribute to each output pixel. Actually, that's not quite correct: depending on your interpolation kernel it will "average" the pixels in the kernel neighborhood, but that really shouldn't be called averaging.
Now, if you want to average pixels locally when you resample, then you should again use the "convert" tool, this time with the "--downsample" option. You can provide either one or three downsample factors (if you provide one, it will downsample all dimensions with the same factor).
In this case, the offset of the resulting image will indeed be different from the input image's offset. Say, you sample a 1mm isotropic 4x4x4 volume (i.e.g, FOV = 3x3x3 mm) by a factor of 2. The result should be a 2x2x2 volume with 2mm isotropic pixel size, FOV = 2x2x2 mm, and offset = (1,1,1) mm. Now whether the offset will always make it into the output file, that depends on whether the file format supports offsets. There's a good chance for Nrrd, but for Analyze that wouldn't happen.
I hope this explanation makes sense and you find this behaviour reasonable.