8 template<
typename TInput,
typename TMask,
typename TOutput>
11 this->SetNthInput(0, const_cast<TInput *>(image));
14 template<
typename TInput,
typename TMask,
typename TOutput>
17 this->SetNthInput(1, const_cast<TMask *>(image));
20 template<
typename TInput,
typename TMask,
typename TOutput>
23 return static_cast< const TInput *
> 24 ( this->itk::ProcessObject::GetInput(0) );
26 template<
typename TInput,
typename TMask,
typename TOutput>
29 return static_cast< const TMask *
> 30 ( this->itk::ProcessObject::GetInput(1) );
33 template<
typename TInput,
typename TMask,
typename TOutput>
38 if( m_OutputFilename !=
"" )
40 std::cout <<
"Writing lesions output image to: " << m_OutputFilename << std::endl;
41 anima::writeImage<TOutput>(m_OutputFilename, this->GetOutput());
45 template<
typename TInput,
typename TMask,
typename TOutput >
50 bool fullyConnected =
false;
53 typename ConnectedComponentFilterType::Pointer ConnectedComponentFilter = ConnectedComponentFilterType::New();
54 ConnectedComponentFilter->SetInput( this->GetInputClassification() );
55 ConnectedComponentFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
56 ConnectedComponentFilter->SetCoordinateTolerance(m_Tol);
57 ConnectedComponentFilter->SetDirectionTolerance(m_Tol);
58 ConnectedComponentFilter->SetFullyConnected( fullyConnected );
60 unsigned int radius = 1;
63 structuringElement.SetRadius(radius);
64 structuringElement.CreateStructuringElement();
66 DilateFilterType::Pointer dilateFilter = DilateFilterType::New();
67 dilateFilter->SetInput(ConnectedComponentFilter->GetOutput());
68 dilateFilter->SetKernel(structuringElement);
69 dilateFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
70 dilateFilter->SetCoordinateTolerance(m_Tol);
71 dilateFilter->SetDirectionTolerance(m_Tol);
72 dilateFilter->Update();
75 typename LabelContourFilterType::Pointer filterLabelContour = LabelContourFilterType::New();
76 filterLabelContour->SetInput(dilateFilter->GetOutput());
77 filterLabelContour->SetFullyConnected( fullyConnected );
78 filterLabelContour->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
79 filterLabelContour->SetCoordinateTolerance(m_Tol);
80 filterLabelContour->SetDirectionTolerance(m_Tol);
81 filterLabelContour->SetBackgroundValue(0);
82 filterLabelContour->Update();
84 unsigned int objectCount = ConnectedComponentFilter->GetObjectCount();
86 std::vector<unsigned int> nbVoxelContour(objectCount+1,0);
87 std::vector<unsigned int> nbVoxelIntersec(objectCount+1,0);
88 std::vector<bool> enoughContour(objectCount+1,
true);
90 ImageIteratorTypeInt labelContourIt(filterLabelContour->GetOutput(), filterLabelContour->GetOutput()->GetLargestPossibleRegion());
92 while(!labelContourIt.IsAtEnd())
94 if(labelContourIt.Get()!=0)
96 nbVoxelContour[labelContourIt.Get()]++;
99 nbVoxelIntersec[labelContourIt.Get()]++;
107 for(
unsigned int i = 1; i < objectCount+1; i++)
109 if(static_cast<double>(nbVoxelIntersec[i])/static_cast<double>(nbVoxelContour[i]) < m_Ratio)
111 enoughContour[i] =
false;
118 output->SetRegions( this->GetInputClassification()->GetLargestPossibleRegion() );
119 output->CopyInformation( this->GetInputClassification() );
121 output->FillBuffer(0);
123 ImageIteratorTypeInt classifIt(ConnectedComponentFilter->GetOutput(), ConnectedComponentFilter->GetOutput()->GetLargestPossibleRegion());
125 while(!classifIt.IsAtEnd())
128 if(classifIt.Get()!=0)
130 if(enoughContour[classifIt.Get()]==
true)
void SetInputClassification(const TInput *image)
void GenerateData() ITK_OVERRIDE
void SetInputMap(const TMask *image)
itk::ImageRegionIterator< ImageTypeInt > ImageIteratorTypeInt
itk::ImageRegionIterator< OutputImageType > OutputIteratorType
OutputImageType::Pointer OutputImagePointer
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
itk::BinaryBallStructuringElement< PixelTypeInt, 3 > StructuringElementType
TInput::ConstPointer GetInputClassification()
TMask::ConstPointer GetInputMap()