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):
)
else:
# 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 = [
create_mask_by_size(image_file_names[i],
os.path.join(output_directory, 'tmp', 'masks',
......@@ -717,6 +718,7 @@ class POPI(Dataset):
os.path.join(mask_directory, sub_directory, 'mhd', '50.mhd'))
else:
# 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 = [
create_mask_by_size(image_file_names[i],
os.path.join(output_directory, 'tmp', 'masks',
......
......@@ -39,8 +39,14 @@ def hausdorff(superelastix, point_sets, deformation_field_file_names):
def inverse_consistency(superelastix, displacement_field_file_names, mask_file_names):
try:
composed_0 = sitk.GetArrayFromImage(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])))
composed_0 = sitk.GetArrayFromImage(
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:
return (
{'3. InverseConsistency': np.NaN},
......@@ -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
norm_0 = np.linalg.norm(composed_0, axis=-1)
norm_0 = norm_0[mask_0]
norm_0 = np.ma.array(norm_0, mask=np.isnan(norm_0))
norm_0 = np.linalg.norm(composed_0[mask_0], axis=-1).flatten()
mask_1 = sitk.GetArrayFromImage(sitk.ReadImage(mask_file_names[1])) > 0
norm_1 = np.linalg.norm(composed_1, axis=-1)
norm_1 = norm_1[mask_1]
norm_1 = np.ma.array(norm_1, mask=np.isnan(norm_1))
norm_1 = np.linalg.norm(composed_1[mask_1], axis=-1).flatten()
return (
{'3. InverseConsistency': np.mean(norm_0)},
{'3. InverseConsistency': np.mean(norm_1)}
{'3. InverseConsistency': float(np.nanmean(norm_0))},
{'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": [
{
"Name": "RegistrationMethod",
"NameOfClass": "ItkImageRegistrationMethodv4Component",
"NumberOfLevels": "4" ,
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ],
"ShrinkFactorsPerLevel": [ "12", "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "8", "4", "2", "1" ],
"Dimensionality": "3",
"RescaleIntensity": ["0", "1"],
"InvertIntensity": "True",
"MetricSamplingPercentage": "0.2",
"MetricSamplingStrategy": "Random"
"InvertIntensity": ["True"]
},
{
"Name": "FixedImageCropper",
......@@ -62,7 +60,7 @@
{
"Name": "Optimizer",
"NameOfClass": "ItkGradientDescentOptimizerv4Component",
"NumberOfIterations": "48",
"NumberOfIterations": "8",
"LearningRate": "0.25",
"EstimateScales": "True",
"EstimateLearningRate": "False"
......@@ -72,13 +70,13 @@
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformComponent",
"InternalComputationValueType": "double",
"Dimensionality": "3",
"GaussianSmoothingVarianceForTheConstantVelocityField": "1.0",
"GaussianSmoothingVarianceForTheUpdateField": "2.0"
"GaussianSmoothingVarianceForTheUpdateField": "3.0",
"GaussianSmoothingVarianceForTheConstantVelocityField": "0.5"
},
{
"Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ],
"ShrinkFactorsPerLevel": [ "12", "8", "4", "2" ],
"Dimensionality": "3"
},
{
......@@ -165,10 +163,6 @@
{
"Out": "FixedMask",
"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 @@
"POPI",
"DIRLAB",
"EMPIRE",
"LPBA40",
"IBSR18",
"CUMC12",
"MGH10",
"SPREAD",
"HAMMERS"
"SPREAD"
],
"Components": [
{
......@@ -21,7 +16,7 @@
{
"Name": "RegistrationMethod1",
"NameOfClass": "NiftyregAladinComponent",
"MaximumNumberOfIterations": "16"
"MaximumNumberOfIterations": "1"
},
{
"Name": "RegistrationMethod2",
......@@ -29,18 +24,16 @@
"InternalComputationValueType": "double",
"Dimensionality": "3",
"PixelType": "float",
"NumberOfLevels": "4",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "8", "4", "2", "1" ],
"NumberOfLevels": "3",
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"SmoothingSigmasPerLevel": [ "4", "2", "1" ],
"RescaleIntensity": ["0", "1"],
"InvertIntensity": "True",
"MetricSamplingPercentage": "0.2",
"MetricSamplingStrategy": "Random"
"InvertIntensity": "True"
},
{
"Name": "TransformResolutionAdaptor",
"NameOfClass": "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent",
"ShrinkFactorsPerLevel": [ "16", "8", "4", "2" ],
"ShrinkFactorsPerLevel": [ "8", "4", "2" ],
"Dimensionality": "3"
},
{
......@@ -67,20 +60,6 @@
"PixelType": "unsigned char",
"Dimensionality": "3"
},
{
"Name": "FixedImageCropper",
"NameOfClass": "ItkCropperComponent",
"Dimensionality": "3",
"PixelType": "float",
"Pad": 8
},
{
"Name": "MovingImageCropper",
"NameOfClass": "ItkCropperComponent",
"Dimensionality": "3",
"PixelType": "float",
"Pad": 8
},
{
"Name": "Metric2",
"NameOfClass": "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component",
......@@ -97,7 +76,7 @@
"Name": "Optimizer2",
"NameOfClass": "ItkGradientDescentOptimizerv4Component",
"InternalComputationValueType": "double",
"MaximumNumberOfIterations": "16",
"MaximumNumberOfIterations": "8",
"MaximumStepSizeInPhysicalUnits": "1.0",
"LearningRate": "0.25",
"EstimateScales": "True",
......@@ -123,30 +102,6 @@
},
{
"Out": "FixedImage",
"In": "FixedImageCropper",
"NameOfInterface": "itkImageInterface"
},
{
"Out": "FixedMask",
"In": "FixedImageCropper",
"NameOfInterface": "itkImageFixedMaskInterface"
},
{
"Out": "FixedImageCropper",
"In": "RegistrationMethod",
"NameOfInterface": "itkImageFixedInterface"
},
{
"Out": "MovingImage",
"In": "MovingImageCropper",
"NameOfInterface": "itkImageInterface"
},{
"Out": "MovingMask",
"In": "MovingImageCropper",
"NameOfInterface": "itkImageMovingMaskInterface"
},
{
"Out": "FixedImageCropper",
"In": "TransformResolutionAdaptor",
"NameOfInterface": "itkImageDomainFixedInterface"
},
......@@ -161,12 +116,17 @@
"NameOfInterface": "NiftyregFloatingImageInterface"
},
{
"Out": "FixedImageCropper",
"Out": "FixedMask",
"In": "RegistrationMethod1",
"NameOfInterface": "NiftyregInputMaskInterface"
},
{
"Out": "FixedImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageFixedInterface"
},
{
"Out": "MovingImageCropper",
"Out": "MovingImage",
"In": "RegistrationMethod2",
"NameOfInterface": "itkImageMovingInterface"
},
......@@ -183,7 +143,7 @@
"In": "RegistrationMethod2"
},
{
"Out": "FixedImageCropper",
"Out": "FixedImage",
"In": "Transform2"
},
{
......@@ -211,10 +171,6 @@
"Out": "FixedMask",
"In": "Metric2"
},
{
"Out": "MovingMask",
"In": "Metric2"
},
{
"Out": "FixedMask",
"In": "RegistrationMethod1",
......
......@@ -117,7 +117,6 @@ NiftyregItkMultiStageComponent< InternalComputationValueType, Dimensionality >::
this->m_CompositeTransform->AppendTransform( m_RegistrationStages[stageName]->GetItkTransform() );
}
}
return;
}
......
......@@ -72,7 +72,7 @@ void
ItkTransformDisplacementFilterComponent< Dimensionality, TPixel, TInternalComputationValue >
::BeforeUpdate()
{
// Required to satisfy input requirements when UpdateOutputInormation is run
// Required to satisfy input requirements when UpdateOutputInformation is run
this->m_DisplacementFieldFilter->SetTransform( this->m_TransformComponent->GetItkTransform() );
this->m_DisplacementFieldFilter->SetSize( this->m_ImageDomainFixed->GetLargestPossibleRegion().GetSize() );
......
......@@ -269,7 +269,7 @@ ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel, InternalComputat
// Next else-if blocks check if the name of setting is an existing property for this component, otherwise MeetsCriterion returns CriterionStatus::Failed.
if (criterionKey == "NumberOfLevels") //Does the Components have this setting?
{
if (criterionValues.size() == 1)
if (hasOneCriterionValue)
{
if (this->m_NumberOfLevelsLastSetBy.empty()) // check if some other settings set the NumberOfLevels
{
......@@ -454,7 +454,7 @@ ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel, InternalComputat
}
}
else if (criterionKey == "MetricSamplingPercentage") {
if (criterionValues.size() != 1) {
if (!hasOneCriterionValue) {
this->m_Logger.Log(LogLevel::ERR, "Expected one value for MetricSamplingPercetage, got {0}.", criterionValues.size());
return false;
}
......@@ -464,7 +464,7 @@ ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel, InternalComputat
}
}
else if (criterionKey == "MetricSamplingStrategy") {
if (criterionValues.size() != 1) {
if (!hasOneCriterionValue) {
this->m_Logger.Log(LogLevel::ERR, "Expected one value for MetricSamplingStrategy (Regular or Random), got {0}.", criterionValues.size());
return false;
}
......
......@@ -151,7 +151,7 @@ NetworkBuilder< ComponentList >::ApplyComponentConfiguration()
currentComponentSelector->AddCriterion( criterion );
this->m_Logger.Log( LogLevel::DBG,
"Finding component for '{0}': {1} component(s) satisfies '{2}' : '{3}' and previous criteria.",
"Finding component for {0}: {1} component(s) satisfies {2} : {3} and previous criteria.",
componentName,
currentComponentSelector->NumberOfComponents(),
criterion.first,
......@@ -205,14 +205,14 @@ NetworkBuilder< ComponentList >::ApplyConn