16 #include <itkConstantPadImageFilter.h> 36 if (idx + 1 > this->GetNumberOfInputs())
38 this->SetNumberOfRequiredInputs(idx + 1);
40 if (input != static_cast<InputType *>(this->ProcessObject::GetInput(idx)))
42 this->ProcessObject::SetNthInput(idx, const_cast<InputType *>(input));
49 if (this->GetNumberOfInputs() < 1)
56 if (this->GetNumberOfInputs() < 1)
63 this->m_ContourValue = contourValue;
69 return this->m_ContourValue;
78 MITK_ERROR <<
"mitk::ImageToContourModelFilter: No input available. Please set the input!" << std::endl;
79 itkExceptionMacro(
"mitk::ImageToContourModelFilter: No input available. Please set the input!");
83 if (sliceImage->GetDimension() > 2 || sliceImage->GetDimension() < 2)
85 MITK_ERROR <<
"mitk::ImageToContourModelFilter::GenerateData() works only with 2D images. Please assure that your " 88 itkExceptionMacro(
"mitk::ImageToContourModelFilter::GenerateData() works only with 2D images. Please assure that " 89 "your input image is 2D!");
93 m_SliceGeometry = sliceImage->GetGeometry();
98 template <
typename TPixel,
unsigned int VImageDimension>
101 typedef itk::Image<TPixel, VImageDimension>
ImageType;
104 typedef itk::PolyLineParametricPath<2> PolyLineParametricPath2D;
105 typedef PolyLineParametricPath2D::VertexListType ContourPath;
107 typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
108 typename PadFilterType::Pointer padFilter = PadFilterType::New();
109 typename ImageType::SizeType lowerExtendRegion;
110 lowerExtendRegion[0] = 1;
111 lowerExtendRegion[1] = 1;
113 typename ImageType::SizeType upperExtendRegion;
114 upperExtendRegion[0] = 1;
115 upperExtendRegion[1] = 1;
122 padFilter->SetInput(sliceImage);
123 padFilter->SetConstant(0);
124 padFilter->SetPadLowerBound(lowerExtendRegion);
125 padFilter->SetPadUpperBound(upperExtendRegion);
127 typename ContourExtractor::Pointer contourExtractor = ContourExtractor::New();
128 contourExtractor->SetInput(padFilter->GetOutput());
129 contourExtractor->SetContourValue(m_ContourValue);
131 contourExtractor->Update();
133 unsigned int foundPaths = contourExtractor->GetNumberOfOutputs();
134 this->SetNumberOfIndexedOutputs(foundPaths);
136 for (
unsigned int i = 0; i < foundPaths; i++)
138 const ContourPath *currentPath = contourExtractor->GetOutput(i)->GetVertexList();
144 if (contour.IsNull())
149 if (contour.IsNull())
152 for (
unsigned int j = 0; j < currentPath->Size(); j++)
154 currentPoint[0] = currentPath->ElementAt(j)[0];
155 currentPoint[1] = currentPath->ElementAt(j)[1];
158 m_SliceGeometry->
IndexToWorld(currentPoint, currentWorldPoint);
160 contour->AddVertex(currentWorldPoint);
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
void GenerateData() override
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
itk::Image< unsigned char, 3 > ImageType
void Itk2DContourExtraction(const itk::Image< TPixel, VImageDimension > *sliceImage)
const InputType * GetInput(void)
Image class for storing images.
ImageToContourModelFilter()
virtual void SetInput(const InputType *input)
~ImageToContourModelFilter() override
void SetContourValue(float contourValue)