-
Notifications
You must be signed in to change notification settings - Fork 22
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
WIP: ENH: Add BlockMatching registration Python wrappings + example #150
Open
tbirdso
wants to merge
6
commits into
KitwareMedical:master
Choose a base branch
from
tbirdso:wrap-blockmatching
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3beeb9c
ENH: Add BlockMatching registration Python wrappings + example
tbirdso d863da8
WIP: Add image point wrapping for calculator member
tbirdso 025ad39
ENH: Rename BlockMatchingImageRegistrationMethod to mitigate collisions
tbirdso 8ac535a
Merge branch 'wrap-blockmatching-renaming' into wrap-blockmatching
tbirdso 4481861
WIP: Replace MetricImage SmartPointer types with pointers for wrapping
tbirdso 461879f
WIP: Fix ImageImagePointerType typename issue
tbirdso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
examples/itkBlockMatchingMultiResolutionImageRegistrationMethodTest.py
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,91 @@ | ||
#!/usr/bin/env python | ||
|
||
# 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 | ||
# | ||
# http://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 os | ||
from urllib.request import urlretrieve | ||
|
||
import itk | ||
|
||
# Verify wrapping succeeded | ||
assert 'MultiResolutionFixedBlockRadiusCalculator' in dir(itk.Ultrasound) | ||
|
||
# Get image input for registration | ||
FIXED_IMAGE_PATH = 'Input/rf_pre15.mha' | ||
MOVING_IMAGE_PATH = 'Input/rf_post15.mha' | ||
|
||
if not os.path.exists(FIXED_IMAGE_PATH): | ||
url = 'https://data.kitware.com/api/v1/file/58ee3b778d777f16d095fd8a/download' | ||
urlretrieve(url, FIXED_IMAGE_PATH) | ||
|
||
if not os.path.exists(MOVING_IMAGE_PATH): | ||
url = 'https://data.kitware.com/api/v1/file/58ee3b758d777f16d095fd87/download' | ||
urlretrieve(url, MOVING_IMAGE_PATH) | ||
|
||
fixed_image = itk.imread(FIXED_IMAGE_PATH, itk.D) | ||
moving_image = itk.imread(MOVING_IMAGE_PATH, itk.D) | ||
|
||
dimension = fixed_image.GetImageDimension() | ||
displacement_image_type = itk.Image[itk.Vector[itk.D,dimension],dimension] | ||
|
||
block_radius_calculator = itk.Ultrasound.MultiResolutionFixedBlockRadiusCalculator[type(fixed_image)].New() | ||
block_radius_calculator.SetRadius([12,4]) | ||
|
||
# Create schedule for iterative registration | ||
search_region_source = itk.Ultrasound.MultiResolutionFixedSearchRegionImageSource[type(fixed_image), | ||
type(fixed_image), | ||
displacement_image_type].New() | ||
pyramid_schedule = itk.Array2D[itk.UI]() | ||
pyramid_schedule.SetSize(3,2) | ||
pyramid_schedule.SetElement(0,0,3) | ||
pyramid_schedule.SetElement(0,1,2) | ||
pyramid_schedule.SetElement(1,0,2) | ||
pyramid_schedule.SetElement(1,1,1) | ||
pyramid_schedule.SetElement(2,0,1) | ||
pyramid_schedule.SetElement(2,1,1) | ||
|
||
search_region_source.SetPyramidSchedule(pyramid_schedule) | ||
search_region_source.SetSearchRegionRadiusSchedule([50,6]) | ||
search_region_source.SetOverlapSchedule(1.0) | ||
|
||
metric_image_filter = itk.Ultrasound.NormalizedCrossCorrelationNeighborhoodIteratorMetricImageFilter[type(fixed_image), | ||
type(fixed_image), | ||
type(fixed_image)].New() | ||
|
||
level_registration_method = itk.Ultrasound.ImageRegistrationMethod[type(fixed_image), | ||
type(fixed_image), | ||
type(fixed_image), | ||
displacement_image_type, | ||
itk.D].New() | ||
level_registration_method.SetMetricImageFilter(metric_image_filter) | ||
|
||
# Set up the multi-resolution registration object | ||
multi_res_registration_method = itk.Ultrasound.MultiResolutionImageRegistrationMethod[type(fixed_image), | ||
type(fixed_image), | ||
type(fixed_image), | ||
displacement_image_type, | ||
itk.D].New() | ||
multi_res_registration_method.SetFixedImage(fixed_image) | ||
multi_res_registration_method.SetMovingImage(moving_image) | ||
multi_res_registration_method.SetBlockRadiusCalculator(block_radius_calculator) | ||
multi_res_registration_method.SetSearchRegionImageSource(search_region_source) | ||
multi_res_registration_method.SetSchedules(pyramid_schedule, pyramid_schedule) | ||
multi_res_registration_method.SetImageRegistrationMethod(level_registration_method) | ||
|
||
# Run the actual registration | ||
multi_res_registration_method.Update() | ||
|
||
# Write out results | ||
itk.imwrite(multi_res_registration_method.GetOutput(), 'Output/rf_post15_registered.mha') |
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
13 changes: 13 additions & 0 deletions
13
wrapping/itkBlockMatchingBayesianRegularizationDisplacementCalculator.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,13 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
itk_wrap_include("itkImage.h") | ||
|
||
# Wrap desired class | ||
itk_wrap_include("itkBlockMatchingBayesianRegularizationDisplacementCalculator.h") | ||
itk_wrap_class("itk::BlockMatching::BayesianRegularizationDisplacementCalculator" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("I${ITKM_${t}}${d}I${ITKM_V${ITKM_${t}}${d}}${d}" | ||
"itk::Image<${ITKT_${t}},${d}>, itk::Image<${ITKT_V${ITKM_${t}}${d}},${d}>") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
13 changes: 13 additions & 0 deletions
13
wrapping/itkBlockMatchingMetricImageToDisplacementCalculator.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,13 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
|
||
itk_wrap_include("itkBlockMatchingMetricImageToDisplacementCalculator.h") | ||
itk_wrap_class("itk::BlockMatching::MetricImageToDisplacementCalculator" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(t2 ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("I${ITKM_${t}}${d}I${ITKM_V${t2}${d}}${d}" | ||
"${ITKT_I${ITKM_${t}}${d}}, ${ITKT_I${ITKM_V${t2}${d}}${d}}") | ||
endforeach() | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
20 changes: 20 additions & 0 deletions
20
wrapping/itkBlockMatchingMultiResolutionFixedBlockRadiusCalculator.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,20 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
itk_wrap_include("itkImage.h") | ||
|
||
itk_wrap_include("itkBlockMatchingMultiResolutionBlockRadiusCalculator.h") | ||
itk_wrap_class("itk::BlockMatching::MultiResolutionBlockRadiusCalculator" POINTER) | ||
foreach(t ${WRAP_ITK_SCALAR}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("I${ITKM_${t}}${d}" "itk::Image<${ITKT_${t}},${d}>") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkBlockMatchingMultiResolutionFixedBlockRadiusCalculator.h") | ||
itk_wrap_class("itk::BlockMatching::MultiResolutionFixedBlockRadiusCalculator" POINTER) | ||
foreach(t ${WRAP_ITK_SCALAR}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("I${ITKM_${t}}${d}" "itk::Image<${ITKT_${t}},${d}>") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
46 changes: 46 additions & 0 deletions
46
wrapping/itkBlockMatchingMultiResolutionFixedSearchRegionImageSource.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,46 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
|
||
itk_wrap_include("itkVector.h") | ||
itk_wrap_include("itkImage.h") | ||
itk_wrap_include("itkImageRegion.h") | ||
|
||
# Wrap for class template | ||
itk_wrap_include("itkImageRegion.h") | ||
itk_wrap_class("itk::Image" POINTER) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("IR${d}${d}" "itk::ImageRegion<${d}>, ${d}") | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkImageSource.h") | ||
itk_wrap_class("itk::ImageSource" POINTER) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("IIR${d}${d}" "itk::Image<itk::ImageRegion<${d}>,${d}>") | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
# Wrap class hierarchy | ||
itk_wrap_include("itkBlockMatchingMultiResolutionSearchRegionImageSource.h") | ||
itk_wrap_class("itk::BlockMatching::MultiResolutionSearchRegionImageSource" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
foreach(vt ${WRAP_ITK_VECTOR_REAL}) | ||
itk_wrap_template("I${ITKM_${t}}${d}I${ITKM_${t}}${d}I${ITKM_${vt}${d}}${d}" | ||
"itk::Image<${ITKT_${t}},${d}>, itk::Image<${ITKT_${t}},${d}>, itk::Image<${ITKT_${vt}${d}},${d}>") | ||
endforeach() | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
# Wrap class | ||
itk_wrap_include("itkBlockMatchingMultiResolutionFixedSearchRegionImageSource.h") | ||
itk_wrap_class("itk::BlockMatching::MultiResolutionFixedSearchRegionImageSource" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
foreach(vt ${WRAP_ITK_VECTOR_REAL}) | ||
itk_wrap_template("I${ITKM_${t}}${d}I${ITKM_${t}}${d}I${ITKM_${vt}${d}}${d}" | ||
"itk::Image<${ITKT_${t}},${d}>, itk::Image<${ITKT_${t}},${d}>, itk::Image<${ITKT_${vt}${d}},${d}>") | ||
endforeach() | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
61 changes: 61 additions & 0 deletions
61
wrapping/itkBlockMatchingMultiResolutionImageRegistrationMethod.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,61 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
itk_wrap_include("itkPoint.h") | ||
itk_wrap_include("itkSmartPointer.h") | ||
itk_wrap_include("itkImage.h") | ||
itk_wrap_include("itkImageRegion.h") | ||
|
||
# Wrap base classes for itk::BlockMatching::MetricImageToDisplacementCalculator public members | ||
#itk_wrap_class("itk::SmartPointer") | ||
# foreach(t ${WRAP_ITK_REAL}) | ||
# foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
# itk_wrap_template("I${ITKM_${t}}${d}" "itk::Image<${ITKT_${t}},${d}>") | ||
# endforeach() | ||
# endforeach() | ||
#itk_end_wrap_class() | ||
|
||
itk_wrap_class("itk::Image" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("P${ITKM_${t}}${d}${d}" "itk::Point<${ITKT_${t}},${d}>, ${d}") | ||
itk_wrap_template("SPI${ITKM_${t}}${d}${d}" "itk::SmartPointer<itk::Image<${ITKT_${t}},${d}>>, ${d}") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
# Wrap class hierarchy | ||
itk_wrap_include("itkImageToImageFilter.h") | ||
itk_wrap_class("itk::ImageToImageFilter" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
itk_wrap_template("IIR${d}${d}I${ITKM_V${t}${d}}${d}" | ||
"itk::Image<itk::ImageRegion<${d}>,${d}>, itk::Image<${ITKT_V${t}${d}},${d}>") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkBlockMatchingImageRegistrationMethod.h") | ||
itk_wrap_class("itk::BlockMatching::ImageRegistrationMethod" POINTER) | ||
tbirdso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
foreach(vt ${WRAP_ITK_VECTOR_REAL}) | ||
set(img_m "I${ITKM_${t}}${d}") | ||
set(img_t "itk::Image<${ITKT_${t}}, ${d}>") | ||
itk_wrap_template("${img_m}${img_m}${img_m}I${ITKM_${vt}${d}}${d}" | ||
"${img_t}, ${img_t}, ${img_t}, itk::Image<${ITKT_${vt}${d}},${d}>, ${ITKT_${t}}") | ||
endforeach() | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() | ||
|
||
# Wrap target class | ||
itk_wrap_include("itkBlockMatchingMultiResolutionImageRegistrationMethod.h") | ||
itk_wrap_class("itk::BlockMatching::MultiResolutionImageRegistrationMethod" POINTER) | ||
foreach(t ${WRAP_ITK_REAL}) | ||
foreach(d ${ITK_WRAP_IMAGE_DIMS}) | ||
set(img_m "I${ITKM_${t}}${d}") | ||
set(img_t "itk::Image<${ITKT_${t}}, ${d}>") | ||
itk_wrap_template("${img_m}${img_m}${img_m}I${ITKM_${vt}${d}}${d}" | ||
"${img_t}, ${img_t}, ${img_t}, itk::Image<${ITKT_V${t}${d}},${d}>, ${ITKT_${t}}") | ||
endforeach() | ||
endforeach() | ||
itk_end_wrap_class() |
16 changes: 16 additions & 0 deletions
16
...ping/itkBlockMatchingNormalizedCrossCorrelationNeighborhoodIteratorMetricImageFilter.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,16 @@ | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
|
||
itk_wrap_include("itkBlockMatchingMetricImageFilter.h") | ||
itk_wrap_class("itk::BlockMatching::MetricImageFilter" POINTER) | ||
itk_wrap_image_filter("${WRAP_ITK_REAL}" 3 2+) | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkBlockMatchingNormalizedCrossCorrelationMetricImageFilter.h") | ||
itk_wrap_class("itk::BlockMatching::NormalizedCrossCorrelationMetricImageFilter" POINTER) | ||
itk_wrap_image_filter("${WRAP_ITK_REAL}" 3 2+) | ||
itk_end_wrap_class() | ||
|
||
itk_wrap_include("itkBlockMatchingNormalizedCrossCorrelationNeighborhoodIteratorMetricImageFilter.h") | ||
itk_wrap_class("itk::BlockMatching::NormalizedCrossCorrelationNeighborhoodIteratorMetricImageFilter" POINTER) | ||
itk_wrap_image_filter("${WRAP_ITK_REAL}" 3 2+) | ||
itk_end_wrap_class() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing the following warnings when instantiating any BlockMatching class at runtime:
The warnings are introduced with these changes, but we are not explicitly wrapping
ImageToImageFilter
for these templates. Any thoughts on where this could be coming from?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😕 interesting. I do not see anything via inspection, either. 👁️ I will start a local build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thewtex Were you able to reproduce by any chance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not reproduce these warnings locally.
I did get
at build time.
And,
at run time.
We could likely replace the
SmartPointer
's with raw pointers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, thanks for taking a look. I'll try a clean build over the weekend and see if warnings still appear on my end.
My guess is that the point wrapping warnings are related to my having
ITK_WRAP_DOUBLE
enabled locally, I'll take a closer look.