[Insight-users] How to transfer Itk parameters to sub-function?

flydps flydps at 163.com
Sat Oct 27 12:48:43 EDT 2012


Hi, friends!
I am trying to write sub function with Itk. But I am puzzled by how to get the Itk typedef parameters for the sub-function. The function I want to realize is as follow, but how can I transfer the information of  "pReader" to my sub-function "OutputOldImageWidth"? 


 


#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include <iostream>
//Subfuntion to get image width
void OutputOldImageWidth(T_Reader::Pointer pReader);

void OutputOldImageWidth(T_Reader::Pointer pReader)
{
  const T_Image::RegionType& inputRegion = 
                              pReader->GetOutput()->GetLargestPossibleRegion();
  const T_Image::SizeType& vnInputSize = inputRegion.GetSize();
  unsigned int nOldWidth = vnInputSize[0];
  unsigned int nOldHeight = vnInputSize[1];
  printf("\nThe old width of image is %d",nOldWidth);
 }
/////////////////////////////////////

int main( int argc, char * argv[] )
{
  if( argc != 3 ) 
  { 
    std::cerr << "Usage: "
              << std::endl
              << argv[0]
              << " inputImageFile outputImageFile "
              << std::endl;

    return EXIT_FAILURE;
  }

  // Typedef's for pixel, image, reader and writer types
  typedef unsigned char T_InputPixel;
  typedef unsigned char T_OutputPixel;

  typedef itk::Image<T_InputPixel, 2> T_Image;
  typedef itk::ImageFileReader<T_Image> T_Reader;
  typedef unsigned char T_WritePixel;
  typedef itk::Image<T_WritePixel, 2> T_WriteImage;
  typedef itk::ImageFileWriter<T_WriteImage> T_Writer;


  // Prepare the reader and update it right away to know the sizes beforehand.

  T_Reader::Pointer pReader = T_Reader::New();
  pReader->SetFileName( argv[1] );
  pReader->Update();

  
  //****************** Call subfunction to get the image width.
 OutputOldImageWidth(T_Reader::Pointer pReader)


  // Write the result
  T_Writer::Pointer pWriter = T_Writer::New();
  pWriter->SetFileName(argv[2]);
  pWriter->SetInput(pReader->GetOutput());
  pWriter->Update();

  return EXIT_SUCCESS;
}

Thank you!

flydps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121028/3bf298ea/attachment.htm>


More information about the Insight-users mailing list