[Insight-developers] Y axis inversion during slice extraction

Dženan Zukić dzenanz at gmail.com
Mon Jul 12 12:11:17 EDT 2010


Thanks Kent, it helps a lot!

Some time ago I was asking exactly for this filter! Take a look here:
http://www.itk.org/pipermail/insight-users/2010-April/036516.html

<http://www.itk.org/pipermail/insight-users/2010-April/036516.html>I have a
question, though: Why do you set exactly the identity matrix as a resulting
direction? Medical scanners usually have something very close to 1 for
direction vectors (e.g. 0.998445 0.05456 0.00123 instead of 1 0 0).

One solution would be to have a tolerance parameter, an angle of rotation
between the actual coordinate system orientation and desired one.
Theoretically, this angle could go up to 45 degrees, but practically it is
usually just a few degrees. Setting tolerance to 5 degrees would allow up to
5 degrees of deviation, otherwise destroy information in direction cosines
and set exactly the desired orientation.

The other solution (a better one) would be to have a bool parameter
RealignDirectionCosines (or something similar), and depending on it's value
either realign the direction matrix as close to desired orientation as
possible, or replace it with desired orientation (thus destroying some
info).

Even without these improvements, I can use the mentioned filter to generate
my PNG slices.

Regards,
Dženan

2010/7/12 kent williams <norman-k-williams at uiowa.edu>

> You're right, PNG images have no concept of coordinate system.  You have to
> look at the direction cosines, and re-orient your image such that the
> resulting PNG images are correctly oriented.
>
> That is why we at Iowa wrote the itk::OrientImageFilter. This deals
> specifically with re-arranging the voxel data so that the index space is
> organized to match a particular anatomical orientation.  It is NOT the
> right
> filter to deal with off-axis orientations -- i.e. dir cosines with
> component
> values other than 1, -1, or 0. In fact it will change the direction cosines
> to the nearest axis-aligned coordinate system, destroying the actual
> orientation.
>
> It is the perfect tool to permute the axes and flip axis directions in
> order
> to get images to display properly.
>
> In dealing with VTK display code we use the following template function to
> reorient images for display:
>
> #include <itkOrientImageFilter.h>
> #include "itkSpatialOrientation.h"
>
> template <class ImageType>
> typename ImageType::Pointer
> OrientImage(typename ImageType::ConstPointer &inputImage,
>            itk::SpatialOrientation::ValidCoordinateOrientationFlags orient)
> {
>  typename itk::OrientImageFilter<ImageType, ImageType>::Pointer orienter
>    = itk::OrientImageFilter<ImageType, ImageType>::New();
>
>  orienter->SetDesiredCoordinateOrientation(orient);
>  orienter->UseImageDirectionOn();
>  orienter->SetInput(inputImage);
>  orienter->Update();
>  typename ImageType::Pointer returnval
>    = orienter->GetOutput();
>  return returnval;
> }
>
> for example:
>  typedef itk::Image<unsigned char,3> ImageType;
>  ImageType::Pointer reOrientedImage
>    = itkUtil::OrientImage<ImageType>(constMask,
>
> itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI);
>
> The orientation code RAI (which stands for Right,Anterior,Inferior) gives
> the anatomical position of the first voxel in index space.  RAI is, in ITK
> terms, the identity rotation -- i.e. dir cosines of [1 0 0] [0 1 0] [0 0 1]
> -- images oriented RAI display properly with VTK.
>
> So your task is to use this filter to permute axes/swap axes direction of
> your image so that the PNG images 'look correct'  -- I'd start with RAI and
> go from there.  It's useful to use an unambiguous anatomical image to
> experiment with, something like:
>
> http://www.cornwarning.com/xfer/avg152T1_LR_nifti.nii.gz
>
> Hope that helps.
>
> On 7/12/10 9:33 AM, "Dženan Zukić" <dzenanz at gmail.com> wrote:
>
> > Hi everyone,
> >
> > in the attached simple code for slice extraction. I am using similar code
> in
> > my segmentation tool. The problem is that 2D slices, which I display
> using Qt,
> > look flipped (Y_axis_current.png
> > <
> http://i274.photobucket.com/albums/jj262/dzenanz/OnlineImageHosting/Y_axis_cu
> > rrent.png> ). Flipping slices either vertically or horizontally resolves
> the
> > discrepancy between 2D slices and 3D visualization (Y_axis_inverted.png
> > <
> http://i274.photobucket.com/albums/jj262/dzenanz/OnlineImageHosting/Y_axis_in
> > verted.png> ).
> >
> > I believe the problem arises somewhere due to origin of coordinate system
> > (lower left vs upper
> >
> left). \InsightToolkit-3.18.0\Code\BasicFilters\itkExtractImageFilter.txx,
> > line 206 clearly states that direction cosines are not taken care of. PNG
> > image writer does not take into account coordinate system conventions
> > (conclusion based on a glimpse into code).
> >
> > Am I doing something wrong? If no, how do you deal with this?
> >
> > Regards,
> > Dženan
> >
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://kitware.com/products/protraining.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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100712/4637ab28/attachment.htm>


More information about the Insight-developers mailing list