[Insight-users] Re: getting pixel values from 3d image
Luis Ibanez
luis.ibanez at kitware.com
Fri Sep 3 18:47:21 EDT 2004
Hi Sharad,
The ChangeInformationFilter will not have any effect
in your image if you don't connect the filter to the
pipeline.
You MUST replace the line
writer->SetInput( reader->GetOutput() );
with the two following lines
imgspacing->SetInput( reader->GetOutput() );
writer->SetInput( imagspacing->GetOutput() );
Regards,
Luis
---------------------------------------
sharad at hermes.eng.fsu.edu wrote:
> Hi Luis
>
> i followed what you said about the spacing the program doesnt give any
> error but i am not sure if the setoutput spacing did any difference to my
> final image can you look at my code and tell me if anything is wrong.
> thanks
>
> regards
> sharad
>
> #############
>
>
> #include "itkNumericSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImage.h"
> #include <vector>
> #include <string>
> #include <stdio.h>
> #include <itkChangeInformationImageFilter.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();
>
>
>
> double spacing[3]; /*new */
>
> spacing[0] = 0.1; // spacing in mm along X
> spacing[1] = 0.1; // spacing in mm along Y
> spacing[2] = 0.50; // spacing in mm along Z
>
> itk::ChangeInformationImageFilter<Image3DType>::Pointer imgspacing =
> itk::ChangeInformationImageFilter<Image3DType>::New();
>
> imgspacing->SetOutputSpacing( spacing );
>
>
>
>
>
> //
> // 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;
> }
>
>
>
More information about the Insight-users
mailing list