14 #include <itkAndImageFilter.h> 15 #include <itkNotImageFilter.h> 16 #include <itkOrImageFilter.h> 21 typedef itk::Image<mitk::Label::PixelType, 3>
ImageType;
25 if (segmentation->GetDimension() != 4)
29 imageTimeSelector->SetInput(segmentation);
30 imageTimeSelector->SetTimeNr(static_cast<int>(time));
32 imageTimeSelector->UpdateLargestPossibleRegion();
34 return imageTimeSelector->GetOutput();
39 ImageType::Pointer result;
48 : m_Type(type), m_SegmentationA(segmentationA), m_SegmentationB(segmentationB), m_Time(time)
50 this->ValidateSegmentations();
62 return this->GetDifference();
65 return this->GetIntersection();
68 return this->GetUnion();
71 mitkThrow() <<
"Unknown boolean operation type '" << m_Type <<
"'!";
80 auto notFilter = itk::NotImageFilter<ImageType, ImageType>::New();
81 notFilter->SetInput(input2);
83 auto andFilter = itk::AndImageFilter<ImageType, ImageType>::New();
84 andFilter->SetInput1(input1);
85 andFilter->SetInput2(notFilter->GetOutput());
87 andFilter->UpdateLargestPossibleRegion();
90 CastToMitkImage<ImageType>(andFilter->GetOutput(), tempResult);
92 tempResult->DisconnectPipeline();
95 result->InitializeByLabeledImage(tempResult);
105 auto andFilter = itk::AndImageFilter<ImageType, ImageType>::New();
106 andFilter->SetInput1(input1);
107 andFilter->SetInput2(input2);
109 andFilter->UpdateLargestPossibleRegion();
112 CastToMitkImage<ImageType>(andFilter->GetOutput(), tempResult);
114 tempResult->DisconnectPipeline();
117 result->InitializeByLabeledImage(tempResult);
127 auto orFilter = itk::OrImageFilter<ImageType, ImageType>::New();
128 orFilter->SetInput1(input1);
129 orFilter->SetInput2(input2);
131 orFilter->UpdateLargestPossibleRegion();
134 CastToMitkImage<ImageType>(orFilter->GetOutput(), tempResult);
136 tempResult->DisconnectPipeline();
139 result->InitializeByLabeledImage(tempResult);
146 if (segmentation.IsNull())
147 mitkThrow() <<
"Segmentation is nullptr!";
149 if (segmentation->GetImageDescriptor()->GetNumberOfChannels() != 1)
150 mitkThrow() <<
"Segmentation has more than one channel!";
152 auto pixelType = segmentation->GetImageDescriptor()->GetChannelDescriptor().GetPixelType();
154 if (pixelType.GetPixelType() != itk::ImageIOBase::SCALAR ||
155 (pixelType.GetComponentType() != itk::ImageIOBase::UCHAR &&
156 pixelType.GetComponentType() != itk::ImageIOBase::USHORT))
157 mitkThrow() <<
"Segmentation is neither of type 'unsigned char' nor type 'unsigned short'!";
159 auto dimension = segmentation->GetDimension();
162 mitkThrow() <<
"Segmentation has more than four dimensions!";
167 mitkThrow() <<
"Expected four-dimensional segmentation!";
169 if (segmentation->GetDimension(3) < m_Time)
170 mitkThrow() <<
"Extent of fourth dimension of segmentation is less than specified time!";
172 else if (dimension < 3)
174 mitkThrow() <<
"Segmentation has less than three dimensions!";
178 void mitk::BooleanOperation::ValidateSegmentations()
const 180 this->ValidateSegmentation(m_SegmentationA);
181 this->ValidateSegmentation(m_SegmentationB);
183 if (m_SegmentationA->GetDimension() != m_SegmentationB->GetDimension())
184 mitkThrow() <<
"Segmentations have different dimensions!";
itk::Image< mitk::Label::PixelType, 3 > ImageType
LabelSetImage::Pointer GetResult() const
static mitk::Image::Pointer Get3DSegmentation(mitk::Image::Pointer segmentation, unsigned int time)
BooleanOperation(Type type, Image::Pointer segmentationA, Image::Pointer segmentationB, unsigned int time=0)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static ImageType::Pointer CastTo3DItkImage(mitk::Image::Pointer segmentation, unsigned int time)