MCPcopy Create free account
hub / github.com/MITK/MITK / TransferLabelContentAtTimeStep

Method TransferLabelContentAtTimeStep

Modules/Multilabel/src/mitkLabelSetImage.cpp:1927–1993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1925}
1926
1927void mitk::TransferLabelContentAtTimeStep(
1928 const Image* sourceImage, Image* destinationImage, const mitk::ConstLabelVector& destinationLabels, const TimeStepType timeStep, mitk::Label::PixelType sourceBackground,
1929 mitk::Label::PixelType destinationBackground, bool destinationBackgroundLocked, LabelValueMappingVector labelMapping,
1930 MultiLabelSegmentation::MergeStyle mergeStyle, MultiLabelSegmentation::OverwriteStyle overwriteStlye)
1931{
1932 if (nullptr == sourceImage)
1933 {
1934 mitkThrow() << "Invalid call of TransferLabelContentAtTimeStep; sourceImage must not be null.";
1935 }
1936 if (nullptr == destinationImage)
1937 {
1938 mitkThrow() << "Invalid call of TransferLabelContentAtTimeStep; destinationImage must not be null.";
1939 }
1940
1941 if (sourceImage == destinationImage && labelMapping.size() > 1)
1942 {
1943 MITK_DEBUG << "Warning. Using TransferLabelContentAtTimeStep or TransferLabelContent with equal source and destination and more then on label to transfer, can lead to wrong results. Please see documentation and verify that the usage is OK.";
1944 }
1945
1946 Image::ConstPointer sourceImageAtTimeStep = SelectImageByTimeStep(sourceImage, timeStep);
1947 Image::Pointer destinationImageAtTimeStep = SelectImageByTimeStep(destinationImage, timeStep);
1948
1949 if (nullptr == sourceImageAtTimeStep)
1950 {
1951 mitkThrow() << "Invalid call of TransferLabelContentAtTimeStep; sourceImage does not have the requested time step: " << timeStep;
1952 }
1953
1954 if (nullptr == destinationImageAtTimeStep)
1955 {
1956 mitkThrow() << "Invalid call of TransferLabelContentAtTimeStep; destinationImage does not have the requested time step: " << timeStep;
1957 }
1958
1959 if (!Equal(*(sourceImageAtTimeStep->GetGeometry()), *(destinationImageAtTimeStep->GetGeometry()), mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_COORDINATE_PRECISION, mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_DIRECTION_PRECISION))
1960 {
1961 if (IsSubGeometry(*(sourceImageAtTimeStep->GetGeometry()), *(destinationImageAtTimeStep->GetGeometry()), mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_COORDINATE_PRECISION, mitk::NODE_PREDICATE_GEOMETRY_DEFAULT_CHECK_DIRECTION_PRECISION, true))
1962 {
1963 //we have to pad the source image
1964 //because ImageToImageFilters always check for origin matching even if
1965 //the requested output region is fitting :(
1966 auto padFilter = mitk::PadImageFilter::New();
1967 padFilter->SetInput(0, sourceImageAtTimeStep);
1968 padFilter->SetInput(1, destinationImageAtTimeStep);
1969 padFilter->SetPadConstant(Label::UNLABELED_VALUE);
1970 padFilter->SetBinaryFilter(false);
1971
1972 padFilter->Update();
1973
1974 sourceImageAtTimeStep = padFilter->GetOutput();
1975 }
1976 else
1977 {
1978 mitkThrow() << "Invalid call of TransferLabelContentAtTimeStep; source image has neither the same geometry than destination image nor has the source image a sub geometry.";
1979 }
1980 }
1981
1982 auto destLabelMap = ConvertLabelVectorToMap(destinationLabels);
1983 for (const auto& [sourceLabel, newDestinationLabel] : labelMapping)
1984 {

Callers

nothing calls this directly

Calls 14

ConvertLabelVectorToMapFunction · 0.85
GetGeometryMethod · 0.80
GetConstLabelsByValueMethod · 0.80
GetLabelValuesByGroupMethod · 0.80
EqualFunction · 0.50
NewFunction · 0.50
sizeMethod · 0.45
SetInputMethod · 0.45
UpdateMethod · 0.45
GetOutputMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected