Commit eeef2074 authored by Kasper Marstal's avatar Kasper Marstal

ENH: Fix rescale and invert intensity for ITKv4 ANTS

parent 8a69bfd8
...@@ -427,6 +427,7 @@ class DIRLAB(Dataset): ...@@ -427,6 +427,7 @@ class DIRLAB(Dataset):
) )
else: else:
# If no mask was provided, just generate mask filled with ones # If no mask was provided, just generate mask filled with ones
logging.warning('Masks not found for DIRLAB. Creating mask with elements set to one.')
mask_file_names = [ mask_file_names = [
create_mask_by_size(image_file_names[i], create_mask_by_size(image_file_names[i],
os.path.join(output_directory, 'tmp', 'masks', os.path.join(output_directory, 'tmp', 'masks',
...@@ -717,6 +718,7 @@ class POPI(Dataset): ...@@ -717,6 +718,7 @@ class POPI(Dataset):
os.path.join(mask_directory, sub_directory, 'mhd', '50.mhd')) os.path.join(mask_directory, sub_directory, 'mhd', '50.mhd'))
else: else:
# If no mask was provided, just generate mask filled with ones # If no mask was provided, just generate mask filled with ones
logging.warning('Masks not found for POPI. Creating mask with elements set to one.')
mask_file_names = [ mask_file_names = [
create_mask_by_size(image_file_names[i], create_mask_by_size(image_file_names[i],
os.path.join(output_directory, 'tmp', 'masks', os.path.join(output_directory, 'tmp', 'masks',
......
...@@ -39,8 +39,14 @@ def hausdorff(superelastix, point_sets, deformation_field_file_names): ...@@ -39,8 +39,14 @@ def hausdorff(superelastix, point_sets, deformation_field_file_names):
def inverse_consistency(superelastix, displacement_field_file_names, mask_file_names): def inverse_consistency(superelastix, displacement_field_file_names, mask_file_names):
try: try:
composed_0 = sitk.GetArrayFromImage(sitk.ReadImage(compose_displacement_fields(superelastix, displacement_field_file_names[0], displacement_field_file_names[1]))) composed_0 = sitk.GetArrayFromImage(
composed_1 = sitk.GetArrayFromImage(sitk.ReadImage(compose_displacement_fields(superelastix, displacement_field_file_names[1], displacement_field_file_names[0]))) sitk.ReadImage(
compose_displacement_fields(
superelastix, displacement_field_file_names[0], displacement_field_file_names[1])))
composed_1 = sitk.GetArrayFromImage(
sitk.ReadImage(
compose_displacement_fields(
superelastix, displacement_field_file_names[1], displacement_field_file_names[0])))
except Exception: except Exception:
return ( return (
{'3. InverseConsistency': np.NaN}, {'3. InverseConsistency': np.NaN},
...@@ -48,18 +54,14 @@ def inverse_consistency(superelastix, displacement_field_file_names, mask_file_n ...@@ -48,18 +54,14 @@ def inverse_consistency(superelastix, displacement_field_file_names, mask_file_n
) )
mask_0 = sitk.GetArrayFromImage(sitk.ReadImage(mask_file_names[0])) > 0 mask_0 = sitk.GetArrayFromImage(sitk.ReadImage(mask_file_names[0])) > 0
norm_0 = np.linalg.norm(composed_0, axis=-1) norm_0 = np.linalg.norm(composed_0[mask_0], axis=-1).flatten()
norm_0 = norm_0[mask_0]
norm_0 = np.ma.array(norm_0, mask=np.isnan(norm_0))
mask_1 = sitk.GetArrayFromImage(sitk.ReadImage(mask_file_names[1])) > 0 mask_1 = sitk.GetArrayFromImage(sitk.ReadImage(mask_file_names[1])) > 0
norm_1 = np.linalg.norm(composed_1, axis=-1) norm_1 = np.linalg.norm(composed_1[mask_1], axis=-1).flatten()
norm_1 = norm_1[mask_1]
norm_1 = np.ma.array(norm_1, mask=np.isnan(norm_1))
return ( return (
{'3. InverseConsistency': np.mean(norm_0)}, {'3. InverseConsistency': float(np.nanmean(norm_0))},
{'3. InverseConsistency': np.mean(norm_1)} {'3. InverseConsistency': float(np.nanmean(norm_1))}
) )
......
{
"Datasets": [
"LPBA40",
"IBSR18",
"CUMC12",
"MGH10",
"HAMMERS"
],
"Components": [
{
"Name": "MultiStageTransformController",
"NameOfClass": "NiftyregItkMultiStageComponent",
"ExecutionOrder": [ "RegistrationMethod1", "RegistrationMethod2" ],
"Dimensionality": "3",
"PixelType": "double"
},
{
"Name": "RegistrationMethod1",
"NameOfClass": "NiftyregAladinComponent",
"MaximumNumberOfIterations": "1"
},
{
"Name": "RegistrationMethod2",
"NameOfClass": "ItkImageRegistrationMethodv4Component",
"InternalComputationValueType": "double",
"Dimensionality": "3",
"PixelType": "float",
"NumberOfLevels": "3",
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "4", "2", "1" ],
"RescaleIntensity": ["0", "1"]
},
{
"Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"Dimensionality": "3"
},
{
"Name": "FixedImage",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "MovingImage",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "FixedMask",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"PixelType": "unsigned char",
"Dimensionality": "3"
},
{
"Name": "MovingMask",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"PixelType": "unsigned char",
"Dimensionality": "3"
},
{
"Name": "Metric2",
"NameOfClass": "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "Transform2",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformComponent",
"GaussianSmoothingVarianceForTheUpdateField": "2.0",
"GaussianSmoothingVarianceForTheConstantVelocityField": "1.0"
},
{
"Name": "Optimizer2",
"NameOfClass": "ItkGradientDescentOptimizerv4Component",
"InternalComputationValueType": "double",
"MaximumNumberOfIterations": "8",
"MaximumStepSizeInPhysicalUnits": "1.0",
"LearningRate": "0.25",
"EstimateScales": "True",
"EstimateLearningRate": "False"
},
{
"Name": "DisplacementField",
"NameOfClass": "ItkDisplacementFieldSinkComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "TransformToDisplacementField",
"NameOfClass": "ItkTransformDisplacementFilterComponent",
"Dimensionality": "3",
"PixelType": "float"
}
],
"Connections": [
{
"Out": "TransformResolutionAdaptor",
"In": "RegistrationMethod2"
},
{
"Out": "FixedImage",
"In": "TransformResolutionAdaptor",
"NameOfInterface": "itkImageDomainFixedInterface"
},
{
"Out": "FixedImage",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregReferenceImageInterface"
},
{
"Out": "MovingImage",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregFloatingImageInterface"
},
{
"Out": "FixedMask",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregInputMaskInterface"
},
{
"Out": "FixedImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageFixedInterface"
},
{
"Out": "MovingImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageMovingInterface"
},
{
"Out": "Metric2",
"In": "RegistrationMethod2"
},
{
"Out": "Transform2",
"In": "RegistrationMethod2"
},
{
"Out": "Optimizer2",
"In": "RegistrationMethod2"
},
{
"Out": "FixedImage",
"In": "Transform2"
},
{
"Out": "RegistrationMethod1",
"In": "MultiStageTransformController"
},
{
"Out": "RegistrationMethod2",
"In": "MultiStageTransformController"
},
{
"Out": "MultiStageTransformController",
"In": "TransformToDisplacementField"
},
{
"Out": "FixedImage",
"In": "TransformToDisplacementField",
"NameOfInterface": "itkImageDomainFixedInterface"
},
{
"Out": "TransformToDisplacementField",
"In": "DisplacementField"
},
{
"Out": "FixedMask",
"In": "Metric2"
},
{
"Out": "FixedMask",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregInputMaskInterface"
}
]
}
{ {
"Datasets": ["POPI", "DIRLAB", "EMPIRE", "LPBA40", "IBSR18", "CUMC12", "MGH10", "SPREAD", "HAMMERS"], "Datasets": ["POPI", "DIRLAB", "EMPIRE", "SPREAD" ],
"Components": [ "Components": [
{ {
"Name": "RegistrationMethod", "Name": "RegistrationMethod",
"NameOfClass": "ItkImageRegistrationMethodv4Component", "NameOfClass": "ItkImageRegistrationMethodv4Component",
"NumberOfLevels": "4" , "NumberOfLevels": "4" ,
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ], "ShrinkFactorsPerLevel": [ "12", "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "8", "4", "2", "1" ], "SmoothingSigmasPerLevel": [ "8", "4", "2", "1" ],
"Dimensionality": "3", "Dimensionality": "3",
"RescaleIntensity": ["0", "1"], "RescaleIntensity": ["0", "1"],
"InvertIntensity": "True", "InvertIntensity": ["True"]
"MetricSamplingPercentage": "0.2",
"MetricSamplingStrategy": "Random"
}, },
{ {
"Name": "FixedImageCropper", "Name": "FixedImageCropper",
...@@ -62,7 +60,7 @@ ...@@ -62,7 +60,7 @@
{ {
"Name": "Optimizer", "Name": "Optimizer",
"NameOfClass": "ItkGradientDescentOptimizerv4Component", "NameOfClass": "ItkGradientDescentOptimizerv4Component",
"NumberOfIterations": "48", "NumberOfIterations": "8",
"LearningRate": "0.25", "LearningRate": "0.25",
"EstimateScales": "True", "EstimateScales": "True",
"EstimateLearningRate": "False" "EstimateLearningRate": "False"
...@@ -72,13 +70,13 @@ ...@@ -72,13 +70,13 @@
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformComponent", "NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformComponent",
"InternalComputationValueType": "double", "InternalComputationValueType": "double",
"Dimensionality": "3", "Dimensionality": "3",
"GaussianSmoothingVarianceForTheConstantVelocityField": "1.0", "GaussianSmoothingVarianceForTheUpdateField": "3.0",
"GaussianSmoothingVarianceForTheUpdateField": "2.0" "GaussianSmoothingVarianceForTheConstantVelocityField": "0.5"
}, },
{ {
"Name": "TransformResolutionAdaptor", "Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent", "NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ], "ShrinkFactorsPerLevel": [ "12", "8", "4", "2" ],
"Dimensionality": "3" "Dimensionality": "3"
}, },
{ {
...@@ -165,10 +163,6 @@ ...@@ -165,10 +163,6 @@
{ {
"Out": "FixedMask", "Out": "FixedMask",
"In": "Metric" "In": "Metric"
},
{
"Out": "MovingMask",
"In": "Metric"
} }
] ]
} }
{
"Datasets": [
"LPBA40",
"IBSR18",
"CUMC12",
"MGH10",
"HAMMERS"
],
"Components": [
{
"Name": "MultiStageTransformController",
"NameOfClass": "NiftyregItkMultiStageComponent",
"ExecutionOrder": [ "RegistrationMethod1", "RegistrationMethod2" ],
"Dimensionality": "3",
"PixelType": "double"
},
{
"Name": "RegistrationMethod1",
"NameOfClass": "NiftyregAladinComponent",
"MaximumNumberOfIterations": "1"
},
{
"Name": "RegistrationMethod2",
"NameOfClass": "ItkImageRegistrationMethodv4Component",
"InternalComputationValueType": "double",
"Dimensionality": "3",
"PixelType": "float",
"NumberOfLevels": "3",
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "4", "2", "1" ],
"RescaleIntensity": ["0", "1"]
},
{
"Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"Dimensionality": "3"
},
{
"Name": "FixedImage",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "MovingImage",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "FixedMask",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"PixelType": "unsigned char",
"Dimensionality": "3"
},
{
"Name": "MovingMask",
"NameOfClass": "ItkToNiftiImageHybridSourceComponent",
"PixelType": "unsigned char",
"Dimensionality": "3"
},
{
"Name": "Metric2",
"NameOfClass": "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "Transform2",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformComponent",
"GaussianSmoothingVarianceForTheUpdateField": "2.0",
"GaussianSmoothingVarianceForTheConstantVelocityField": "1.0"
},
{
"Name": "Optimizer2",
"NameOfClass": "ItkGradientDescentOptimizerv4Component",
"InternalComputationValueType": "double",
"MaximumNumberOfIterations": "8",
"MaximumStepSizeInPhysicalUnits": "1.0",
"LearningRate": "0.25",
"EstimateScales": "True",
"EstimateLearningRate": "False"
},
{
"Name": "DisplacementField",
"NameOfClass": "ItkDisplacementFieldSinkComponent",
"Dimensionality": "3",
"PixelType": "float"
},
{
"Name": "TransformToDisplacementField",
"NameOfClass": "ItkTransformDisplacementFilterComponent",
"Dimensionality": "3",
"PixelType": "float"
}
],
"Connections": [
{
"Out": "TransformResolutionAdaptor",
"In": "RegistrationMethod2"
},
{
"Out": "FixedImage",
"In": "TransformResolutionAdaptor",
"NameOfInterface": "itkImageDomainFixedInterface"
},
{
"Out": "FixedImage",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregReferenceImageInterface"
},
{
"Out": "MovingImage",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregFloatingImageInterface"
},
{
"Out": "FixedMask",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregInputMaskInterface"
},
{
"Out": "FixedImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageFixedInterface"
},
{
"Out": "MovingImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageMovingInterface"
},
{
"Out": "Metric2",
"In": "RegistrationMethod2"
},
{
"Out": "Transform2",
"In": "RegistrationMethod2"
},
{
"Out": "Optimizer2",
"In": "RegistrationMethod2"
},
{
"Out": "FixedImage",
"In": "Transform2"
},
{
"Out": "RegistrationMethod1",
"In": "MultiStageTransformController"
},
{
"Out": "RegistrationMethod2",
"In": "MultiStageTransformController"
},
{
"Out": "MultiStageTransformController",
"In": "TransformToDisplacementField"
},
{
"Out": "FixedImage",
"In": "TransformToDisplacementField",
"NameOfInterface": "itkImageDomainFixedInterface"
},
{
"Out": "TransformToDisplacementField",
"In": "DisplacementField"
},
{
"Out": "FixedMask",
"In": "Metric2"
},
{
"Out": "FixedMask",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregInputMaskInterface"
}
]
}
...@@ -3,12 +3,7 @@ ...@@ -3,12 +3,7 @@
"POPI", "POPI",
"DIRLAB", "DIRLAB",
"EMPIRE", "EMPIRE",
"LPBA40", "SPREAD"
"IBSR18",
"CUMC12",
"MGH10",
"SPREAD",
"HAMMERS"
], ],
"Components": [ "Components": [
{ {
...@@ -21,7 +16,7 @@ ...@@ -21,7 +16,7 @@
{ {
"Name": "RegistrationMethod1", "Name": "RegistrationMethod1",
"NameOfClass": "NiftyregAladinComponent", "NameOfClass": "NiftyregAladinComponent",
"MaximumNumberOfIterations": "16" "MaximumNumberOfIterations": "1"
}, },
{ {
"Name": "RegistrationMethod2", "Name": "RegistrationMethod2",
...@@ -29,18 +24,16 @@ ...@@ -29,18 +24,16 @@
"InternalComputationValueType": "double", "InternalComputationValueType": "double",
"Dimensionality": "3", "Dimensionality": "3",
"PixelType": "float", "PixelType": "float",
"NumberOfLevels": "4", "NumberOfLevels": "3",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ], "ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "8", "4", "2", "1" ], "SmoothingSigmasPerLevel": [ "4", "2", "1" ],
"RescaleIntensity": ["0", "1"], "RescaleIntensity": ["0", "1"],
"InvertIntensity": "True", "InvertIntensity": "True"
"MetricSamplingPercentage": "0.2",
"MetricSamplingStrategy": "Random"
}, },
{ {
"Name": "TransformResolutionAdaptor", "Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent", "NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ], "ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"Dimensionality": "3" "Dimensionality": "3"
}, },
{ {
...@@ -67,20 +60,6 @@ ...@@ -67,20 +60,6 @@
"PixelType": "unsigned char", "PixelType": "unsigned char",
"Dimensionality": "3" "Dimensionality": "3"
}, },
{
"Name": "FixedImageCropper",
"NameOfClass": "ItkCropperComponent",
"Dimensionality": "3",
"PixelType": "float",
"Pad": 8
},
{
"Name": "MovingImageCropper",
"NameOfClass": "ItkCropperComponent",
"Dimensionality": "3",
"PixelType": "float",
"Pad": 8
},
{ {
"Name": "Metric2", "Name": "Metric2",
"NameOfClass": "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component", "NameOfClass": "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component",
...@@ -97,7 +76,7 @@ ...@@ -97,7 +76,7 @@
"Name": "Optimizer2", "Name": "Optimizer2",
"NameOfClass": "ItkGradientDescentOptimizerv4Component", "NameOfClass": "ItkGradientDescentOptimizerv4Component",
"InternalComputationValueType": "double", "InternalComputationValueType": "double",
"MaximumNumberOfIterations": "16", "MaximumNumberOfIterations": "8",
"MaximumStepSizeInPhysicalUnits": "1.0", "MaximumStepSizeInPhysicalUnits": "1.0",
"LearningRate": "0.25", "LearningRate": "0.25",
"EstimateScales": "True", "EstimateScales": "True",
...@@ -123,30 +102,6 @@ ...@@ -123,30 +102,6 @@
}, },
{ {
"Out": "FixedImage", "Out": "FixedImage",
"In": "FixedImageCropper",
"NameOfInterface": "itkImageInterface"
},
{
"Out": "FixedMask",
"In": "FixedImageCropper",
"NameOfInterface": "itkImageFixedMaskInterface"