[Insight-users] setting the spacing when writing an image to disk
Lucas Lorenzo
lucas at cvrti.utah.edu
Tue, 10 Feb 2004 21:12:08 -0700
--Apple-Mail-12--618718974
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
delsp=yes;
charset=US-ASCII;
format=flowed
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
--Apple-Mail-12--618718974
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
charset=US-ASCII
Hi Luis,
sorry for having such a mess in my code.
I'm using an application based on
<fontfamily><param>Times New Roman</param>ITK/Testing/Code/Algorithms/itkGeodesicActiveContourShapePriorLevelSetImageFilterTest_2.cxx</fontfamily>
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:
<excerpt>
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:
<excerpt>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
</excerpt>
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users
</excerpt>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
--Apple-Mail-12--618718974--