|
| 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 | + * https://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 | +#include "itkImageToWasmImageFilter.h" |
| 19 | +#include "itkWasmImageToImageFilter.h" |
| 20 | + |
| 21 | +#include "itkConstantPadImageFilter.h" |
| 22 | +#include "itkImageFileReader.h" |
| 23 | +#include "itkImageFileWriter.h" |
| 24 | +#include "itkTestingMacros.h" |
| 25 | + |
| 26 | +int |
| 27 | +itkWasmImageInterfaceWithNegativeIndexTest(int argc, char * argv[]) |
| 28 | +{ |
| 29 | + if (argc < 3) |
| 30 | + { |
| 31 | + std::cerr << "Missing parameters" << std::endl; |
| 32 | + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage" << std::endl; |
| 33 | + return EXIT_FAILURE; |
| 34 | + } |
| 35 | + const char * inputImageFile = argv[1]; |
| 36 | + const char * outputImageFile = argv[2]; |
| 37 | + |
| 38 | + constexpr unsigned int Dimension = 3; |
| 39 | + using PixelType = unsigned char; |
| 40 | + using ImageType = itk::Image<PixelType, Dimension>; |
| 41 | + using ImagePointer = ImageType::Pointer; |
| 42 | + |
| 43 | + ImagePointer inputImage = nullptr; |
| 44 | + ITK_TRY_EXPECT_NO_EXCEPTION(inputImage = itk::ReadImage<ImageType>(inputImageFile)); |
| 45 | + std::cout << "inputImage: " << inputImage << std::endl; |
| 46 | + |
| 47 | + ImageType::SizeType lowerExtendRegion; |
| 48 | + lowerExtendRegion.Fill(1); |
| 49 | + |
| 50 | + ImageType::SizeType upperExtendRegion; |
| 51 | + upperExtendRegion.Fill(1); |
| 52 | + |
| 53 | + using ConstantPadImageFilterType = itk::ConstantPadImageFilter<ImageType,ImageType>; |
| 54 | + auto constantPad = ConstantPadImageFilterType::New(); |
| 55 | + constantPad->SetInput(inputImage); |
| 56 | + constantPad->SetPadLowerBound(lowerExtendRegion); |
| 57 | + constantPad->SetPadUpperBound(upperExtendRegion); |
| 58 | + constantPad->SetConstant(0); |
| 59 | + |
| 60 | + using ImageToWasmImageFilterType = itk::ImageToWasmImageFilter<ImageType>; |
| 61 | + auto imageToJSON = ImageToWasmImageFilterType::New(); |
| 62 | + imageToJSON->SetInput(constantPad->GetOutput()); |
| 63 | + imageToJSON->Update(); |
| 64 | + auto imageJSON = imageToJSON->GetOutput(); |
| 65 | + std::cout << "Image JSON: " << imageJSON->GetJSON() << std::endl; |
| 66 | + |
| 67 | + using WasmImageToImageFilterType = itk::WasmImageToImageFilter<ImageType>; |
| 68 | + auto jsonToImage = WasmImageToImageFilterType::New(); |
| 69 | + jsonToImage->SetInput(imageToJSON->GetOutput()); |
| 70 | + jsonToImage->Update(); |
| 71 | + ImageType::Pointer convertedImage = jsonToImage->GetOutput(); |
| 72 | + |
| 73 | + std::cout << "convertedImage: " << convertedImage << std::endl; |
| 74 | + |
| 75 | + ITK_TRY_EXPECT_NO_EXCEPTION(itk::WriteImage(convertedImage, outputImageFile)); |
| 76 | + |
| 77 | + return EXIT_SUCCESS; |
| 78 | +} |
0 commit comments