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

Python examples #105

Closed
simeks opened this issue Oct 9, 2019 · 1 comment · Fixed by #127
Closed

Python examples #105

simeks opened this issue Oct 9, 2019 · 1 comment · Fixed by #127

Comments

@simeks
Copy link
Owner

simeks commented Oct 9, 2019

No description provided.

@simeks
Copy link
Owner Author

simeks commented Oct 25, 2019

Basic example:

import pydeform

settings = {
    'step_size': 0.2
}

fixed = pydeform.read_volume('fixed.nrrd')
moving = pydeform.read_volume('moving.nrrd')

df = pydeform.register(fixed, moving, settings = settings)

pydeform.write_volume('result.nrrd', df)

Image API:

import pydeform

# Read a volume
volume = pydeform.read_volume('image.nrrd')

# Creates a copy of the image data
array1 = np.array(volume)

# Reference to image data, enabling editing of 'img' object
array2 = np.array(volume, copy=False)
array2[0,0,0] = 1

# Create a new Volume object, for input to registration:
new_volume = pydeform.Volume(
    array1,
    origin = volume.origin,
    spacing = volume.spacing
)

# ...
pydeform.register(volume, new_volume)

Regularization weight map:

import pydeform

settings = {
    'step_size': 0.2
}

fixed = pydeform.read_volume('fixed.nrrd')
moving = pydeform.read_volume('moving.nrrd')

# Retrieve fixed image data
fixed_data = np.array(fixed)

# Create a regularization map
regmap = pydeform.Volume(
    (fixed_data > 0.5)*0.5, # Only regularize voxels with intensities larger than 0.5
)

# Don't forget meta data
regmap.copy_meta_from(fixed)

# Perform registration
df = pydeform.register(
    fixed,
    moving,
    regularization_map = regmap,
    settings = settings
)

pydeform.write_volume('result.nrrd', df)

@simeks simeks mentioned this issue Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant