-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add SSSCI wrapping with Python test and baseline
- Loading branch information
Showing
11 changed files
with
326 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
517f382d498571f325ac804602aa373fd6db0786d25cd9e38c6097dd8251ea17f735b28670036bfab26cdddc94312486ef48899d089c8f4314baa41a6645b1ff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
637863e4b552e0d58c5ee9ce1f414b3b3c89b782a29a9503c0f2eca4fc23bbbf0ad8d741b5d884400e4aed71e8f43c3881113914c6ca34a79fcdc85272066179 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
itk_wrap_include("itkEuler3DTransform.h") | ||
|
||
# Explicitly override template method wrappings so that implicit | ||
# scalar type is always `double` for greatest precision. | ||
# Adds wrapping overrides to `itkSliceSeriesSpecialCoordinatesImage_ext.i` configured with | ||
# CMake for input to SWIG wrapping generation. | ||
# See `DECL_PYTHON_IMAGEBASE_CLASS` definition in `ITK/Wrapping/Generators/Python/PyBase/pyBase.i` | ||
# for precedent. | ||
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT " | ||
%inline %{ | ||
#include \"itkContinuousIndexSwigInterface.h\" | ||
%} | ||
|
||
%define DECL_PYTHON_SLICESERIESSPECIALCOORDINATESIMAGE_CLASS(swig_name, template_params) | ||
|
||
%extend swig_name { | ||
itkIndex##template_params TransformPhysicalPointToIndex(const itkPointD##template_params & point ) { | ||
return self->TransformPhysicalPointToIndex<double>( point ); | ||
} | ||
|
||
itkContinuousIndexD##template_params TransformPhysicalPointToContinuousIndex(const itkPointD##template_params & point ) { | ||
return self->TransformPhysicalPointToContinuousIndex<double>( point ); | ||
} | ||
|
||
itkPointD##template_params TransformContinuousIndexToPhysicalPoint(const itkContinuousIndexD##template_params & idx ) { | ||
return self->TransformContinuousIndexToPhysicalPoint<double>( idx ); | ||
} | ||
|
||
itkPointD##template_params TransformIndexToPhysicalPoint(const itkIndex##template_params & idx ) { | ||
return self->TransformIndexToPhysicalPoint<double>( idx ); | ||
} | ||
} | ||
|
||
%enddef | ||
") | ||
|
||
# Wrap class for UC and F. Dimension is always 3 (slice dimension 2). | ||
itk_wrap_class("itk::SliceSeriesSpecialCoordinatesImage" POINTER_WITH_SUPERCLASS) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template_params "itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>") | ||
itk_wrap_template("IUC3E3D" ${SSSCI_template_params}) | ||
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT "DECL_PYTHON_SLICESERIESSPECIALCOORDINATESIMAGE_CLASS(${WRAPPER_SWIG_NAME}IUC3E3D, 3)\n") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template_params "itk::Image<float, 2>, itk::Euler3DTransform<double>") | ||
itk_wrap_template("IF3E3D" ${SSSCI_template_params}) | ||
string(APPEND ITK_WRAP_PYTHON_SWIG_EXT "DECL_PYTHON_SLICESERIESSPECIALCOORDINATESIMAGE_CLASS(${WRAPPER_SWIG_NAME}IF3E3D, 3)\n") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
# Then wrap consuming filters in itkSliceSeriesSpecialCoordinatesImageFilters.wrap |
185 changes: 185 additions & 0 deletions
185
wrapping/itkSliceSeriesSpecialCoordinatesImageFilters.wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# ITK image filters wrapped for ITKUltrasound `itk::SliceSeriesSpecialCoordinatesImage` inputs. | ||
# Must be wrapped in a separate file after `itkSliceSeriesSpecialCoordinatesImage.wrap` so that | ||
# SWIG does not implicitly define erroneous overrides for template methods such as | ||
# `TransformPhysicalPointToContinuousIndex`, etc. | ||
|
||
# See `WRAPPER_SUBMODULE_ORDER` in CMakeLists.txt for where | ||
# `itkSliceSeriesSpecialCoordinatesImageFilters.wrap` is set to | ||
# be wrapped after `itkSliceSeriesSpecialCoordinatesImage.wrap`. | ||
|
||
itk_wrap_include("itkSliceSeriesSpecialCoordinatesImage.h") | ||
itk_wrap_include("itkEuler3DTransform.h") | ||
|
||
itk_wrap_class("itk::ImageSource" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D" "${SSSCI_template}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D" "${SSSCI_template}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkImage.h") | ||
itk_wrap_class("itk::ImageToImageFilter" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IUC3SSSCIUC3E3D" "itk::Image< unsigned char, 3 >, ${SSSCI_template}") | ||
# itk_wrap_template("SSSCIUC3E3DSSSCIUC3E3D" "${SSSCI_template}, ${SSSCI_template}") # procedural form defaults to this | ||
itk_wrap_template("SSSCIUC3E3DIUC3" "${SSSCI_template}, itk::Image< unsigned char, 3 >") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IF3SSSCIF3E3D" "itk::Image< float, 3 >, ${SSSCI_template}") | ||
# itk_wrap_template("SSSCIF3E3DSSSCIF3E3D" "${SSSCI_template}, ${SSSCI_template}") # procedural form defaults to this | ||
itk_wrap_template("SSSCIF3E3DIF3" "${SSSCI_template}, itk::Image< float, 3 >") | ||
endif() | ||
if(ITK_WRAP_unsigned_char AND ITK_WRAP_float) | ||
set(SSSCI_F "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3DIUC3" "${SSSCI_F}, itk::Image< unsigned char, 3 >") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::ImageFileReader" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D" "${SSSCI_template}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D" "${SSSCI_template}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::ImageFileWriter" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D" "${SSSCI_template}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D" "${SSSCI_template}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::CastImageFilter" POINTER_WITH_2_SUPERCLASSES) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IUC3SSSCIUC3E3D" "itk::Image< unsigned char, 3 >, ${SSSCI_template}") | ||
itk_wrap_template("SSSCIUC3E3DIUC3" "${SSSCI_template}, itk::Image< unsigned char, 3 >") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IF3SSSCIF3E3D" "itk::Image< float, 3 >, ${SSSCI_template}") | ||
itk_wrap_template("SSSCIF3E3DIF3" "${SSSCI_template}, itk::Image< float, 3 >") | ||
endif() | ||
if(ITK_WRAP_unsigned_char AND ITK_WRAP_float) | ||
set(SSSCI_UC "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
set(SSSCI_F "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3DSSSCIF3E3D" "${SSSCI_UC}, ${SSSCI_F}") | ||
itk_wrap_template("SSSCIF3E3DSSSCIUC3E3D" "${SSSCI_F}, ${SSSCI_UC}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::RescaleIntensityImageFilter" POINTER_WITH_2_SUPERCLASSES) | ||
if(ITK_WRAP_unsigned_char AND ITK_WRAP_float) | ||
set(SSSCI_UC "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
set(SSSCI_F "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3DSSSCIUC3E3D" "${SSSCI_F}, ${SSSCI_UC}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
# The rest is needed for ResampleImageFilter and interpolator functions | ||
itk_wrap_include("itkResampleImageFilter.h") | ||
itk_wrap_class("itk::ResampleImageFilter" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IUC3SSSCIUC3E3D" "itk::Image< unsigned char, 3 >, ${SSSCI_template}") | ||
itk_wrap_template("SSSCIUC3E3DIUC3" "${SSSCI_template}, itk::Image< unsigned char, 3 >") | ||
# itk_wrap_template("SSSCIUC3E3DSSSCIUC3E3D" "${SSSCI_template}, ${SSSCI_template}") # itk.resample_image_filter defaults to this | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("IF3SSSCIF3E3D" "itk::Image< float, 3 >, ${SSSCI_template}") | ||
itk_wrap_template("SSSCIF3E3DIF3" "${SSSCI_template}, itk::Image< float, 3 >") | ||
# itk_wrap_template("SSSCIF3E3DSSSCIF3E3D" "${SSSCI_template}, ${SSSCI_template}") # itk.resample_image_filter defaults to this | ||
endif() | ||
if(ITK_WRAP_unsigned_char AND ITK_WRAP_float) | ||
set(SSSCI_F "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3DIUC3" "${SSSCI_F}, itk::Image< unsigned char, 3 >") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::ImageFunction" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}, ${ITKT_D}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}, ${ITKT_D}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::InterpolateImageFunction" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::NearestNeighborInterpolateImageFunction" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::LinearInterpolateImageFunction" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::GaussianInterpolateImageFunction" POINTER) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${ITKM_D}" "${SSSCI_template}, ${ITKT_D}") | ||
endif() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkWindowedSincInterpolateImageFunction.h") | ||
set(window_functions "Hamming" "Cosine" "Welch" "Lanczos") | ||
set(radii 2 3) | ||
itk_wrap_class("itk::WindowedSincInterpolateImageFunction" POINTER) | ||
foreach(r ${radii}) # radius | ||
foreach(function ${window_functions}) | ||
if(ITK_WRAP_unsigned_char) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<unsigned char, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIUC3E3D${r}${function}" "${SSSCI_template}, ${r}, itk::Function::${function}WindowFunction< ${r} >") | ||
endif() | ||
if(ITK_WRAP_float) | ||
set(SSSCI_template "itk::SliceSeriesSpecialCoordinatesImage<itk::Image<float, 2>, itk::Euler3DTransform<double>>") | ||
itk_wrap_template("SSSCIF3E3D${r}${function}" "${SSSCI_template}, ${r}, itk::Function::${function}WindowFunction< ${r} >") | ||
endif() | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#========================================================================== | ||
# | ||
# 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. | ||
# | ||
#==========================================================================*/ | ||
|
||
import math | ||
import itk | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Estimate three back-scatter coefficients.") | ||
parser.add_argument("-i", "--input-image", required=True) | ||
parser.add_argument("-o", "--output-image", required=True) | ||
args = parser.parse_args() | ||
|
||
itk.auto_progress(2) | ||
|
||
# define the types we will use | ||
pixel_type = itk.UC | ||
dimension = 3 | ||
slice_type = itk.Image[pixel_type, dimension - 1] | ||
transform_type = itk.Euler3DTransform[itk.D] | ||
image_type = itk.SliceSeriesSpecialCoordinatesImage[slice_type, transform_type] | ||
|
||
# read the image | ||
reader = itk.UltrasoundImageFileReader[image_type].New() | ||
reader.SetFileName(args.input_image) | ||
reader.Update() | ||
image = reader.GetOutput() | ||
image.DisconnectPipeline() | ||
|
||
print("Verify resampling works with SliceSeriesSpecialCoordinatesImage input") | ||
output_size = [46, 55, 82] | ||
output_spacing = [1.0] * dimension | ||
output_origin = [0.0, -27.2693, -40.6222] | ||
result = itk.resample_image_filter(image, size=output_size, output_spacing=output_spacing, output_origin=output_origin) | ||
itk.imwrite(result, args.output_image) | ||
print(f"Image written to {args.output_image}") |