0

I want to register 2 3D datasets that are read into numpy arrays and then given to the registrate() function. When I execute the code it prints the following log:

Installing all components. InstallingComponents was successful.

ELASTIX version: 5.0.1 Command line options from ElastixBase:
-fMask unspecified, so no fixed mask used
-mMask unspecified, so no moving mask used
-out D:\...\test/
-priority unspecified, so NORMAL process priority
-threads unspecified, so all available threads are used
Command line options from TransformBase:
-t0 unspecified, so no initial transform used

Reading images...
Reading images took 1 ms.

After that is just stops and goes back to the normal command line. It doesn't reach 'step2'.

Is there a way to backtrack what goes wrong and why?

def registrate(vol1, vol2, log_out_path):
    """

    Parameters
    ----------
    vol1: np.array, fixed image
    vol2: np.array, moving image
    log_out_path: str, path to the directory for the logfile

    Returns
    -------
    None
    """

    fixed_img = itk.GetImageFromArray(vol1)
    moving_img = itk.GetImageFromArray(vol2)

    print(type(moving_img))

    parameter_object_ = itk.ParameterObject.New()
    default_euler_ = parameter_object_.GetDefaultParameterMap("rigid", 3)
    parameter_object_.AddParameterMap(default_euler_)
    set_elastix_parameters(parameter_object_, 0, "euler")
    print("step1")
    result_image_, result_transform_parameters_ = itk.elastix_registration_method(fixed_img,  # fixed
                                                                                  moving_img,  # moving
                                                                                  parameter_object=parameter_object_,
                                                                                  log_to_console=True,
                                                                                  output_directory=log_out_path,
                                                                                  log_file_name=r"log.txt",
                                                                                  log_to_file=True,
                                                                                  )

    print("step2")
    deformed_image_ = apply_transformix([result_transform_parameters_], moving_img)
    print("Step3")
    save_volume(itk.GetArrayFromImage(deformed_image_), r"D:\...\deformed",
                     "de", True)
    save_volume(itk.GetArrayFromImage(result_image_),
                     r"D:\...\result_transformed", "re", True)


if __name__ == "__main__":

    moving_img = read_in_volume(r"D:\...\sample1")
    print("moving image read in correctly")
    fixed_img = read_in_volume(r"D:\...\sample2")
    print("fixed image read in correctly")

    registrate(fixed_img, moving_img, r"D:\...\test") 

The parameters used are the folowing:

def set_elastix_parameters(parameters, i, transform):
    # Image types
    parameters.SetParameter(i, "UseDirectionCosines", "true")
    # Main components
    parameters.SetParameter(i, "Registration", "MultiResolutionRegistration")
    # parameters.SetParameter(i, "Interpolator", "BSplineInterpolatorFloat") not avalaible for python
    parameters.SetParameter(i, "Interpolator", "LinearInterpolator")
    parameters.SetParameter(i, "ResampleInterpolator", "FinalBSplineInterpolator")
    parameters.SetParameter(i, "Resampler", "DefaultResampler")
    parameters.SetParameter(i, "FixedImageBSplineInterpolationOrder", "1")
    parameters.SetParameter(i, "BSplineInterpolationOrder", "1")
    parameters.SetParameter(i, "FixedImagePyramid", "FixedSmoothingImagePyramid")
    parameters.SetParameter(i, "MovingImagePyramid", "MovingSmoothingImagePyramid")
    parameters.SetParameter(i, "Optimizer", "AdaptiveStochasticGradientDescent")
    parameters.SetParameter(i, "Metric", "AdvancedMattesMutualInformation")
    parameters.SetParameter(i, "FixedInternalImagePixelType", "float")
    parameters.SetParameter(i, "MovingInternalImagePixelType", "float")

    # Transformation
    if transform == "euler":
        parameters.SetParameter(i, "Transform", "EulerTransform")
        parameters.SetParameter(i, "AutomaticTransformInitialization", "true")
    else:
        parameters.SetParameter(i, "Transform", "BSplineTransform")
        parameters.SetParameter(i, "BSplineTransformSplineOrder", "3")
    parameters.SetParameter(i, "FinalGridSpacingInPhysicalUnits", "12")
    parameters.SetParameter(i, "GridSpacingSchedule", ["16", "8", "4", "2", "1"])
    parameters.SetParameter(i, "HowToCombineTransforms", "Compose")
    parameters.SetParameter(i, "UseCyclicTransform", "false")
    # Similarity measure
    parameters.SetParameter(i, "NumberOfHistogramBins", "64")
    parameters.SetParameter(i, "NumberOfFixedHistogramBins", "64")
    parameters.SetParameter(i, "NumberOfMovingHistogramBins", "64")
    parameters.SetParameter(i, "ShowExactMetricValue", "false")
    parameters.SetParameter(i, "CheckNumberOfSamples", "true")
    # Multiresolution
    parameters.SetParameter(i, "NumberOfResolutions", "5")
    parameters.SetParameter(i, "ImagePyramidSchedule",
                            ["16", "16", "8", "8", "8", "4", "4", "4", "2", "2", "2", "2", "1", "1", "1"])
    # Optimizer
    parameters.SetParameter(i, "MaximumNumberOfIterations", "2000")
    parameters.SetParameter(i, "FixedLimitRangeRatio", "0.01")
    parameters.SetParameter(i, "MovingLimitRangeRatio", "0.01")
    parameters.SetParameter(i, "FixedKernelBSplineOrder", "0")
    parameters.SetParameter(i, "MovingKernelBSplineOrder", "3")
    parameters.SetParameter(i, "UseFastAndLowMemoryVersion", "true")
    parameters.SetParameter(i, "UseJacobianPreconditioning", "false")
    parameters.SetParameter(i, "FiniteDifferenceDerivative", "false")
    parameters.SetParameter(i, "SP_A", "20")
    parameters.SetParameter(i, "MaximumNumberOfSamplingAttempts", "0")
    parameters.SetParameter(i, "SigmoidInitialTime", "0")
    parameters.SetParameter(i, "MaxBandCovSize", "192")
    parameters.SetParameter(i, "NumberOfBandStructureSamples", "10")
    parameters.SetParameter(i, "UseAdaptiveStepSizes", "true")
    parameters.SetParameter(i, "AutomaticParameterEstimation", "true")
    parameters.SetParameter(i, "MaximumStepLength", "0.976562")
    parameters.SetParameter(i, "NumberOfGradientMeasurements", "0")
    parameters.SetParameter(i, "NumberOfJacobianMeasurements", "1000")
    parameters.SetParameter(i, "NumberOfSamplesForExactGradient", "100000")
    parameters.SetParameter(i, "SigmoidScaleFactor", "0.1")
    parameters.SetParameter(i, "ASGDParameterEstimationMethod", "Original")
    # Image sampling
    parameters.SetParameter(i, "UseRandomSampleRegion", "false")
    parameters.SetParameter(i, "NumberOfSpatialSamples", "4096")
    parameters.SetParameter(i, "NewSamplesEveryIteration", "true")
    parameters.SetParameter(i, "ImageSampler", "RandomCoordinate")
    # Interpolation and Resampling
    parameters.SetParameter(i, "FinalBSplineInterpolationOrder", "3")
    parameters.SetParameter(i, "DefaultPixelValue", "-1000")
    parameters.SetParameter(i, "WriteResultImage", "true")
    parameters.SetParameter(i, "WriteDVFFromCoeff", "true")
    parameters.SetParameter(i, "ResultImageFormat", "mhd")
  • It's possible the native code in `elastix_registration_method` crashes or otherwise exits the program. – AKX Jul 22 '21 at 10:13
  • Since its the last thing that gets executed before crashing and I didnt change anything in it, yeah thats probably the reason, but knowing that does not really help me preventing it from crashing. I would like to know why it does that :( – Kai Winkler Jul 22 '21 at 10:28
  • I'd maybe run the app under `strace` to see the final syscalls before its demise... – AKX Jul 22 '21 at 10:42

0 Answers0