Skip to content

Commit

Permalink
feat(compare-images): add vector-magnitude pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Aug 21, 2023
1 parent 6cabf37 commit 3478c4a
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/compare-images/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ include(${ITK_USE_FILE})
add_executable(compare-double-images compare-double-images.cxx)
target_link_libraries(compare-double-images PUBLIC ${ITK_LIBRARIES})

add_executable(vector-magnitude vector-magnitude.cxx)
target_link_libraries(vector-magnitude PUBLIC ${ITK_LIBRARIES})

enable_testing()
add_test(NAME compare-double-images
COMMAND compare-double-images
Expand All @@ -36,4 +39,10 @@ add_test(NAME compare-double-images
${CMAKE_CURRENT_BINARY_DIR}/cake_diff_double.iwi.cbor
${CMAKE_CURRENT_BINARY_DIR}/cake_diff.png
--baseline-images ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/cake_hard.iwi.cbor
)

add_test(NAME vector-magnitude
COMMAND vector-magnitude
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/apple.iwi.cbor
${CMAKE_CURRENT_BINARY_DIR}/apply_magnitude.iwi.cbor
)
3 changes: 2 additions & 1 deletion packages/compare-images/compare-double-images.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include "itkInputImage.h"
#include "itkOutputImage.h"
#include "itkOutputTextStream.h"
#include "itkSupportInputImageTypes.h"

#include "itkImage.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkExtractImageFilter.h"
#include "itkTestingComparisonImageFilter.h"
#include "itkSupportInputImageTypes.h"

#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
Expand Down Expand Up @@ -219,6 +219,7 @@ int main(int argc, char * argv[])
itk::wasm::Pipeline pipeline("compare-double-images", "Compare double pixel type images with a tolerance for regression testing.", argc, argv);

return itk::wasm::SupportInputImageTypes<PipelineFunctor,

double>
::Dimensions<2U,3U,4U,5U,6U>("test-image", pipeline);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

from .compare_double_images_async import compare_double_images_async
from .compare_double_images import compare_double_images
from .vector_magnitude_async import vector_magnitude_async
from .vector_magnitude import vector_magnitude

from ._version import __version__
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compare_double_images(
radius_tolerance: int = 0,
number_of_pixels_tolerance: int = 0,
ignore_boundary_pixels: bool = False,
) -> Tuple[Dict, Image, Image]:
) -> Tuple[Any, Image, Image]:
"""Compare double pixel type images with a tolerance for regression testing.
:param test_image: The input test image
Expand All @@ -37,7 +37,7 @@ def compare_double_images(
:type ignore_boundary_pixels: bool
:return: Metrics for the baseline with the fewest number of pixels outside the tolerances.
:rtype: Dict
:rtype: Any
:return: Absolute difference image
:rtype: Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated file. Do not edit.

import os
from typing import Dict, Tuple, Optional, List, Any

Expand All @@ -13,7 +15,7 @@ async def compare_double_images_async(
radius_tolerance: int = 0,
number_of_pixels_tolerance: int = 0,
ignore_boundary_pixels: bool = False,
) -> Tuple[Dict, Image, Image]:
) -> Tuple[Any, Image, Image]:
"""Compare double pixel type images with a tolerance for regression testing.
:param test_image: The input test image
Expand All @@ -35,7 +37,7 @@ async def compare_double_images_async(
:type ignore_boundary_pixels: bool
:return: Metrics for the baseline with the fewest number of pixels outside the tolerances.
:rtype: Dict
:rtype: Any
:return: Absolute difference image
:rtype: Image
Expand Down
Binary file not shown.
Binary file added packages/compare-images/test/data/input/apple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions packages/compare-images/vector-magnitude.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*=========================================================================
* 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 "itkPipeline.h"
#include "itkInputImage.h"
#include "itkOutputImage.h"
#include "itkSupportInputImageTypes.h"

#include "itkImage.h"
#include "itkVectorImage.h"
#include "itkVectorMagnitudeImageFilter.h"

template<typename TImage>
class PipelineFunctor
{
public:
int operator()(itk::wasm::Pipeline & pipeline)
{
using ImageType = TImage;
using ScalarType = typename ImageType::PixelType::ValueType;
using ScalarImageType = itk::Image<ScalarType, ImageType::ImageDimension>;
using MagnitudeFilterType = itk::VectorMagnitudeImageFilter<ImageType, ScalarImageType>;

using InputImageType = itk::wasm::InputImage<ImageType>;
InputImageType vectorImage;
pipeline.add_option("vector-image", vectorImage, "Input vector image")->required()->type_name("INPUT_IMAGE");

using OutputImageType = itk::wasm::OutputImage<ScalarImageType>;
OutputImageType magnitudeImage;
pipeline.add_option("magnitude-image", magnitudeImage, "Output magnitude image")->required()->type_name("OUTPUT_IMAGE");

ITK_WASM_PARSE(pipeline);

auto magnitudeFilter = MagnitudeFilterType::New();
magnitudeFilter->SetInput(vectorImage.Get());
ITK_WASM_CATCH_EXCEPTION(pipeline, magnitudeFilter->UpdateLargestPossibleRegion());

typename ScalarImageType::ConstPointer magnitude = magnitudeFilter->GetOutput();
magnitudeImage.Set(magnitude);

return EXIT_SUCCESS;
}
};

int main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("vector-magnitude", "Generate a scalar magnitude image based on the input vector's norm.", argc, argv);

return itk::wasm::SupportInputImageTypes<PipelineFunctor,
itk::VariableLengthVector<double> >
::Dimensions<2U,3U,4U,5U,6U>("vector-image", pipeline);
}

0 comments on commit 3478c4a

Please sign in to comment.