diff --git a/include/itkImageToWasmImageFilter.hxx b/include/itkImageToWasmImageFilter.hxx index 9516366bb..c77400319 100644 --- a/include/itkImageToWasmImageFilter.hxx +++ b/include/itkImageToWasmImageFilter.hxx @@ -138,8 +138,9 @@ ImageToWasmImageFilter imageJSON->SetImage(image); using PointType = typename TImage::PointType; - using PixelType = typename TImage::IOPixelType; - using ConvertPixelTraits = DefaultConvertPixelTraits; + using PixelType = typename TImage::PixelType; + using IOPixelType = typename TImage::IOPixelType; + using ConvertPixelTraits = DefaultConvertPixelTraits; using ComponentType = typename ConvertPixelTraits::ComponentType; rapidjson::Document document; @@ -160,7 +161,7 @@ ImageToWasmImageFilter pixelType.SetString( wasm::MapPixelType::PixelString.data(), allocator ); imageType.AddMember("pixelType", pixelType.Move(), allocator ); - imageType.AddMember("components", rapidjson::Value( ConvertPixelTraits::GetNumberOfComponents() ).Move(), allocator ); + imageType.AddMember("components", rapidjson::Value( image->GetNumberOfComponentsPerPixel() ).Move(), allocator ); document.AddMember( "imageType", imageType.Move(), allocator ); diff --git a/include/itkOutputImage.h b/include/itkOutputImage.h index 50349c108..eb34b46c0 100644 --- a/include/itkOutputImage.h +++ b/include/itkOutputImage.h @@ -84,7 +84,7 @@ class ITK_TEMPLATE_EXPORT OutputImage const auto dataAddress = reinterpret_cast< size_t >( wasmImage->GetImage()->GetBufferPointer() ); using ConvertPixelTraits = DefaultConvertPixelTraits; - const auto dataSize = wasmImage->GetImage()->GetPixelContainer()->Size() * sizeof(typename ConvertPixelTraits::ComponentType) * ConvertPixelTraits::GetNumberOfComponents(); + const auto dataSize = wasmImage->GetImage()->GetPixelContainer()->Size() * sizeof(typename ConvertPixelTraits::ComponentType); setMemoryStoreOutputArray(0, index, 0, dataAddress, dataSize); const auto directionAddress = reinterpret_cast< size_t >( wasmImage->GetImage()->GetDirection().GetVnlMatrix().begin() ); diff --git a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm index 8175cd654..7104d46bc 100755 Binary files a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm and b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm differ diff --git a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm index 2e867693a..7d7b8c987 100755 Binary files a/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm and b/packages/compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm differ diff --git a/packages/core/typescript/itk-wasm/src/cli/default-image-tag.js b/packages/core/typescript/itk-wasm/src/cli/default-image-tag.js index 00fc363ea..da4ef1563 100644 --- a/packages/core/typescript/itk-wasm/src/cli/default-image-tag.js +++ b/packages/core/typescript/itk-wasm/src/cli/default-image-tag.js @@ -1,2 +1,2 @@ -const defaultImageTag = '20240605-0b83f08b' +const defaultImageTag = '20240624-b89bcb6c' export default defaultImageTag diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm index 27de9aef3..a902e3c0b 100755 Binary files a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm differ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm index 7cef7ed4c..cc7b603fe 100755 Binary files a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm differ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 31897f735..cea2baad6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,6 +56,7 @@ ExternalData_Expand_Arguments( set(WebAssemblyInterfaceTests itkWasmImageInterfaceTest.cxx + itkWasmVectorImageInterfaceTest.cxx itkWasmImageInterfaceWithNegativeIndexTest.cxx itkWasmMeshInterfaceTest.cxx itkWasmPolyDataInterfaceTest.cxx @@ -87,6 +88,15 @@ itk_add_test(NAME itkWasmImageInterfaceTest ${ITK_TEST_OUTPUT_DIR}/itkWasmImageInterfaceTest.mha ) +itk_add_test(NAME itkWasmVectorImageInterfaceTest + COMMAND WebAssemblyInterfaceTestDriver + --compare DATA{Input/apple.jpg} + ${ITK_TEST_OUTPUT_DIR}/itkWasmVectorImageInterfaceTest.mha + itkWasmVectorImageInterfaceTest + DATA{Input/apple.jpg} + ${ITK_TEST_OUTPUT_DIR}/itkWasmVectorImageInterfaceTest.mha +) + itk_add_test(NAME itkWasmImageInterfaceWithNegativeIndexTest COMMAND WebAssemblyInterfaceTestDriver --compare DATA{Baseline/negative_idx_padded.mha} diff --git a/test/itkWasmVectorImageInterfaceTest.cxx b/test/itkWasmVectorImageInterfaceTest.cxx new file mode 100644 index 000000000..fbef34f1a --- /dev/null +++ b/test/itkWasmVectorImageInterfaceTest.cxx @@ -0,0 +1,64 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#include "itkImageToWasmImageFilter.h" +#include "itkWasmImageToImageFilter.h" + +#include "itkImageFileReader.h" +#include "itkImageFileWriter.h" +#include "itkTestingMacros.h" + +int +itkWasmVectorImageInterfaceTest(int argc, char * argv[]) +{ + if (argc < 3) + { + std::cerr << "Missing parameters" << std::endl; + std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage" << std::endl; + return EXIT_FAILURE; + } + const char * inputImageFile = argv[1]; + const char * outputImageFile = argv[2]; + + constexpr unsigned int Dimension = 2; + using PixelType = unsigned char; + using ImageType = itk::VectorImage; + using ImagePointer = ImageType::Pointer; + + ImagePointer inputImage = nullptr; + ITK_TRY_EXPECT_NO_EXCEPTION(inputImage = itk::ReadImage(inputImageFile)); + std::cout << "inputImage: " << inputImage << std::endl; + + using ImageToWasmImageFilterType = itk::ImageToWasmImageFilter; + auto imageToJSON = ImageToWasmImageFilterType::New(); + imageToJSON->SetInput(inputImage); + imageToJSON->Update(); + auto imageJSON = imageToJSON->GetOutput(); + std::cout << "Image JSON: " << imageJSON->GetJSON() << std::endl; + + using WasmImageToImageFilterType = itk::WasmImageToImageFilter; + auto jsonToImage = WasmImageToImageFilterType::New(); + jsonToImage->SetInput(imageToJSON->GetOutput()); + jsonToImage->Update(); + ImageType::Pointer convertedImage = jsonToImage->GetOutput(); + + std::cout << "convertedImage: " << convertedImage << std::endl; + + ITK_TRY_EXPECT_NO_EXCEPTION(itk::WriteImage(convertedImage, outputImageFile)); + + return EXIT_SUCCESS; +}