[Insight-users] TriangleMeshToBinaryImageFilter with direction cosines different from identity

Luis Ibanez luis.ibanez at kitware.com
Wed May 26 15:30:35 EDT 2010


Hi Dženan,

You seem to have identified a real bug.

Could you please log a bug entry at:
http://public.kitware.com/Bug/my_view_page.php

As you already pointed out, it looks like the source of the
error is the manual computation of conversions between
indexes and point coordinates in lines 442-446:

    point = points.Value();

    newpoint[0] = (point[0]-m_Origin[0]) * invspacing[0];
    newpoint[1] = (point[1]-m_Origin[1]) * invspacing[1];
    newpoint[2] = (point[2]-m_Origin[2]) * invspacing[2];

which should have been something like:

    image->TransformPhysicalPointToIndex( point, newpoint );

or even better, we should rename the variable "newpoint"
as "newindex" to be

    image->TransformPhysicalPointToIndex( point, newpoint );


Also, the filter has settings for the Origin and Spacing of the
output image, but not for its direction.

It needs something like

     itkSetMacro(Direction, DirectionType);

in the header file,

and then in lines 194 in the .txx file

    OutputImage->SetLargestPossibleRegion( region);     //
    OutputImage->SetBufferedRegion( region );           // set the region
    OutputImage->SetRequestedRegion( region );          //
    OutputImage->SetSpacing(m_Spacing);         // set spacing
    OutputImage->SetOrigin(m_Origin);   //   and origin

we should add

    OutputImage->SetDirection(m_Direction);


----



Would you be interested in adopting this bug ?

http://www.itk.org/Wiki/ITK_10th_Anniversary_Activities/Adopt-A-Bug_1.0

The adoption process
includes full CVS write access to ITK      :-)



If so, we will be happy to assist you in the
process of fixing it.


    Regards,


        Luis


------------------
2010/5/26 Dženan Zukić <dzenanz at gmail.com>:
> Update: by setting transform matrices to identity in order to experiment
> with them, I notices that my code for using
> DeformableMesh3DFilter was not wrong, but that filter does not respect
> direction cosines either. With identity cosines it worked without weird
> deformations I was experiencing with sagittal images.
> And since many (most?) filters which deal with images ignore direction
> cosines, again we come to the need of having a filter which will reorient
> image pixels in order to have identity cosines matrix (DICOM LPS
> orientation, ITK RAI orientation). And creating this filter does not have to
> be considered admitting "ITK is not perfect", it can be considered as a
> stopgap measure until all filters use TransformPhysicalPointToIndex and
> other built-in transformation routines instead of custom (and incomplete)
> transformation code (such as in TriangleMeshToBinaryImageFilter).
> Regards,
> Dženan
> 2010/5/26 Dženan Zukić <dzenanz at gmail.com>
>>
>> Hi everyone!
>> While wrestling with DeformableMesh3DFilter, I wanted to create binary
>> mask of my initial mesh (so I could use it with examples), but I ran into a
>> problem. TriangleMeshToBinaryImageFilter is not designed to produce images
>> with direction cosines matrix different from identity matrix. When I supply
>> it with such an image and mesh which is valid with respect to ITK's physical
>> coordinate handling routines (TransformPhysicalPointToContinuousIndex and
>> friends), it crashes.
>> typedef
>> itk::TriangleMeshToBinaryImageFilter<MeshType,VisualizingImageType>
>> MeshFilterType;
>> MeshFilterType::Pointer meshFilter = MeshFilterType::New();
>> meshFilter->SetInfoImage(visualizing); //TransformMatrix = 0 1 0
>> -0.0939968 0 -0.995573 -0.995573 0 0.0939968
>> meshFilter->SetInput(mesh);
>> meshFilter->Update(); //crashes
>> For usage in examples, I can edit my transform matrix in .mha files and
>> set it to identity, but what about normal usage? Is there some quick (and
>> possibly dirty) way to get this right, or do I have to do all the math on
>> paper in order to transform between representations with and without
>> direction cosines?
>> Thanks,
>> 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://www.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-users
>
>


More information about the Insight-users mailing list