[Insight-users] setting the spacing when writing an image to disk : FastMarchingImageFilter

Lucas Lorenzo lucas at cvrti.utah.edu
Sun, 25 Apr 2004 15:28:52 -0600


Hi Luis,

once again I have to say thanks a lot to you and Lydia.
Best regards,

Lucas

On Apr 25, 2004, at 7:59 AM, Luis Ibanez wrote:

>
>
> Hi Lucas,
>
>
> Lydia already solved your problem 5 weeks ago:
>
> http://www.itk.org/cgi-bin/cvsweb.cgi/Insight/Code/Algorithms/ 
> itkFastMarchingImageFilter.txx.diff?r1=1.44&r2=1.45&cvsroot=Insight
>
> That was done in order to fix Bug #624:
> http://www.itk.org/Bug/bug.php?op=show&bugid=624&pos=16
>
>
> You must now call the functions
>
>          fastMarchingFilter->SetOutputSpacing( ... )
>          fastMarchingFilter->SetOutputOrigin( ... )
>          fastMarchingFilter->SetOutputRegion( ... )
>
>
> from Doxygen:
>
> http://www.itk.org/Insight/Doxygen/html/ 
> classitk_1_1FastMarchingImageFilter.html
>
>   "The output largeset possible, spacing and origin is
>    computed as follows. If the speed image is NULL or
>    if the OverrideOutputInformation is true, the output
>    information is set from user specified parameters.
>
>    These parameters can be specified using methods
>    SetOutputRegion(), SetOutputSpacing() and SetOutputOrigin().
>    Else if the speed image is not NULL, the output information
>    is copied from the input speed image."
>
>
> --
>
> Of course, you must make sure that you use a CVS checkout
> posterior to March 18 2004. (When that changes were made).
>
>
>
>    Regards,
>
>
>
>       Luis
>
>
>
>
>
> -----------------------
> Lucas Lorenzo wrote:
>
>> I think I know what's the problem ... although I don't know yet how  
>> to solve it.
>> In this application there's no input to the FastMarchingImageFilter  
>> so there's no way to inherit the spacing from the original image.
>> The output size is set explicitly with the SetOutputSize member  
>> function but there's no member function to set the spacing  
>> explicitly.
>> The code is the following one:
>> typedef itk::FastMarchingImageFilter<InternalImageType>  
>> FastMarchingFilterType;
>> FastMarchingFilterType::Pointer fastMarching =  
>> FastMarchingFilterType::New();
>> typedef FastMarchingFilterType::NodeContainer NodeContainer;
>> typedef FastMarchingFilterType::NodeType NodeType;
>> NodeContainer::Pointer seeds = NodeContainer::New();
>> // Choose an initial contour that is the objet to be segmented
>> // The initial contour is a circle centered at {x_ini,y_ini} with  
>> radius
>> // 2.0
>> int x_ini = std::atoi(argv[10]);
>> int y_ini = std::atoi(argv[11]);
>> InternalImageType::IndexType seedPosition;
>> seedPosition[0] = x_ini;
>> seedPosition[1] = y_ini;
>> NodeType node;
>> node.SetValue( -2.0 );
>> node.SetIndex( seedPosition );
>> seeds->Initialize();
>> seeds->InsertElement( 0, node );
>> fastMarching->SetTrialPoints( seeds );
>> fastMarching->SetSpeedConstant( 1.0 );
>> //original reader reads the input image to be segmented
>> OriginalImageType::RegionType inputRegion =  
>> original_reader->GetOutput()->GetLargestPossibleRegion();
>> OriginalImageType::SizeType imageSize = inputRegion.GetSize();
>> fastMarching->SetOutputSize( imageSize );
>> try
>> {
>> fastMarching->Update();
>> }
>> catch( itk::ExceptionObject & exp )
>> {
>> std::cerr << "Exception caught ! fastMarching" << std::endl;
>> std::cerr << exp << std::endl;
>> return -1;
>> }
>> If you have any suggestions please let me know.
>> Thanks,
>> Lucas
>> On Apr 24, 2004, at 11:26 AM, Luis Ibanez wrote:
>>     Hi Lucas,
>>     Thanks for letting us know.
>>     The message you get about regions is normal,
>>     it is a remanent of a debugging effort that
>>     we should now remove.
>>     About your code: please try the following,
>>     just after calling Update in the FastMarching
>>     filter add the two lines:
>>     fastMarching->GetInput()->Print( std::cout );
>>     fastMarching->GetOutput()->Print( std::cout );
>>     I'm wandering if the spacing of the image is
>>     getting lost before it arrives to the fastMarching
>>     filter.
>>     Please let us know what you find.
>>     Thanks
>>     Luis
>>     ---------------------------------------------
>>     Lucas Lorenzo wrote:
>>         Hi Luis,
>>         I followed your directives and it does work fine.
>>         I'll go over my code again and if I find what's wrong I'll let
>>         you know.
>>         Also, if you have further suggestions please let me know.
>>         One last comment: the following message keeps appearing when I
>>         run this program with my vtk file:
>>         lucas:Borrar> FastMarchingImageFilter slc05fr_filt06.vtk  
>> out.vtk
>>         114 115 0.75 -0.4 12 10 11
>>         inputRequestedRegion: ImageRegion (0xbfffed60)
>>         Dimension: 2
>>         Index: [-1, -1]
>>         Size: [258, 258]
>>         largestPossibleRegion: ImageRegion (0x11004fc)
>>         Dimension: 2
>>         Index: [0, 0]
>>         Size: [256, 256]
>>         I don't know if this is useful but the header for the vtk file
>>         is as follows:
>>         # vtk DataFile Version 3.0
>>         VTK File Generated by Insight Segmentation and Registration
>>         Toolkit (ITK)
>>         BINARY
>>         DATASET STRUCTURED_POINTS
>>         DIMENSIONS 256 256 1
>>         SPACING 1.33 1.33 1.0
>>         ORIGIN 0 0 0.0
>>         POINT_DATA 65536
>>         SCALARS scalars unsigned_short 1
>>         LOOKUP_TABLE default
>>         Thanks,
>>         Lucas
>>         On Apr 23, 2004, at 3:43 PM, Luis Ibanez wrote:
>>         Hi Lucas,
>>         I just tested the capability of the FastMarching filter for  
>> using
>>         the Image Spacing, and it is working fine with the CVS  
>> version.
>>         Something else should be happening in your installation.
>>         Please do the following test:
>>         1) Compile the example:
>>         Insight/Examples/Segmentation/
>>         FastMarchingImageFitler.cxx
>>         2) Provide as input the .vtk image you have with pixel spacing
>>         different from unit
>>         3) Check if the output image carries the same spacing as the
>>         input one.
>>         This tests works for me both for .vtk and .mhd (MetaImage)
>>         images.
>>         Please let us know what you find.
>>         Thanks
>>         ----------------------
>>         Lucas Lorenzo wrote:
>>         Sorry, I kept making the same mistake once and once again. I
>>         guess that what I meant was obvious but let's clarify it  
>> anyway:
>>         when I talk about the "header files" I meant the headers for  
>> the
>>         image files (in vtk format).
>>         Cheers,
>>         Lucas
>>         On Apr 22, 2004, at 10:49 AM, Lucas Lorenzo wrote:
>>         Hi Luis,
>>         I'm attaching the file GeoACPSLS.cxx (which is a modified
>>         version of
>>          
>> itkGeodesicActiveContourShapePriorLevelSetImageFilterTest.cxx).
>>         When compiling against released version 1.6 the output after
>>         running
>>         one single iteration is as follows (as you see all image  
>> files are
>>         in vtk format):
>>         lucas:GeodesicAcContPrSh> GeoACPSLS PrincipalModes_fr06 5  
>> 0.75 -0.4
>>         12 0.2 2.0 0.15 0.8 1 slc5_fr_filt09.vtk 112 120
>>         Potential map created successfully !
>>          
>> ../DATAP091703/Anatomical/SLICE_05/PrincipalModes_fr06/mean.vtk
>>         shape components set successfully !
>>         Filter parameters set successfully !
>>         Thresholder parameters set successfully !
>>         1: [0.00025, 0, 0, 0, 0, 0, 0] 0.185567
>>         The input file header is:
>>         # vtk DataFile Version 3.0
>>         VTK File Generated by Insight Segmentation and Registration  
>> Toolkit
>>         (ITK)
>>         BINARY
>>         DATASET STRUCTURED_POINTS
>>         DIMENSIONS 256 256 1
>>         SPACING 1.33 1.33 1.0
>>         ORIGIN 0 0 0.0
>>         POINT_DATA 65536
>>         SCALARS scalars unsigned_short 1
>>         LOOKUP_TABLE default
>>         And the header file for the vtk image resulting from the fast
>>         marching algorithm is like this:
>>         # vtk DataFile Version 3.0
>>         VTK File Generated by Insight Segmentation and Registration  
>> Toolkit
>>         (ITK)
>>         BINARY
>>         DATASET STRUCTURED_POINTS
>>         DIMENSIONS 256 256 1
>>         SPACING 1 1 1.0
>>         ORIGIN 0 0 0.0
>>         POINT_DATA 65536
>>         SCALARS scalars float 1
>>         LOOKUP_TABLE default
>>         When compiling against the CVS copy I checked out about one  
>> week
>>         and
>>         a half ago the output is like this:
>>         lucas:GeodesicAcContPrSh> GeoACPSLS PrincipalModes_fr06 5  
>> 0.75 -0.4
>>         12 0.2 2.0 0.15 0.8 1 slc5_fr_filt09.vtk 112 120
>>         Potential map created successfully !
>>          
>> ../DATAP091703/Anatomical/SLICE_05/PrincipalModes_fr06/mean.vtk
>>         shape components set successfully !
>>         Filter parameters set successfully !
>>         Thresholder parameters set successfully !
>>         inputRequestedRegion: ImageRegion (0xbfffeb80)
>>         Dimension: 2
>>         Index: [-1, -1]
>>         Size: [258, 258]
>>         largestPossibleRegion: ImageRegion (0x1101f1c)
>>         Dimension: 2
>>         Index: [0, 0]
>>         Size: [256, 256]
>>         inputRequestedRegion: ImageRegion (0xbfffeb80)
>>         Dimension: 2
>>         Index: [-1, -1]
>>         Size: [258, 258]
>>         largestPossibleRegion: ImageRegion (0x1101f1c)
>>         Dimension: 2
>>         Index: [0, 0]
>>         Size: [256, 256]
>>         1: [0.00025, 0, 0, 0, 0, 0, 0] 0.185567
>>         And the header files are still as before (that is, the spacing
>>         problem still exists).
>>         I hope that this information is clear enough. If not, please  
>> let me
>>         know.
>>         Thanks for your help,
>>         Lucas
>>         <GeoACPSLS.cxx>
>>         On Apr 21, 2004, at 7:51 PM, Luis Ibanez wrote:
>>         Hi Lucas,
>>         Can you please post a minimal (working) example
>>         of code that illustrates this behavior. We need
>>         some initial code for reproducing the problem
>>         that you report.
>>         Thanks
>>         Luis
>>         -----------------------
>>         Lucas Lorenzo wrote:
>>         HI Luis,
>>         I've checked out a CVS copy last week and I still have the
>>         same problem.
>>         Also now, when running my code the following messages appear:
>>         inputRequestedRegion: ImageRegion (0xbfffeb70)
>>         Dimension: 2
>>         Index: [-1, -1]
>>         Size: [258, 258]
>>         largestPossibleRegion: ImageRegion (0x1101c5c)
>>         Dimension: 2
>>         Index: [0, 0]
>>         Size: [256, 256]
>>         inputRequestedRegion: ImageRegion (0xbfffeb70)
>>         Dimension: 2
>>         Index: [-1, -1]
>>         Size: [258, 258]
>>         largestPossibleRegion: ImageRegion (0x1101c5c)
>>         Dimension: 2
>>         Index: [0, 0]
>>         Size: [256, 256]
>>         Do you have any suggestions ?
>>         Thanks,
>>         Lucas
>>         On Feb 19, 2004, at 12:05 AM, Luis Ibanez wrote:
>>         Hi Lucas,
>>         The changes to the FastMarchingImageFilter have
>>         been commited. The output image now uses the
>>         spacing and origin of the input image.
>>         Please let us know if you find any problem.
>>         Thanks
>>         Luis
>>         ------------------------
>>         Lucas Lorenzo wrote:
>>         Hi Luis,
>>         sorry for answering so late.
>>         I've tried what you suggested but I have a run time
>>         error "Abort trap" when trying to apply the
>>         GetOutput() method to my FastMarchingImageFilter
>>         object.
>>         Let me know if there are any other changes we could
>>         try.
>>         Thanks,
>>         Lucas
>>         On Feb 11, 2004, at 5:58 AM, Luis Ibanez wrote:
>>         Hi Lucas,
>>         Thanks for pointing this out.
>>         Please try the following:
>>         Edit the file:
>>         Insight/Code/Algorithms/
>>         itkFastMarchingImageFilter.txx
>>         Go to to line : 150
>>         and after the statement
>>         output->Allocate();
>>         add
>>         output->CopyInformation( this->GetInput() );
>>         Then, go to line : 157
>>         and after the statement
>>         m_LabelImage->Allocate();
>>         add
>>         m_LabelImage->CopyInformation( this->GetInput() );
>>         This should copy the origin and spacing
>>         of the input image into the output and
>>         label images.
>>         Then recompile your application and try
>>         running it to see if the correct spacing
>>         appears in the file.
>>         Please let us know what you find, so we proceed
>>         to do the same changes in the repository.
>>         Thanks
>>         Luis
>>         ----------------------
>>         Lucas Lorenzo wrote:
>>         Hi Luis,
>>         sorry for having such a mess in my code.
>>         I'm using an application based on
>>         ITK/Testing/Code/Algorithms/
>>          
>> itkGeodesicActiveContourShapePriorLevelSetImageFilterTest_2.cxx
>>         The spacing is being carried through the
>>         pipeline with no problem, except when
>>         arriving to the point when I have to
>>         generate my initial contour (signed distance
>>         map) from a seed point using
>>         FastMarchingImageFilter. It is the output
>>         from this filter the one that has the
>>         "default" spacing (and I think that this new
>>         spacing is carried to the end to the output
>>         image) and I can't find any method to set
>>         the correct spacing.
>>         Thanks,
>>         Lucas
>>         On Tuesday, February 10, 2004, at 08:38 PM,
>>         Luis Ibanez wrote:
>>         Hi Lucas,
>>         Why are you setting the spacing on the ImageIO
>>         object instead of the image itself ?
>>         You should just carry the spacing through the
>>         pipeline. Does your input image has an invalid
>>         spacing ?
>>         An option in that case is to use the
>>         ChangeInformationImageFilter
>>         http://www.itk.org/Insight/Doxygen/html/
>>         classitk_1_1ChangeInformationImageFilter.html
>>         This filter carries the data buffer of the
>>         input image to the output image, and allows
>>         you to alter the meta-data such as image
>>         origin and spacing.
>>         Please don't use this filter for processing
>>         images of human beings or any other living
>>         organisms, since chances are that you will
>>         make somebody operate in a liver instead of
>>         a lung.
>>         In the long term the right thing to do is
>>         to fix the source of your images which is
>>         where the real spacing information should
>>         be comming from.
>>         Regards,
>>         Luis
>>         ======================================
>>         -------------------
>>         Lucas Lorenzo wrote:
>>         Hi all,
>>         I'm trying to write an image to disk in vtk
>>         format.
>>         By default the spacing is set to 1 1 1. I'd
>>         like to change it so
>>         I'm doing the following:
>>         /#include "itkVTKImageIO.h"
>>         int main( int argc, char * argv[] )
>>         {
>>         /* /* Typedefs of components. */*/
>>         const unsigned int ImageDimension = 2;
>>         typedef unsigned char BinaryPixelType;
>>         typedef
>>         itk::Image<BinaryPixelType,ImageDimension>
>>         BinaryImageType;
>>         /*// read the input image and get the
>>         spacing from it:*/
>>         typedef itk::VTKImageIO ImageIOType;
>>         ImageIOType::Pointer IO1 = ImageIOType::New();
>>         original_reader->SetImageIO(IO1);
>>         double dx,dy,dz;
>>         original_reader->Update();
>>         dx = IO1->GetSpacing(0);
>>         dy = IO1->GetSpacing(1);
>>         dz = IO1->GetSpacing(2);
>>         /*// here I'm omitting when I process the
>>         input image
>>         // write the image to a file but perviously
>>         set the spacing
>>         */
>>         binary_writer->SetFileName("out.vtk");
>>         binary_writer->SetInput(thresholder->GetOutput());
>>         ImageIOType::Pointer IO2 = ImageIOType::New();
>>         IO2->SetSpacing(0,dx);
>>         IO2->SetSpacing(1,dy);
>>         IO2->SetSpacing(2,dz);
>>         binary_writer->SetImageIO(IO2);
>>         try
>>         {
>>         binary_writer->Update();
>>         }
>>         catch( itk::ExceptionObject & exp )
>>         {
>>         std::cerr << "Exception caught ! binary
>>         image writer" << std::endl;
>>         std::cerr << exp << std::endl;
>>         return -1;
>>         }
>>         return 0;
>>         }
>>         /
>>         When I execute this program I have a
>>         "segmentation fault" run
>>         time error.
>>         If I ommit the line setting the spacing in
>>         the z axis ("/
>>         IO2->SetSpacing(2,dz); /") the programs
>>         executes without
>>         crashing but the spacing is not really set,
>>         that is, in the
>>         header of the output vtk file (out.vtk) you
>>         can still see
>>         "SPACING 1 1 1.0" instead of "SPACING dx dy
>>         1.0".
>>         Any clue of what am I doing wrong ?
>>         Thanks,
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research
>>         and Training Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         _______________________________________________
>>         Insight-users mailing list
>>         Insight-users at itk.org
>>         http://www.itk.org/mailman/listinfo/insight-users
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research
>>         and Training Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research and
>>         Training Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         _______________________________________________
>>         Insight-users mailing list
>>         Insight-users at itk.org
>>         http://www.itk.org/mailman/listinfo/insight-users
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research and Training
>>         Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         _______________________________________________
>>         Insight-users mailing list
>>         Insight-users at itk.org
>>         http://www.itk.org/mailman/listinfo/insight-users
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research and Training  
>> Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research and Training  
>> Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>         Lucas Lorenzo
>>         University of Utah
>>         Nora Eccles Harrison CardioVascular Research and Training  
>> Institute
>>         Fellows Room
>>         95 South 2000 East
>>         Salt Lake City, UT 84112-5000
>>         e-mail: lucas at cvrti.utah.edu
>>         telephone: 801-587-9536
>>     _______________________________________________
>>     Insight-users mailing list
>>     Insight-users at itk.org
>>     http://www.itk.org/mailman/listinfo/insight-users
>> Lucas Lorenzo
>> University of Utah
>> Nora Eccles Harrison CardioVascular Research and Training Institute
>> Fellows Room
>> 95 South 2000 East
>> Salt Lake City, UT 84112-5000
>> e-mail: lucas at cvrti.utah.edu
>> telephone: 801-587-9536
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
Lucas Lorenzo

University of Utah
Nora Eccles Harrison CardioVascular Research and Training Institute
Fellows Room
95 South 2000 East
Salt Lake City, UT 84112-5000

e-mail:  lucas at cvrti.utah.edu
telephone: 801-587-9536