[Insight-users] How to transfer Itk parameters to sub-function?
Dženan Zukić
dzenanz at gmail.com
Mon Oct 29 05:55:41 EDT 2012
typedef must come before its use, that is before function. You should make
it just after all the includes.
typedef itk::ImageFileReader<T_Image> T_Reader;
On Sat, Oct 27, 2012 at 6:48 PM, flydps <flydps at 163.com> wrote:
> **
> 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
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121029/a266db9f/attachment.htm>
More information about the Insight-users
mailing list