Skip to content

Commit

Permalink
Merge pull request #233 from pyplati/fix-cast-mask-negated
Browse files Browse the repository at this point in the history
Fix cast mask negated
  • Loading branch information
pchlap authored Oct 10, 2023
2 parents baa6716 + 196f573 commit 9be427a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 10 additions & 3 deletions platipy/imaging/label/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ def prime_encode_structure_list(structure_list):

# Multiply with the encoded image
prime_encoded_image = (
sitk.MaskNegated(prime_encoded_image, s_img_int)
+ sitk.Mask(prime_encoded_image, s_img_int) * prime * s_img_int
sitk.Cast(
sitk.MaskNegated(
sitk.Cast(prime_encoded_image, sitk.sitkUInt8),
sitk.Cast(s_img_int, sitk.sitkUInt8),
),
sitk.sitkUInt64,
)
+ sitk.Mask(prime_encoded_image, sitk.Cast(s_img_int, sitk.sitkUInt8))
* prime
* s_img_int
)

return prime_encoded_image
Expand Down Expand Up @@ -262,7 +270,6 @@ def binary_decode_image(binary_encoded_img):
num_nonzero_voxels = 1

for power in range(32):

# Calculate the region originally defined with this prime
s_arr = np.bitwise_and(binary_encoded_arr, 2 ** (power + 1))

Expand Down
11 changes: 3 additions & 8 deletions platipy/imaging/registration/deformable.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def multiscale_demons(
moving_images = []

for resolution, smoothing_sigma in zip(resolution_staging, smoothing_sigmas):

isotropic_voxel_size_mm = None
shrink_factor = None

Expand Down Expand Up @@ -123,9 +122,7 @@ def multiscale_demons(
)
initial_displacement_field.CopyInformation(fixed_image)
else:
initial_displacement_field = sitk.Resample(
initial_displacement_field, fixed_image
)
initial_displacement_field = sitk.Resample(initial_displacement_field, fixed_image)

# Run the registration.
# Start at the top of the pyramid and work our way down.
Expand All @@ -139,9 +136,7 @@ def multiscale_demons(
# we now apply the (total) transform to the moving image
dvf_total = sitk.Resample(dvf_total, f_image)

tfm_total = sitk.DisplacementFieldTransform(
sitk.Cast(dvf_total, sitk.sitkVectorFloat64)
)
tfm_total = sitk.DisplacementFieldTransform(sitk.Cast(dvf_total, sitk.sitkVectorFloat64))
m_image = sitk.Resample(m_image, tfm_total, interp_order)

# set up iteration staging
Expand Down Expand Up @@ -258,7 +253,7 @@ def fast_symmetric_forces_demons_registration(
regularisation_kernel_vox = np.array(regularisation_kernel_mm) / np.array(
fixed_image.GetSpacing()
)
print("regularisation_kernel_vox", regularisation_kernel_vox)

registration_method.SetStandardDeviations(regularisation_kernel_vox.tolist())

# This allows monitoring of the progress
Expand Down

0 comments on commit 9be427a

Please sign in to comment.