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

Update the Python example and fix the CI #45

Merged
merged 2 commits into from
Jan 27, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/clang-format-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ jobs:
with:
fetch-depth: 1
- uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@master
with:
itk-branch: master
67 changes: 43 additions & 24 deletions examples/phase-symmetry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
#==========================================================================
# ==========================================================================
#
# Copyright NumFOCUS
#
Expand All @@ -15,20 +15,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
#==========================================================================*/
# ==========================================================================*/

import itk
import argparse
import numpy as np

def run(input_image_file, output_image_file,
wavelengths=None,
sigma=0.55,
polarity=0,
noise_threshold=10.0):
input_image = itk.imread(input_image_file, itk.ctype('float'))

def run(
input_image_file,
output_image_file,
wavelengths=None,
sigma=0.55,
polarity=0,
noise_threshold=10.0,
):
input_image = itk.imread(input_image_file, itk.ctype("float"))
boundary_condition = itk.PeriodicBoundaryCondition[type(input_image)]()
padded = itk.fft_pad_image_filter(input_image, boundary_condition=boundary_condition)
padded = itk.fft_pad_image_filter(
input_image, boundary_condition=boundary_condition
)

dimension = input_image.GetImageDimension()

Expand Down Expand Up @@ -64,23 +70,36 @@ def run(input_image_file, output_image_file,
output_image = phase_symmetry_filter.GetOutput()
itk.imwrite(output_image, output_image_file, True)


def main():
parser = argparse.ArgumentParser(description='Compute image phase symmetry.',
epilog='Example invocation: phase-symmetry.py --wavelengths 10 10 10 20 20 20 30 30 30 --sigma 0.25 --polarity 1 --noise-threshold 10.0 -- /tmp/HeartUltrasound.mha /tmp/HeartUltrasoundPhaseSymmetry.mha')

parser.add_argument('input_image')
parser.add_argument('output_image')
parser.add_argument('-w', '--wavelengths', dest='wavelengths', nargs='+',
type=float)
parser.add_argument('-s', '--sigma', dest='sigma', type=float, default=0.55)
parser.add_argument('-p', '--polarity', dest='polarity', type=int,
choices=[-1, 0, 1], default=0)
parser.add_argument('-n', '--noise-threshold', dest='noise', type=float,
default=10.0)
parser = argparse.ArgumentParser(
description="Compute image phase symmetry.",
epilog="Example invocation: phase-symmetry.py --wavelengths 10 10 10 20 20 20 30 30 30 --sigma 0.25 --polarity 1 --noise-threshold 10.0 -- /tmp/HeartUltrasound.mha /tmp/HeartUltrasoundPhaseSymmetry.mha",
)

parser.add_argument("input_image")
parser.add_argument("output_image")
parser.add_argument(
"-w", "--wavelengths", dest="wavelengths", nargs="+", type=float
)
parser.add_argument("-s", "--sigma", dest="sigma", type=float, default=0.55)
parser.add_argument(
"-p", "--polarity", dest="polarity", type=int, choices=[-1, 0, 1], default=0
)
parser.add_argument(
"-n", "--noise-threshold", dest="noise", type=float, default=10.0
)
args = parser.parse_args()

run(args.input_image, args.output_image, args.wavelengths, args.sigma,
args.polarity, args.noise)
run(
args.input_image,
args.output_image,
args.wavelengths,
args.sigma,
args.polarity,
args.noise,
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading