[Insight-users] itkRescaleImageFilter

Suresh G N suresh.gn at gmail.com
Thu Aug 4 00:11:48 EDT 2005


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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050804/538ff7b0/attachment.htm


More information about the Insight-users mailing list