|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | + |
| 19 | +// |
| 20 | + |
| 21 | +#include "itkImageFileReader.h" |
| 22 | +#include "itkImageFileWriter.h" |
| 23 | + |
| 24 | +#include "itkGrayscaleGrindPeakImageFilter.h" |
| 25 | +#include "itkTestingMacros.h" |
| 26 | + |
| 27 | +int |
| 28 | +itkGrayscaleGrindPeakImageFilterTest(int argc, char * argv[]) |
| 29 | +{ |
| 30 | + if (argc < 3) |
| 31 | + { |
| 32 | + std::cerr << "Missing arguments." << std::endl; |
| 33 | + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " inputImageFile" |
| 34 | + << " outputImageFile" |
| 35 | + << " fullyConnected" << std::endl; |
| 36 | + return EXIT_FAILURE; |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + // |
| 41 | + // The following code defines the input and output pixel types and their |
| 42 | + // associated image types. |
| 43 | + // |
| 44 | + constexpr unsigned int Dimension = 2; |
| 45 | + |
| 46 | + using InputPixelType = unsigned char; |
| 47 | + using OutputPixelType = unsigned char; |
| 48 | + using WritePixelType = unsigned char; |
| 49 | + |
| 50 | + using InputImageType = itk::Image<InputPixelType, Dimension>; |
| 51 | + using OutputImageType = itk::Image<OutputPixelType, Dimension>; |
| 52 | + using WriteImageType = itk::Image<WritePixelType, Dimension>; |
| 53 | + |
| 54 | + using ReaderType = itk::ImageFileReader<InputImageType>; |
| 55 | + ReaderType::Pointer reader = ReaderType::New(); |
| 56 | + reader->SetFileName(argv[1]); |
| 57 | + |
| 58 | + |
| 59 | + // Create the filter |
| 60 | + using GrindPeakFilterType = itk::GrayscaleGrindPeakImageFilter<InputImageType, OutputImageType>; |
| 61 | + GrindPeakFilterType::Pointer grindpeak = GrindPeakFilterType::New(); |
| 62 | + |
| 63 | + ITK_EXERCISE_BASIC_OBJECT_METHODS(grindpeak, GrayscaleGrindPeakImageFilter, ImageToImageFilter); |
| 64 | + |
| 65 | + grindpeak->SetInput(reader->GetOutput()); |
| 66 | + |
| 67 | + auto fullyConnected = static_cast<bool>(std::stoi(argv[3])); |
| 68 | + ITK_TEST_SET_GET_BOOLEAN(grindpeak, FullyConnected, fullyConnected); |
| 69 | + |
| 70 | + ITK_TRY_EXPECT_NO_EXCEPTION(grindpeak->Update()); |
| 71 | + |
| 72 | + // Write the output |
| 73 | + using WriterType = itk::ImageFileWriter<WriteImageType>; |
| 74 | + WriterType::Pointer writer = WriterType::New(); |
| 75 | + writer->SetFileName(argv[2]); |
| 76 | + writer->SetInput(grindpeak->GetOutput()); |
| 77 | + |
| 78 | + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); |
| 79 | + |
| 80 | + |
| 81 | + std::cout << "Test finished" << std::endl; |
| 82 | + return EXIT_SUCCESS; |
| 83 | +} |
0 commit comments