Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compare-images): add spatial tolerance #1181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/compare-images/compare-double-images.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ CompareImages(itk::wasm::Pipeline & pipeline, const TImage * testImage)
double differenceThreshold = 0.0;
pipeline.add_option("-d,--difference-threshold", differenceThreshold, "Intensity difference for pixels to be considered different.");

double spatialTolerance = 1e-8;
pipeline.add_option("-s,--spatial-tolerance", spatialTolerance, "Tolerance for comparing spatial overlap (origin and direction matrix).");

unsigned int radiusTolerance = 0;
pipeline.add_option("-r,--radius-tolerance", radiusTolerance, "Radius of the neighborhood around a pixel to search for similar intensity values.");

Expand All @@ -72,6 +75,9 @@ CompareImages(itk::wasm::Pipeline & pipeline, const TImage * testImage)

ITK_WASM_PARSE(pipeline);

itk::ImageToImageFilterCommon::SetGlobalDefaultDirectionTolerance(spatialTolerance);
itk::ImageToImageFilterCommon::SetGlobalDefaultCoordinateTolerance(spatialTolerance);

using DiffType = itk::Testing::ComparisonImageFilter<ImageType, ImageType>;
auto diff = DiffType::New();
diff->SetValidInput(testImage);
Expand Down Expand Up @@ -222,4 +228,4 @@ int main(int argc, char * argv[])

double>
::Dimensions<2U,3U,4U,5U,6U>("test-image", pipeline);
}
}

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def compare_double_images(
test_image: Image,
baseline_images: List[Image] = [],
difference_threshold: float = 0,
spatial_tolerance: float = 1e-08,
radius_tolerance: int = 0,
number_of_pixels_tolerance: int = 0,
ignore_boundary_pixels: bool = False,
Expand All @@ -27,6 +28,9 @@ def compare_double_images(
:param difference_threshold: Intensity difference for pixels to be considered different.
:type difference_threshold: float

:param spatial_tolerance: Tolerance for comparing spatial overlap (origin and direction matrix).
:type spatial_tolerance: float

:param radius_tolerance: Radius of the neighborhood around a pixel to search for similar intensity values.
:type radius_tolerance: int

Expand All @@ -46,5 +50,5 @@ def compare_double_images(
:rtype: Image
"""
func = environment_dispatch("itkwasm_compare_images", "compare_double_images")
output = func(test_image, baseline_images=baseline_images, difference_threshold=difference_threshold, radius_tolerance=radius_tolerance, number_of_pixels_tolerance=number_of_pixels_tolerance, ignore_boundary_pixels=ignore_boundary_pixels)
output = func(test_image, baseline_images=baseline_images, difference_threshold=difference_threshold, spatial_tolerance=spatial_tolerance, radius_tolerance=radius_tolerance, number_of_pixels_tolerance=number_of_pixels_tolerance, ignore_boundary_pixels=ignore_boundary_pixels)
return output
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async def compare_double_images_async(
test_image: Image,
baseline_images: List[Image] = [],
difference_threshold: float = 0,
spatial_tolerance: float = 1e-08,
radius_tolerance: int = 0,
number_of_pixels_tolerance: int = 0,
ignore_boundary_pixels: bool = False,
Expand All @@ -27,6 +28,9 @@ async def compare_double_images_async(
:param difference_threshold: Intensity difference for pixels to be considered different.
:type difference_threshold: float

:param spatial_tolerance: Tolerance for comparing spatial overlap (origin and direction matrix).
:type spatial_tolerance: float

:param radius_tolerance: Radius of the neighborhood around a pixel to search for similar intensity values.
:type radius_tolerance: int

Expand All @@ -46,5 +50,5 @@ async def compare_double_images_async(
:rtype: Image
"""
func = environment_dispatch("itkwasm_compare_images", "compare_double_images_async")
output = await func(test_image, baseline_images=baseline_images, difference_threshold=difference_threshold, radius_tolerance=radius_tolerance, number_of_pixels_tolerance=number_of_pixels_tolerance, ignore_boundary_pixels=ignore_boundary_pixels)
output = await func(test_image, baseline_images=baseline_images, difference_threshold=difference_threshold, spatial_tolerance=spatial_tolerance, radius_tolerance=radius_tolerance, number_of_pixels_tolerance=number_of_pixels_tolerance, ignore_boundary_pixels=ignore_boundary_pixels)
return output
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface CompareDoubleImagesNodeOptions {
/** Intensity difference for pixels to be considered different. */
differenceThreshold?: number

/** Tolerance for comparing spatial overlap (origin and direction matrix). */
spatialTolerance?: number

/** Radius of the neighborhood around a pixel to search for similar intensity values. */
radiusTolerance?: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ async function compareDoubleImagesNode(
if (typeof options.radiusTolerance !== "undefined") {
args.push('--radius-tolerance', options.radiusTolerance.toString())

}
if (typeof options.spatialTolerance !== "undefined") {
args.push('--spatial-tolerance', options.spatialTolerance.toString())

jadh4v marked this conversation as resolved.
Show resolved Hide resolved
}
if (typeof options.numberOfPixelsTolerance !== "undefined") {
args.push('--number-of-pixels-tolerance', options.numberOfPixelsTolerance.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface CompareDoubleImagesOptions extends WorkerPoolFunctionOption {
/** Intensity difference for pixels to be considered different. */
differenceThreshold?: number

/** Tolerance for comparing spatial overlap (origin and direction matrix). */
spatialTolerance?: number

/** Radius of the neighborhood around a pixel to search for similar intensity values. */
radiusTolerance?: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ async function compareDoubleImages(
if (typeof options.radiusTolerance !== "undefined") {
args.push('--radius-tolerance', options.radiusTolerance.toString())

}
if (typeof options.spatialTolerance !== "undefined") {
args.push('--spatial-tolerance', options.spatialTolerance.toString())

jadh4v marked this conversation as resolved.
Show resolved Hide resolved
}
if (typeof options.numberOfPixelsTolerance !== "undefined") {
args.push('--number-of-pixels-tolerance', options.numberOfPixelsTolerance.toString())
Expand Down
3 changes: 3 additions & 0 deletions packages/compare-images/typescript/src/index-node-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export type { VectorMagnitudeNodeResult }

import vectorMagnitudeNode from './vector-magnitude-node.js'
export { vectorMagnitudeNode }

import toScalarDouble from './to-scalar-double.js'
export { toScalarDouble }
jadh4v marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class CompareDoubleImagesController {
model.options.set("differenceThreshold", parseFloat(differenceThresholdElement.value))
})

const spatialToleranceElement = document.querySelector('#compareDoubleImagesInputs sl-input[name=spatial-tolerance]')
spatialToleranceElement.addEventListener('sl-change', (event) => {
model.options.set("spatialTolerance", parseFloat(spatialToleranceElement.value))
})

const radiusToleranceElement = document.querySelector('#compareDoubleImagesInputs sl-input[name=radius-tolerance]')
radiusToleranceElement.addEventListener('sl-change', (event) => {
model.options.set("radiusTolerance", parseInt(radiusToleranceElement.value))
Expand Down
Loading