Skip to content

Commit

Permalink
Do not import sitk.global.default_random_seed
Browse files Browse the repository at this point in the history
The variable is a integer and a deepcopy will be made.
  • Loading branch information
blowekamp committed Dec 8, 2020
1 parent 53b1ca5 commit 1d4e215
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion sitkibex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .globals import default_random_seed # noqa: F401
from .registration import registration
from .resample import resample

Expand Down
6 changes: 3 additions & 3 deletions sitkibex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
""" Provides command line interfaces for sitkibex registration algorithms"""

from .globals import default_random_seed # noqa: F401
import sitkibex.globals
import os
from os.path import basename
import SimpleITK as sitk
Expand Down Expand Up @@ -71,12 +71,12 @@ def cli(**kwargs):
def reg_cli(fixed_image, moving_image, output_transform, **kwargs):
"""Perform registration to solve for an OUTPUT_TRANSFORM mapping points from the FIXED_IMAGE to the MOVING_IMAGE."""
global default_random_seed
from .registration import registration
from sitkibex.registration import registration

args = _Bunch(kwargs)

if args.random:
default_random_seed = sitk.sitkWallClock
sitkibex.globals.default_random_seed = sitk.sitkWallClock

fixed_image = sitk.BinShrink(sitk.ReadImage(fixed_image, sitk.sitkFloat32), [args.bin, args.bin, 1])
moving_image = sitk.BinShrink(sitk.ReadImage(moving_image, sitk.sitkFloat32), [args.bin, args.bin, 1])
Expand Down
9 changes: 5 additions & 4 deletions sitkibex/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
from .registration_utilities import RegistrationCallbackManager
from . import image_utilities as imgf
from .globals import default_random_seed # noqa: F401
import sitkibex.globals
import logging

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,7 +97,7 @@ def register_3d(fixed_image,
zip(sampling_percentage_per_level, scale_factors)]))

reg.SetMetricSamplingPercentagePerLevel(sampling_percentage_per_level,
default_random_seed)
sitkibex.globals.default_random_seed)
reg.SetMetricSamplingStrategy(reg.REGULAR)
reg.SetShrinkFactorsPerLevel([f for f in scale_factors])
reg.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()
Expand Down Expand Up @@ -201,7 +201,8 @@ def register_as_2d_affine(fixed_image,
# We don't need more samples for larger image, so base the number of samples on the number of parameters
sampling_percentage = len(
initial_rigid.GetParameters()) * number_of_samples_per_parameter / fixed_2d.GetNumberOfPixels()
R.SetMetricSamplingPercentagePerLevel([min(0.10, sampling_percentage) for f in scale_factors], default_random_seed)
R.SetMetricSamplingPercentagePerLevel([min(0.10, sampling_percentage) for f in scale_factors],
sitkibex.globals.default_random_seed)
R.SetMetricSamplingStrategy(R.REGULAR)
R.SetShrinkFactorsPerLevel([1 for f in scale_factors])
R.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()
Expand Down Expand Up @@ -255,7 +256,7 @@ def register_as_2d_affine(fixed_image,
scale_factors = [8, 4, 2]
sampling_percentage = len(affine.GetParameters()) * number_of_samples_per_parameter / fixed_2d.GetNumberOfPixels()
R2.SetMetricSamplingPercentagePerLevel([min(0.10, sampling_percentage*f) for f in scale_factors],
default_random_seed)
sitkibex.globals.default_random_seed)
R2.SetMetricSamplingStrategy(R.RANDOM)
R2.SetShrinkFactorsPerLevel([f for f in scale_factors])
R2.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()
Expand Down

0 comments on commit 1d4e215

Please sign in to comment.