[Insight-developers] Y axis inversion during slice extraction
kent williams
norman-k-williams at uiowa.edu
Mon Jul 12 11:45:34 EDT 2010
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
More information about the Insight-developers
mailing list