[Insight-users] Re: spacing of images
Luis Ibanez
luis.ibanez at kitware.com
Thu Jun 17 23:09:26 EDT 2004
Hi Sharad,
Since the ImageSeriesReader cannot figure out the
inter-slice spacing of the 3D image from your set of
PNG image, the best way to introduce this information
is by using the ChangeInformationImageFilter.
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html
This is not the filter that you want to use if you
were doing Image Guided Surgery or Computer Aided Diagnosis
for real patients. In your case, since you are controlling
the image acquisition, it is safe and justified to use this
filter.
Your pipeline should look like:
ImageSeriesReader---->> ChangeInformationFilter---->>> etc
in the ChangeInformationImageFilter you should invoke the
method:
SetOutputSpacing()
and feed it with an array that has the correct spacing values.
---
Regarding the input of BMP files, the only change that you
have to introduce is to use the extension ".bmp" in the
filename format that you pass to the NumericSeriesFileNames
object.
The ImageIO factory will take care of invoking the correct
reader.
Regards,
Luis
------------------------------
sharad at lynx.eng.fsu.edu wrote:
> Hi Luis
> i got a question regarding stacking of images.1i am using the following
> code (at the end of the email) to stack 2d png images to a 3d vtk image
> but i am not sure how to give the spacing between the images(i take 2d
> images moving the stepper motor 0.5 microns) so how can implement the
> functionality of specifying the spacing between the images
> also how can i make the same program read in bmp images for stacking
> rather than png
> thanks a lot for your time
> regards
> sharad
>
> START OF CODE
> *******************************************************************
>
> #include "itkNumericSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImage.h"
> #include <vector>
> #include <string>
> #include <stdio.h>
>
> int main(int argc, char * argv[])
> {
> std::cout << argv[1] << std::endl;
> typedef itk::Image<unsigned char,3> Image3DType;
>
> // Verify the number of parameters in the command line
> if( argc < 4 )
> {
> std::cerr << "Usage: " << std::endl;
> std::cerr << argv[0] << "StartIndex EndIndex inputImageFileBaseName
> outputImageFile" << std::endl;
> std::cerr << " Example: StartIndex = 1 , EndIndex =
> 100,inputImageFileBaseName = myI00%d.png" << std::endl;
> std::cerr << " will read myI001.png, ..., myI100.png. 100 png files"
> << std::endl;
> std::cerr << " if outputImageFile = my.mha then it will output a file
> my.mha which is in meta format" << std::endl;
> std::cerr << " if outputImageFile = my.gipl then it will output a
> file my.gipl which is in gipl format" << std::endl;
> std::cerr << " ./readPngWrite3DGiplNew 0 1 myImages00%d.png outp.mha
> " << std::endl;
> std::cerr << " will read in myImages000.png and myImages001.png,
> output outp.mha in meta format " << std::endl;
> return -1;
> }
>
> const int StartIndex = (int) atof(argv[1]);
> const int EndIndex = (int) atof(argv[2]);
> const char * inImFileBase = argv[3];
> const char * ouImFileName = argv[4];
>
>
>
> //std::cout << argv[4] << std::endl;
>
> //
> // Here we generate filenames like
> // myImage000.png, myImage001.png .... to myImage200.png
> // The most important thing is that the seriess must be
> // same size!!!!!!!!!!!!!!
> //
> itk::NumericSeriesFileNames::Pointer fileIter =
> itk::NumericSeriesFileNames::New();
>
> fileIter->SetStartIndex( StartIndex );
> fileIter->SetEndIndex( EndIndex );
> fileIter->SetIncrementIndex( 1 );
> //const char * inputFileNameBase = ( const char * ) strcat( (char *)
> //inImFileBase, (char *) "00%d.png");
> //std::cout << inputFileNameBase << std::endl;
> //std::cout << argv[3] << std::endl;
> //std::cout << argv[4] << std::endl;
> //fileIter->SetSeriesFormat("myImages00%d.png");
>
> fileIter->SetSeriesFormat(inImFileBase);
>
> itk::ImageSeriesReader<Image3DType>::Pointer reader =
> itk::ImageSeriesReader<Image3DType>::New();
> reader->SetFileNames( fileIter->GetFileNames() );
>
> reader->Update();
>
>
> //
> // Here we save the image in GIPL format
> // or any other forms which itk understand!
> // The user only need to give the correct
> // file extention !
> //
> itk::ImageFileWriter< Image3DType >::Pointer writer =
> itk::ImageFileWriter< Image3DType >::New();
>
> writer->SetInput( reader->GetOutput() );
> //writer->SetFileName("myImage.mha");
> //return 0;
>
> writer->SetFileName(ouImFileName);
>
> try
>
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cout << "ExceptionObject caught !" << std::endl;
> std::cout << err << std::endl;
> return -1;
> }
>
>
> return 0;
> }
>
> ************************************************END OF CODE
>
>
>
More information about the Insight-users
mailing list