/*========================================================================= Program: GIFT QMF Wavelet Image Filter Example Module: giftExampleQmfWavelet.cxx Language: C++ Date: 2005/11/21 Version: 0.1 Author: Dan Mueller [d.mueller@qut.edu.au] Copyright (c) 2005 Queensland University of Technology. All rights reserved. See giftCopyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #if defined(_MSC_VER) //Warning about: identifier was truncated to '255' characters in the //debug information (MVC6.0 Debug) #pragma warning( disable : 4786 ) #endif //General includes #include #include //ITK includes #include #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkCastImageFilter.h" #include "itkAbsImageFilter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkSimpleFilterWatcher.h" //GIFT includes #include "giftBiorthogonalWaveletOperator.h" #include "giftQmfWaveletImageFilter.h" ///////////////////////////////////////////////////////////// //Main method for example int main(int argc, char* argv[]) { //ARGUMENTS: //argv[0] = Executable name //argv[1] = Number of levels to deconstruct/reconstruct //argv[2] = Input file name and path //argv[3] = Output file name and path pattern with "{0}" //argv[4] = Final output file and path //Check arguments if (argc < 5) { std::cerr << "Usage: " << argv[0] << " NumberOfLevels" << " InputFilename" << " OutputDeconstructionFilepattern" << " OutputFilename\n"; return EXIT_FAILURE; } //Set input variables unsigned int NumberOfLevels = atoi(argv[1]); char* InputFilename = argv[2]; char* OutputDeconstructionFilepattern = argv[3]; //NOTE: must have "{0}" char* OutputFilename = argv[4]; //Typedefs and declarations const unsigned int Dimension = 2; typedef float InternalPixelType; typedef unsigned char WritePixelType; typedef itk::Image InternalImageType; typedef itk::Image WriteImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; typedef itk::RescaleIntensityImageFilter RescaleFilterType; typedef itk::CastImageFilter CastFilterType; typedef gift::BiorthogonalWaveletOperator BiorWavelet; typedef gift::QmfWaveletImageFilter WaveletFilter; //Read input ReaderType::Pointer reader = ReaderType::New(); std::cout << "Reading input=" << InputFilename << std::endl; reader->SetFileName(InputFilename); reader->Update(); //Create the wavelet operator BiorWavelet bior(BiorWavelet::Bior_1_3); //Create and setup deconstruction wavelet filter WaveletFilter::Pointer filterWaveletDeconstruct = WaveletFilter::New(); std::cout << "Setting Deconstruction NumberOfLevels=" << NumberOfLevels << std::endl; filterWaveletDeconstruct->SetNumberOfLevels(NumberOfLevels); filterWaveletDeconstruct->SetDeconstruction(); filterWaveletDeconstruct->SetWavelet(bior); filterWaveletDeconstruct->SetInput(reader->GetOutput()); itk::SimpleFilterWatcher watcherDeconstruct(filterWaveletDeconstruct, "QmfWaveletDeconstruction"); //Create and setup reconstruction wavelet filter WaveletFilter::Pointer filterWaveletReconstruct = WaveletFilter::New(); std::cout << "Setting Reconstruction NumberOfLevels=" << NumberOfLevels << std::endl; filterWaveletReconstruct->SetNumberOfLevels(NumberOfLevels); filterWaveletReconstruct->SetReconstruction(); filterWaveletReconstruct->SetWavelet(bior); itk::SimpleFilterWatcher watcherReconstruct(filterWaveletReconstruct, "QmfWaveletReconstruction"); //Set inputs for reconstruction, write deconstruction outputs for (unsigned int index=0; index < filterWaveletDeconstruct->GetNumberOfOutputs(); index++) { //Set input for reconstruction filterWaveletReconstruct->SetInput(index, filterWaveletDeconstruct->GetOutput(index)); //Construct output filename char strIndex[5]; sprintf(strIndex, "%02d", index); std::string outputFilename = OutputDeconstructionFilepattern; itksys::SystemTools::ReplaceString(outputFilename, "{0}", strIndex); //Rescale RescaleFilterType::Pointer filterRescale = RescaleFilterType::New(); filterRescale->SetOutputMinimum(0); filterRescale->SetOutputMaximum(255); filterRescale->SetInput(filterWaveletDeconstruct->GetOutput(index)); //Setup Writer WriterType::Pointer writer = WriterType::New(); std::cout << "Writing deconstruction output=" << outputFilename << std::endl; writer->SetFileName(outputFilename.c_str()); writer->SetInput(filterRescale->GetOutput()); //Perform write try { writer->Update(); } catch( itk::ExceptionObject & err ) { std::cout << "Caught exception trying to write deconstruction output!" << std::endl; std::cout << err << std::endl; return EXIT_FAILURE; } } //Force update on reconstruction filter //IMPORTANT NOTE: BUG //We must manually update the filter, otherwise the final image has // the wrong dimensions. //Sounds like an issue with GenerateOutputRequestedRegion(.), // but I can't find it. //Any help with this bug? Email me: d.mueller[at]qut.edu.au filterWaveletReconstruct->Update(); //Cast reconstruction output CastFilterType::Pointer filterCast = CastFilterType::New(); filterCast->SetInput(filterWaveletReconstruct->GetOutput()); //Setup final writer WriterType::Pointer writer = WriterType::New(); std::cout << "Writing reconstruction output=" << OutputFilename << std::endl; writer->SetFileName(OutputFilename); writer->SetInput(filterCast->GetOutput()); //Perform write try { writer->Update(); } catch( itk::ExceptionObject & err ) { std::cout << "Caught exception trying to write reconstruction output!" << std::endl; std::cout << err << std::endl; return EXIT_FAILURE; } //Return return EXIT_SUCCESS; }