Skip to content

Commit

Permalink
Try fix for random registration seeding
Browse files Browse the repository at this point in the history
Were getting Windows error
  • Loading branch information
matthew-brett committed Oct 3, 2024
1 parent da58993 commit c6d8fd6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nipy/algorithms/registration/histogram_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self, from_img, to_img,
from_bins=256, to_bins=None,
from_mask=None, to_mask=None,
similarity='crl1', interp='pv',
smooth=0, renormalize=False, dist=None):
smooth=0, renormalize=False, dist=None,
rng=None):
"""
Creates a new histogram registration object.
Expand Down Expand Up @@ -77,6 +78,8 @@ def __init__(self, from_img, to_img,
Standard deviation in millimeters of an isotropic Gaussian
kernel used to smooth the `To` image. If 0, no smoothing is
applied.
rng : None :class:`numpy.random.Generator`
Random number generator.
"""
# Function assumes xyx_affine for inputs
from_img = as_xyz_image(from_img)
Expand Down Expand Up @@ -125,6 +128,7 @@ def __init__(self, from_img, to_img,
# Set default registration parameters
self._set_interp(interp)
self._set_similarity(similarity, renormalize=renormalize, dist=dist)
self.rng = np.random.default_rng() if rng is None else rng

def _get_interp(self):
return list(interp_methods.keys())[\
Expand Down Expand Up @@ -306,7 +310,7 @@ def _eval(self, Tv):
trans_vox_coords = Tv.apply(self._vox_coords)
interp = self._interp
if self._interp < 0:
interp = - np.random.randint(MAX_INT)
interp = -self.rng.integers(MAX_INT)
_joint_histogram(self._joint_hist,
self._from_data.flat, # array iterator
self._to_data,
Expand Down

0 comments on commit c6d8fd6

Please sign in to comment.