[Insight-developers] NIfTI, DiffusionTensor3D Pixels, SymmetricSecondRankTensor

Tom Vercauteren tom.vercauteren at gmail.com
Thu Mar 12 04:11:51 EDT 2009


Hi Kent,

Using two loops should make it right. It would avoid constructing an
ordering vector.

for i=0:N
  for j=i:N
    NIfTIPixel[j*(j+1)/2+i] = ITKPixel[j+i*(2N-i-1)/2];
  end
end

You might want to really check these indexes though. Anyhow it should
be along these lines.

IIRC for a lower triangular matrix M stored in C syle order and i>=j you have
  M(i,j) = M[ j + i(i+1)/2 ]

Similarly for an upper triangular matrix M stored in C syle order and
j>=i you have
  M(i,j) = M[ j + i(2N-i-1)/2 ]

Here since you have symmetric matrices you also use the fact that
M(i,j) = M(j,i) to get things right when j>=i instead of i>=j or i>=j
instead of j>=i.

Hope this helps,
Tom

On Wed, Mar 11, 2009 at 21:08, kent williams
<norman-k-williams at uiowa.edu> wrote:
> I've managed to get myself confused and throw myself on the mercy of the
> more mathematically inclined.
>
> Luke logged this bug http://public.kitware.com/Bug/view.php?id=7485 a while
> back.  In essence the problem is that ITK and NIfTI disagree about the order
> of values when storing a DiffusionTensor3D, and one presumes
> SymmetricSecondRankTensor as well. ITK stores upper-triangular and NIfTI
> stores lower-triangular.
>
> In the case of DiffusionTensor3D, a symmetric 3x3 matrix, the ordering for a
> matrix
>
> A B C
> B D E is A B C D E F for ITK, and A B D C E F for NIfTI.
> C E F
>
> Given how the NIfTI filter works when it's copying pixels to and from ITK
> images, I handle this with an ordering array.  In other words I have an
> array
>    int niftiorder[9] = { 0,1,3,2,4,5,6 };
> and in essence, NIfTIPixel[i] = ITKPixel[order[i]];
>
> That's good for DiffusionTensor3D, but the general case of
> SymmetricSecondRankTensor is baffling me. For a 4x4 symmetric matrix
>  int niftiorder[10] = { 0, 1, 4, 2, 5, 7, 3, 6, 8, 9 };
>
> and 5x5 is even crazier.
>  int niftiorder[15] = { 0, 1, 5, 2, 6, 9, 3, 7, 10, 2, 4, 8, 11, 13, 14 };
>
> So I'm not seeing how I would go about deriving this ordering.  I.e. I don't
> know what general purpose code would handle re-ordering the scalars from an
> upper triangular to a lower triangular or vice verse.
>
> Does anyone have a suggestion on how to go about this?
>
> And while I'm on the subject, why is the VNL Symmetric Matrix lower
> triangular, yet ITK is upper triangular?
>
>
>
>
>
> Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>


More information about the Insight-developers mailing list