15 #include <itkCastImageFilter.h> 16 #include <itkGradientMagnitudeImageFilter.h> 17 #include <itkImageRegionIterator.h> 24 this->SetNumberOfRequiredInputs(1);
25 this->SetNumberOfIndexedOutputs(1);
26 this->SetNthOutput(0, output.GetPointer());
40 return Superclass::GetOutput();
51 if (idx + 1 > this->GetNumberOfInputs())
53 this->SetNumberOfRequiredInputs(idx + 1);
55 if (input != static_cast<InputType *>(this->ProcessObject::GetInput(idx)))
57 this->ProcessObject::SetNthInput(idx, const_cast<InputType *>(input));
66 if (this->GetNumberOfInputs() < 1)
74 if (this->GetNumberOfInputs() < 1)
86 itkExceptionMacro(
"mitk::ImageToLiveWireContourFilter: No input available. Please set the input!");
90 if (input->GetDimension() != 2)
92 MITK_ERROR <<
"Filter is only working on 2D images.";
93 itkExceptionMacro(
"mitk::ImageToLiveWireContourFilter: Filter is only working on 2D images.. Please make sure that " 109 catch (itk::ExceptionObject &e)
111 MITK_INFO <<
"Exception caught during live wiring calculation: " << e;
117 template <
typename TPixel,
unsigned int VImageDimension>
121 typedef itk::CastImageFilter<InputImageType, InternalImageType> CastFilterType;
123 typename CastFilterType::Pointer castFilter = CastFilterType::New();
124 castFilter->SetInput(inputImage);
125 castFilter->Update();
145 mask->SetVolume(this->
m_CostFunction->GetMaskImage()->GetBufferPointer());
158 auto iter = points.begin();
159 for (; iter != points.end(); iter++)
168 InternalImageType::IndexType startPoint, endPoint;
177 InternalImageType::IndexType startRegion;
178 startRegion[0] = startPoint[0] < endPoint[0] ? startPoint[0] : endPoint[0];
179 startRegion[1] = startPoint[1] < endPoint[1] ? startPoint[1] : endPoint[1];
182 InternalImageType::SizeType size;
183 size[0] = std::abs(startPoint[0] - endPoint[0]) + 1;
184 size[1] = std::abs(startPoint[1] - endPoint[1]) + 1;
187 region.SetSize(size);
188 region.SetIndex(startRegion);
216 this->SetNthOutput(0, output.GetPointer());
225 ShortestPathType::const_iterator pathIterator = shortestPath.begin();
227 while (pathIterator != shortestPath.end())
232 currentPoint[2] = 0.0;
234 input->GetGeometry()->IndexToWorld(currentPoint, currentPoint);
235 output->AddVertex(currentPoint,
false,
m_TimeStep);
251 catch (itk::ExceptionObject &e)
253 MITK_INFO <<
"Exception caught during dynamic cost map alculation: " << e;
260 template <
typename TPixel,
unsigned int VImageDimension>
274 std::vector<itk::Index<VImageDimension>> shortestPath;
280 auto it = output->IteratorBegin();
281 while (it != output->IteratorEnd())
285 input->GetGeometry()->WorldToIndex(c, c);
289 shortestPath.push_back(cur);
300 input->GetGeometry()->WorldToIndex(c, c);
304 shortestPath.push_back(cur);
310 typedef itk::GradientMagnitudeImageFilter<itk::Image<TPixel, VImageDimension>, itk::Image<TPixel, VImageDimension>>
311 GradientMagnitudeFilterType;
312 typename GradientMagnitudeFilterType::Pointer gradientFilter = GradientMagnitudeFilterType::New();
313 gradientFilter->SetInput(inputImage);
314 gradientFilter->Update();
315 typename itk::Image<TPixel, VImageDimension>::Pointer gradientMagnImage = gradientFilter->GetOutput();
320 auto pathIterator = shortestPath.begin();
322 std::map<int, int> histogram;
325 while (pathIterator != shortestPath.end())
329 histogram[
static_cast<int>(gradientMagnImage->GetPixel((*pathIterator)) *
337 if (!histogram.empty())
339 std::map<int, int>::iterator itMAX;
342 int currentMaxValue = 0;
343 auto it = histogram.begin();
344 while (it != histogram.end())
346 if ((*it).second > currentMaxValue)
349 currentMaxValue = (*it).second;
354 std::map<int, int>::key_type keyOfMax = itMAX->first;
357 auto end = histogram.end();
358 auto last = --(histogram.end());
360 std::map<int, int>::iterator left2;
361 std::map<int, int>::iterator left1;
362 std::map<int, int>::iterator right1;
363 std::map<int, int>::iterator right2;
367 if (right1 == end || right1 == last)
378 if (right1 == histogram.begin())
383 else if (right1 == (++(histogram.begin())))
398 double partRight1, partRight2, partLeft1, partLeft2;
399 partRight1 = partRight2 = partLeft1 = partLeft2 = 0.0;
431 max = (partRight1 + partRight2 + partLeft1 + partLeft2);
ImageLiveWireContourModelFilter()
mitk::Point3D m_EndPoint
end point in woorldcoordinates
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
const InputType * GetInput(void)
bool CreateDynamicCostMap(mitk::ContourModel *path=nullptr)
Create dynamic cost tranfer map - on the fly training.
itk::ImageRegion< 2 > RegionType
std::vector< itk::Index< 2 > > ShortestPathType
void ClearRepulsivePoints()
Clear all repulsive points used in the cost function.
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
CostFunctionType::Pointer m_CostFunction
The cost function to compute costs between two pixels.
::mitk::Image InputImageType
void AddRepulsivePoint(const itk::Index< 2 > &idx)
Add a single repulsive point to the cost function.
void SetRepulsivePoints(const ShortestPathType &points)
Set a vector with repulsive points to use in the cost function.
virtual OutputType * GetOutput()
static double Gaussian(double x, double xOfGaussian, double yOfGaussian)
Returns the y value of gaussian with given offset and amplitude.
mitk::Point3D m_EndPointInIndex
End point in index.
mitkBaseDataSourceGetOutputDeclarations itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
ShortestPathImageFilterType::Pointer m_ShortestPathFilter
Shortest path filter according to cost function m_CostFunction.
mitk::Point3D m_StartPoint
start point in worldcoordinates
void GenerateData() override
Image class for storing images.
VertexIterator IteratorEnd(int timestep=0) const
Returns a const VertexIterator at the end element of the contour.
InternalImageType::Pointer m_InternalImage
bool m_UseDynamicCostMap
Flag to use a dynmic cost map or not.
virtual void DumpMaskImage()
void CreateDynamicCostMapByITK(const itk::Image< TPixel, VImageDimension > *inputImage, mitk::ContourModel *path=nullptr)
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
void ItkPreProcessImage(const itk::Image< TPixel, VImageDimension > *inputImage)
mitk::Image::Pointer mask
VertexIterator IteratorBegin(int timestep=0) const
Returns a const VertexIterator at the start element of the contour.
virtual void SetInput(const InputType *input)
~ImageLiveWireContourModelFilter() override
mitk::Point3D m_StartPointInIndex
Start point in index.
void RemoveRepulsivePoint(const itk::Index< 2 > &idx)
Remove a single repulsive point from the cost function.