/*========================================================================= Program: GIFT Feature Generators Test Module: giftTestFeatureGenerators.cxx Language: C++ Date: 2005/11/24 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 //ITK includes #include #include "itkNumericTraits.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkCastImageFilter.h" #include "itkRescaleIntensityImageFilter.h" //GIFT includes #include "giftSampleActivity.h" #include "giftAbsSampleActivity.h" #include "giftMedianWindowSampleActivity.h" #include "giftMaximumWindowSampleActivity.h" ///////////////////////////////////////////////////////////// //Test gift::giftTestActivityFeature template int giftTestFourBandActivityFeature(int argc, char* argv[], typename FeatureGeneratorType::Pointer featureGen) { bool success = true; //Set input variables char* FilenameInput0 = argv[1]; char* FilenameInput1 = argv[2]; char* FilenameInput2 = argv[3]; char* FilenameInput3 = argv[4]; char* FilenameOutputPattern = argv[5]; //Typedefs typedef unsigned char WritePixelType; //Declare types typedef itk::Image InternalImageType; typedef itk::Image WriteImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageFileWriter WriterType; typedef itk::RescaleIntensityImageFilter RescaleFilterType; // typedef gift::SampleActivity FeatureGeneratorType; //Read input0 typename ReaderType::Pointer readerInput0 = ReaderType::New(); readerInput0->SetFileName(FilenameInput0); //Read input1 typename ReaderType::Pointer readerInput1 = ReaderType::New(); readerInput1->SetFileName(FilenameInput1); //Read input2 typename ReaderType::Pointer readerInput2 = ReaderType::New(); readerInput2->SetFileName(FilenameInput2); //Read input3 typename ReaderType::Pointer readerInput3 = ReaderType::New(); readerInput3->SetFileName(FilenameInput3); //Setup feature generator featureGen->SetNumberOfInputImages(1); featureGen->SetNumberOfInputLevels(1); featureGen->SetNumberOfInputBands(4); featureGen->SetInput(0, readerInput0->GetOutput()); featureGen->SetInput(1, readerInput1->GetOutput()); featureGen->SetInput(2, readerInput2->GetOutput()); featureGen->SetInput(3, readerInput3->GetOutput()); featureGen->Update(); for (unsigned int index=0; indexGetNumberOfOutputs(); index++) { //Rescale typename RescaleFilterType::Pointer filterRescale = RescaleFilterType::New(); filterRescale->SetOutputMinimum(0); filterRescale->SetOutputMaximum(255); filterRescale->SetInput(featureGen->GetOutput(index)); //Construct output filename char strIndex[5]; sprintf(strIndex, "%02d", index); std::string outputFilename = FilenameOutputPattern; itksys::SystemTools::ReplaceString(outputFilename, "{0}", strIndex); //Write typename WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputFilename.c_str()); writer->SetInput(filterRescale->GetOutput()); writer->Update(); } //Return if (success){return EXIT_SUCCESS;} else {return EXIT_FAILURE;} } ///////////////////////////////////////////////////////////// //Test gift::SampleActivity int giftTestSampleActivityFeature( int argc, char* argv[] ) { //ARGUMENTS: //argv[0] = Executable name //argv[1] = Feature 0 file name and path (eg. "C:\temp\feature_input1.png") //argv[2] = Feature 1 file name and path (eg. "C:\temp\feature_input2.png") //argv[3] = Feature 2 file name and path (eg. "C:\temp\feature_input3.png") //argv[4] = Feature 3 file name and path (eg. "C:\temp\feature_input4.png") //argv[5] = FilenameOutputPattern = feature output file name and path pattern (eg. "C:\temp\feature_output_{0}.png") //Declare typedefs const unsigned int Dimension = 2; typedef float InternalPixelType; typedef itk::Image InternalImageType; //Create and setup feature generator typedef gift::SampleActivity FeatureGeneratorType; FeatureGeneratorType::Pointer featureGen = FeatureGeneratorType::New(); //Test return giftTestFourBandActivityFeature(argc, argv, featureGen); } ///////////////////////////////////////////////////////////// //Test gift::AbsSampleActivity int giftTestAbsSampleActivityFeature( int argc, char* argv[] ) { //ARGUMENTS: //argv[0] = Executable name //argv[1] = Feature 0 file name and path (eg. "C:\temp\feature_input1.png") //argv[2] = Feature 1 file name and path (eg. "C:\temp\feature_input2.png") //argv[3] = Feature 2 file name and path (eg. "C:\temp\feature_input3.png") //argv[4] = Feature 3 file name and path (eg. "C:\temp\feature_input4.png") //argv[5] = FilenameOutputPattern = feature output file name and path pattern (eg. "C:\temp\feature_output_{0}.png") //Declare typedefs const unsigned int Dimension = 2; typedef float InternalPixelType; typedef itk::Image InternalImageType; //Create and setup feature generator typedef gift::AbsSampleActivity FeatureGeneratorType; FeatureGeneratorType::Pointer featureGen = FeatureGeneratorType::New(); //Test return giftTestFourBandActivityFeature(argc, argv, featureGen); } ///////////////////////////////////////////////////////////// //Test gift::MedianWindowSampleActivity int giftTestMedianWindowSampleActivityFeature( int argc, char* argv[] ) { //ARGUMENTS: //argv[0] = Executable name //argv[1] = Feature 0 file name and path (eg. "C:\temp\feature_input1.png") //argv[2] = Feature 1 file name and path (eg. "C:\temp\feature_input2.png") //argv[3] = Feature 2 file name and path (eg. "C:\temp\feature_input3.png") //argv[4] = Feature 3 file name and path (eg. "C:\temp\feature_input4.png") //argv[5] = FilenameOutputPattern = feature output file name and path pattern (eg. "C:\temp\feature_output_{0}.png") //Declare typedefs const unsigned int Dimension = 2; typedef float InternalPixelType; typedef itk::Image InternalImageType; //Create and setup feature generator typedef gift::MedianWindowSampleActivity FeatureGeneratorType; FeatureGeneratorType::Pointer featureGen = FeatureGeneratorType::New(); featureGen->SetWindowRadius(1); //0=0x0, 1=3x3, 2=5x5, 3=7x7 //Test return giftTestFourBandActivityFeature(argc, argv, featureGen); } ///////////////////////////////////////////////////////////// //Test gift::MaximumWindowSampleActivity int giftTestMaximumWindowSampleActivityFeature( int argc, char* argv[] ) { //ARGUMENTS: //argv[0] = Executable name //argv[1] = Feature 0 file name and path (eg. "C:\temp\feature_input1.png") //argv[2] = Feature 1 file name and path (eg. "C:\temp\feature_input2.png") //argv[3] = Feature 2 file name and path (eg. "C:\temp\feature_input3.png") //argv[4] = Feature 3 file name and path (eg. "C:\temp\feature_input4.png") //argv[5] = FilenameOutputPattern = feature output file name and path pattern (eg. "C:\temp\feature_output_{0}.png") //Declare typedefs const unsigned int Dimension = 2; typedef float InternalPixelType; typedef itk::Image InternalImageType; //Create and setup feature generator typedef gift::MaximumWindowSampleActivity FeatureGeneratorType; FeatureGeneratorType::Pointer featureGen = FeatureGeneratorType::New(); featureGen->SetWindowRadius(1); //0=0x0, 1=3x3, 2=5x5, 3=7x7 //Test return giftTestFourBandActivityFeature(argc, argv, featureGen); }