From 614ae51b16c0140db8980d546985031b0bb5c27c Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Fri, 15 Aug 2025 18:57:26 -0400 Subject: [PATCH 1/2] Add wrapping for DisplacementFieldToBSplineImageFilter This filter has been noted as a useful algorithm to compute the inverse of displacement fields. It provides B-spline approximation of displacement fields which can be useful for image registration and field inversion. Converted from JSON to YAML configuration format to work with current main branch. --- ...DisplacementFieldToBSplineImageFilter.yaml | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml diff --git a/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml b/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml new file mode 100644 index 000000000..578620dd2 --- /dev/null +++ b/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml @@ -0,0 +1,152 @@ +name: DisplacementFieldToBSplineImageFilter +template_code_filename: ImageFilter +template_test_filename: ImageFilter +number_of_inputs: 0 +pixel_types: RealVectorPixelIDTypeList +filter_type: itk::DisplacementFieldToBSplineImageFilter< itk::Image< itk::Vector, InputImageType::ImageDimension > > +inputs: +- name: DisplacementField + type: Image + custom_itk_cast: |- + filter->SetDisplacementField( GetImageFromVectorImage(const_cast< InputImageType * >(this->CastImageToITK(*inDisplacementField).GetPointer()))); +- name: ConfidenceImage + type: Image + custom_itk_cast: |- + filter->SetConfidenceImage( this->CastImageToITK(*inConfidenceImage) ); + optional: true +include_files: +- itkVector.h +- sitkImageConvert.hxx +members: +- name: BSplineDomainOrigin + type: double + default: std::vector(3, 0.0) + dim_vec: true + doc: '' + itk_type: typename FilterType::OriginType + custom_itk_cast: "" + briefdescriptionSet: '' + detaileddescriptionSet: "" + briefdescriptionGet: '' + detaileddescriptionGet: "" +- name: BSplineDomainSpacing + type: double + default: std::vector(3, 1.0) + dim_vec: true + doc: '' + itk_type: typename FilterType::SpacingType + custom_itk_cast: "" + briefdescriptionSet: '' + detaileddescriptionSet: "" + briefdescriptionGet: '' + detaileddescriptionGet: "" +- name: BSplineDomainSize + type: uint32_t + default: std::vector(3, 0) + dim_vec: true + doc: '' + itk_type: typename FilterType::SizeType + custom_itk_cast: "" + briefdescriptionSet: '' + detaileddescriptionSet: "" + briefdescriptionGet: '' + detaileddescriptionGet: "" +- name: BSplineDomainDirection + type: std::vector + default: std::vector() + doc: Passing a zero sized array, defaults to identify matrix. The size of the array must exactly match the direction matrix + for the dimension of the image. + custom_itk_cast: |- + filter->SetBSplineDomain( sitkSTLVectorToITK( m_BSplineDomainOrigin ), sitkSTLVectorToITK( m_BSplineDomainSpacing ), sitkSTLVectorToITK( m_BSplineDomainSize), sitkSTLToITKDirection( this->m_BSplineDomainDirection ) ); + briefdescriptionSet: '' + detaileddescriptionSet: >- + Set the output direction cosine matrix. + briefdescriptionGet: '' + detaileddescriptionGet: "" +- name: NumberOfFittingLevels + type: uint32_t + default: 1u + doc: '' + briefdescriptionSet: '' + detaileddescriptionSet: >- + Set the number of fitting levels. One of the contributions of N4 is the introduction of a multi-scale approach to fitting. + This allows one to specify a B-spline mesh size for initial fitting followed by a doubling of the mesh resolution for + each subsequent fitting level. Default = 1 level. + briefdescriptionGet: '' + detaileddescriptionGet: >- + Get the number of fitting levels. One of the contributions of N4 is the introduction of a multi-scale approach to fitting. + This allows one to specify a B-spline mesh size for initial fitting followed by a doubling of the mesh resolution for + each subsequent fitting level. Default = 1 level. +- name: NumberOfControlPoints + type: uint32_t + default: std::vector(3, 4) + dim_vec: true + doc: '' + itk_type: typename FilterType::ArrayType + briefdescriptionSet: '' + detaileddescriptionSet: >- + Set the control point grid size defining the B-spline estimate of the scalar bias field. In each dimension, the B-spline + mesh size is equal to the number of control points in that dimension minus the spline order. Default = 4 control points + in each dimension for a mesh size of 1 in each dimension. + briefdescriptionGet: '' + detaileddescriptionGet: >- + Get the control point grid size defining the B-spline estimate of the scalar bias field. In each dimension, the B-spline + mesh size is equal to the number of control points in that dimension minus the spline order. Default = 4 control points + in each dimension for a mesh size of 1 in each dimension. +- name: SplineOrder + type: uint32_t + default: 3u + doc: '' + briefdescriptionSet: '' + detaileddescriptionSet: >- + Set the spline order defining the bias field estimate. Default = 3. + briefdescriptionGet: '' + detaileddescriptionGet: >- + Get the spline order defining the bias field estimate. Default = 3. +- name: EnforceStationaryBoundary + type: bool + default: 'true' + briefdescriptionSet: '' + detaileddescriptionSet: >- + Enforce stationary boundary conditions. Default = false. + briefdescriptionGet: '' + detaileddescriptionGet: >- + Enforce stationary boundary conditions. Default = false. +- name: EstimateInverse + type: bool + default: 'false' + briefdescriptionSet: '' + detaileddescriptionSet: >- + Estimate the inverse field instead of the forward field. Default = false. + briefdescriptionGet: '' + detaileddescriptionGet: >- + Estimate the inverse field instead of the forward field. Default = false. +- name: UseInputFieldToDefineTheBSplineDomain + type: bool + default: 'false' + briefdescriptionSet: '' + detaileddescriptionSet: "" + briefdescriptionGet: '' + detaileddescriptionGet: "" +measurements: [] +custom_methods: +- name: SetBSplineDomainFromImage + doc: This methods sets the size, origin, spacing and direction to that of the provided image for the BSpline domain. + return_type: void + parameters: + - type: const Image & + var_name: refImage + body: |- + this->SetBSplineDomainSize( refImage.GetSize() ); + this->SetBSplineDomainOrigin( refImage.GetOrigin() ); + this->SetBSplineDomainSpacing( refImage.GetSpacing() ); + this->SetBSplineDomainDirection( refImage.GetDirection() ); +tests: [] +briefdescription: Class which takes a dense displacement field image and/or a set of points with associated displacements + and smooths them using B-splines. The inverse can also be estimated. +detaileddescription: >- + \author Nick Tustison +itk_module: ITKDisplacementField +itk_group: DisplacementField +in_place: false From 8737e04eaa49d5754b65cad8918e6b36532579e7 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Thu, 21 Aug 2025 18:30:04 -0400 Subject: [PATCH 2/2] Add test cases for DisplacementFieldToBSpline filter --- ...DisplacementFieldToBSplineImageFilter.yaml | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml b/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml index 578620dd2..5f4785b32 100644 --- a/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml +++ b/Code/BasicFilters/yaml/DisplacementFieldToBSplineImageFilter.yaml @@ -142,7 +142,63 @@ custom_methods: this->SetBSplineDomainOrigin( refImage.GetOrigin() ); this->SetBSplineDomainSpacing( refImage.GetSpacing() ); this->SetBSplineDomainDirection( refImage.GetDirection() ); -tests: [] +tests: +- tag: displacement + description: Test with displacement field data + settings: + - parameter: SplineOrder + type: uint32_t + value: 3 + - parameter: NumberOfControlPoints + type: uint32_t + dim_vec: true + value: + - 4 + - 4 + - parameter: NumberOfFittingLevels + type: uint32_t + value: 1 + - parameter: UseInputFieldToDefineTheBSplineDomain + type: bool + value: "true" + python_value: True + tolerance: 0.01 + inputs: + - Input/displacement.mha +- tag: displacement_manual_domain + description: Test with manually specified B-spline domain + settings: + - parameter: SplineOrder + type: uint32_t + value: 3 + - parameter: NumberOfFittingLevels + type: uint32_t + value: 2 + - parameter: UseInputFieldToDefineTheBSplineDomain + type: bool + value: "false" + python_value: False + - parameter: BSplineDomainOrigin + type: double + dim_vec: true + value: + - 0.0 + - 0.0 + - parameter: BSplineDomainSpacing + type: double + dim_vec: true + value: + - 10.0 + - 10.0 + - parameter: BSplineDomainSize + type: uint32_t + dim_vec: true + value: + - 13 + - 13 + tolerance: 0.01 + inputs: + - Input/displacement.mha briefdescription: Class which takes a dense displacement field image and/or a set of points with associated displacements and smooths them using B-splines. The inverse can also be estimated. detaileddescription: >-