typedef float InternalPixelType; const unsigned int Dimension = 2; typedef itk::Image< InternalPixelType, Dimension > InternalImageType; typedef unsigned char OutputPixelType; typedef itk::Image< OutputPixelType, Dimension > OutputImageType; typedef itk::ImageFileReader< InternalImageType > ReaderType; typedef itk::ImageFileWriter< OutputImageType > WriterType; typedef itk::RescaleIntensityImageFilter< InternalImageType, OutputImageType > CastFilterType; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); CastFilterType::Pointer caster = CastFilterType::New(); reader->SetFileName( "Input.bmp" ); reader->Update(); typedef itk::ImageRegionConstIterator< InternalImageType > ConstIteratorType; typedef itk::ImageRegionIterator< InternalImageType > IteratorType; InternalImageType::Pointer outputImage = InternalImageType::New(); outputImage->SetRegions( reader->GetOutput()->GetLargestPossibleRegion() ); outputImage->Allocate(); ConstIteratorType inputIt( reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion() ); IteratorType outputIt( outputImage, reader->GetOutput()->GetLargestPossibleRegion() ); for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt) { outputIt.Set( inputIt.Get() + 777); //Add 777 to every pixel. } caster->SetInput( outputImage ); writer->SetInput( caster->GetOutput() ); writer->SetFileName("Output.png"); caster->SetOutputMinimum( 0 ); caster->SetOutputMaximum( 255 ); writer->Update();