X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkRelativePositionAnalyzerFilter.txx;h=df12ea33437c42975282662ad74015745d625041;hb=cd054aec7943b5973dbf27ec20f62f38f0f11719;hp=c8d126a96d92d1ccf444dd59e08c83282ec77d75;hpb=5bff4d89c8ca42336267c36974e9ceb6fe2ac843;p=clitk.git diff --git a/itk/clitkRelativePositionAnalyzerFilter.txx b/itk/clitkRelativePositionAnalyzerFilter.txx index c8d126a..df12ea3 100644 --- a/itk/clitkRelativePositionAnalyzerFilter.txx +++ b/itk/clitkRelativePositionAnalyzerFilter.txx @@ -20,18 +20,13 @@ template clitk::RelativePositionAnalyzerFilter:: RelativePositionAnalyzerFilter(): - // clitk::FilterBase(), - clitk::FilterWithAnatomicalFeatureDatabaseManagement(), itk::ImageToImageFilter() { - this->SetNumberOfRequiredInputs(3); // support, object, target - VerboseFlagOff(); + this->SetNumberOfRequiredInputs(3); // Input : support, object, target SetBackgroundValue(0); SetForegroundValue(1); SetNumberOfBins(100); - SetNumberOfAngles(4); SetAreaLossTolerance(0.01); - m_ListOfAngles.clear(); SetSupportSize(0); SetTargetSize(0); SetSizeWithThreshold(0); @@ -106,20 +101,14 @@ void clitk::RelativePositionAnalyzerFilter:: GenerateData() { - this->LoadAFDB(); - - // Get input pointer - m_Support = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer temp = dynamic_cast(itk::ProcessObject::GetInput(0)); m_Object = dynamic_cast(itk::ProcessObject::GetInput(1)); m_Target = dynamic_cast(itk::ProcessObject::GetInput(2)); - static const unsigned int dim = ImageType::ImageDimension; - // Remove object from support + // Remove object from support (keep initial image) + m_Support = clitk::Clone(temp); clitk::AndNot(m_Support, m_Object, GetBackgroundValue()); - // Resize object like target (to enable substraction later) - ImagePointer objectLikeTarget = clitk::ResizeImageLike(m_Object, m_Target, GetBackgroundValue()); - // Define filter to compute statics on mask image typedef itk::LabelStatisticsImageFilter StatFilterType; typename StatFilterType::Pointer statFilter = StatFilterType::New(); @@ -139,82 +128,63 @@ GenerateData() SetTargetSize(statFilter->GetCount(GetForegroundValue())); // DD(GetTargetSize()); - // Build the list of tested orientations - m_ListOfAngles.clear(); - for(uint i=0; i180) a = 180-a; - m_ListOfAngles.push_back(clitk::deg2rad(a)); - RelativePositionOrientationType r; - r.angle1 = clitk::deg2rad(a); - r.angle2 = 0; - r.notFlag = false; - m_ListOfOrientation.push_back(r); - r.notFlag = true; - m_ListOfOrientation.push_back(r); - } - - // Loop on all orientations + // int bins = GetNumberOfBins(); double tolerance = GetAreaLossTolerance(); - for(int i=0; i(map, "fuzzy_"+toString(i)+".mha"); - - // Compute the optimal thresholds (direct and inverse) - double mThreshold=0.0; - double mReverseThreshold=1.0; - ComputeOptimalThresholds(map, m_Target, bins, tolerance, mThreshold, mReverseThreshold); - - // Use the threshold to compute new support - int s1 = GetSupportSize(); - // DD(mThreshold); - // DD(mReverseThreshold); - if (mThreshold > 0.0) { - ImagePointer support1 = - clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, - mThreshold, - m_ListOfAngles[i],false, - false, -1, true, false); - // writeImage(support1, "sup_"+toString(i)+".mha"); - // Compute the new support size - statFilter->SetInput(support1); - statFilter->SetLabelInput(support1); - statFilter->Update(); - s1 = statFilter->GetCount(GetForegroundValue()); - } - - int s2 = GetSupportSize(); - if (mReverseThreshold < 1.0) { - // DD(m_ListOfAngles[1]); - ImagePointer support2 = - clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, - mReverseThreshold, - m_ListOfAngles[i],true, - false, -1, true, false); - writeImage(support2, "sup_rev_"+toString(i)+".mha"); - // Compute the new support size - statFilter = StatFilterType::New(); - statFilter->SetInput(support2); - statFilter->SetLabelInput(support2); - statFilter->Update(); - s2 = statFilter->GetCount(GetForegroundValue()); - } - - // Set results values - RelativePositionInformationType r; - r.threshold = mThreshold; - r.sizeAfterThreshold = s1; // DD(s1); - r.sizeBeforeThreshold = GetSupportSize(); - r.sizeReference = GetTargetSize(); - m_ListOfInformation.push_back(r); - r.threshold = mReverseThreshold; - r.sizeAfterThreshold = s2; // DD(s2); - m_ListOfInformation.push_back(r); - // Print(); - } // end loop on orientations + // Compute Fuzzy map + double angle = GetDirection().angle1; + typename FloatImageType::Pointer map = ComputeFuzzyMap(m_Object, m_Target, m_Support, angle); + writeImage(map, "fuzzy_"+toString(clitk::rad2deg(angle))+".mha"); + + // Compute the optimal thresholds (direct and inverse) + double mThreshold=0.0; + double mReverseThreshold=1.0; + ComputeOptimalThresholds(map, m_Target, bins, tolerance, mThreshold, mReverseThreshold); + + // Use the threshold to compute new support + int s1 = GetSupportSize(); + if (mThreshold > 0.0) { + ImagePointer support1 = + clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, + mThreshold, + angle,false, // inverseFlag + false, // uniqueConnectedComponent + -1, true, + false);//singleObjectCCL + // Compute the new support size + statFilter->SetInput(support1); + statFilter->SetLabelInput(support1); + statFilter->Update(); + s1 = statFilter->GetCount(GetForegroundValue()); + } + + int s2 = GetSupportSize(); + if (mReverseThreshold < 1.0) { + ImagePointer support2 = + clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, + mReverseThreshold, + angle,true,// inverseFlag + false, // uniqueConnectedComponent + -1, true, + false); //singleObjectCCL + // Compute the new support size + statFilter = StatFilterType::New(); + statFilter->SetInput(support2); + statFilter->SetLabelInput(support2); + statFilter->Update(); + s2 = statFilter->GetCount(GetForegroundValue()); + } + + // Set results values + m_Info.threshold = mThreshold; + m_Info.sizeAfterThreshold = s1; + m_Info.sizeBeforeThreshold = GetSupportSize(); + m_Info.sizeReference = GetTargetSize(); + m_InfoReverse.threshold = mReverseThreshold; + m_InfoReverse.sizeAfterThreshold = s2; + m_InfoReverse.sizeBeforeThreshold = GetSupportSize(); + m_InfoReverse.sizeReference = GetTargetSize(); } //-------------------------------------------------------------------- @@ -223,24 +193,27 @@ GenerateData() template typename clitk::RelativePositionAnalyzerFilter::FloatImageType::Pointer clitk::RelativePositionAnalyzerFilter:: -ComputeFuzzyMap(ImageType * object, ImageType * target, double angle) +ComputeFuzzyMap(ImageType * object, ImageType * target, ImageType * support, double angle) { typedef clitk::SliceBySliceRelativePositionFilter SliceRelPosFilterType; typedef typename SliceRelPosFilterType::FloatImageType FloatImageType; typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New(); sliceRelPosFilter->VerboseStepFlagOff(); sliceRelPosFilter->WriteStepFlagOff(); - sliceRelPosFilter->SetInput(target); + sliceRelPosFilter->SetInput(support); sliceRelPosFilter->SetInputObject(object); sliceRelPosFilter->SetDirection(2); sliceRelPosFilter->SetIntermediateSpacingFlag(false); //sliceRelPosFilter->AddOrientationTypeString(orientation); - sliceRelPosFilter->AddAngles(angle, 0.0); + sliceRelPosFilter->AddAnglesInRad(angle, 0.0); sliceRelPosFilter->FuzzyMapOnlyFlagOn(); // do not threshold, only compute the fuzzy map // sliceRelPosFilter->PrintOptions(); sliceRelPosFilter->Update(); typename FloatImageType::Pointer map = sliceRelPosFilter->GetFuzzyMap(); + // Resize map like object to allow SetBackground + map = clitk::ResizeImageLike(map, object, GetBackgroundValue()); + // Remove initial object from the fuzzy map map = clitk::SetBackground(map, object, GetForegroundValue(), 0.0, true); @@ -310,17 +283,3 @@ ComputeOptimalThresholds(FloatImageType * map, ImageType * target, int bins, dou } //-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -Print(std::string s, std::ostream & os) -{ - for(int i=0; i