[Insight-users] itkRescaleImageFilter
Luis Ibanez
luis.ibanez at kitware.com
Mon Aug 8 10:11:15 EDT 2005
Hi Suresh,
Your code look good.
Probably what is wrong is your assumption that you can take
any pixel type as input and then save it as unsighed short.
If you want to do such a thing, you probably should use
"double" as the pixel type of the input image.
Note that reader will do "casting" in your input images.
For more details, please read the ITK Software Guide
http://www.itk.org/ItkSoftwareGuide.pdf
in particular the Chapter:
"Reading and Writing Images"
Regards,
Luis
-------------------
Suresh G N wrote:
> Hi
>
> I am trying to read a 3D volume and write into a file. My code should
> take any kind of pixel type and change it to specified type. I am losing
> the data. Can any one tell me what is not working? here is my code:
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
>
> int main(int argc, char *argv[])
> {
> //Check number of commandline parameters
> if( argc < 3)
> {
> std:: cerr << "Incorrect number of parameters, check the usage:
> " << std::endl;
> std:: cerr << "inputFile outputFile " << std::endl;
> return EXIT_FAILURE;
> }
>
> //Input pixel type and output pixel type
> typedef unsigned short InputPixelType; //My data type is unsigned short
> typedef unsigned short OutputPixelType;
>
> //Dimension of the image
> const unsigned int Dimension = 3;
>
> const char* inputFilename = argv[1];
> const char* outputFilename = argv[2];
>
> typedef itk::Image< InputPixelType, Dimension > InputImageType;
> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>
> typedef itk::RescaleIntensityImageFilter< InputImageType,
> OutputImageType > RescaleFilterType;
>
> RescaleFilterType::Pointer rescalefilter = RescaleFilterType::New();
>
> rescalefilter->SetOutputMinimum( 0 );
> rescalefilter->SetOutputMaximum( 2019 );
>
> //Create reader and writer, update the pipeline
> ReaderType::Pointer reader = ReaderType::New();
> WriterType::Pointer writer = WriterType::New();
>
>
> reader->SetFileName( inputFilename );
> writer->SetFileName( outputFilename );
>
> rescalefilter->SetInput( reader->GetOutput() );
> writer->SetInput( rescalefilter->GetOutput() );
>
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return EXIT_FAILURE;
> }
>
> return EXIT_SUCCESS;
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list