X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkSliceBySliceRelativePositionFilter.txx;h=d75cc889be2fb6a39b06fceb688e69c438425b65;hb=60c5b5c699be63c0bba2093f3f353e415fbcec5f;hp=9d355bfe39941ecff8807939043599e0c3421ffc;hpb=573d80d0f7a17607d2ee883c21c940c0ba020282;p=clitk.git diff --git a/itk/clitkSliceBySliceRelativePositionFilter.txx b/itk/clitkSliceBySliceRelativePositionFilter.txx index 9d355bf..d75cc88 100644 --- a/itk/clitkSliceBySliceRelativePositionFilter.txx +++ b/itk/clitkSliceBySliceRelativePositionFilter.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ + ======================================================================-====*/ // clitk #include "clitkSegmentationUtils.h" @@ -31,12 +31,16 @@ SliceBySliceRelativePositionFilter(): clitk::AddRelativePositionConstraintToLabelImageFilter() { SetDirection(2); - UniqueConnectedComponentBySliceOff(); + UniqueConnectedComponentBySliceFlagOff(); SetIgnoreEmptySliceObjectFlag(false); - UseASingleObjectConnectedComponentBySliceFlagOn(); + UseTheLargestObjectCCLFlagOff(); this->VerboseStepFlagOff(); this->WriteStepFlagOff(); this->SetCombineWithOrFlag(false); + ObjectCCLSelectionFlagOff(); + SetObjectCCLSelectionDimension(0); + SetObjectCCLSelectionDirection(1); + ObjectCCLSelectionIgnoreSingleCCLFlagOff(); } //-------------------------------------------------------------------- @@ -77,11 +81,15 @@ PrintOptions() DD(this->GetIntermediateSpacingFlag()); DD(this->GetIntermediateSpacing()); DD(this->GetFuzzyThreshold()); - DD(this->GetUniqueConnectedComponentBySlice()); + DD(this->GetUniqueConnectedComponentBySliceFlag()); DD(this->GetAutoCropFlag()); DD(this->GetInverseOrientationFlag()); DD(this->GetRemoveObjectFlag()); DD(this->GetCombineWithOrFlag()); + DD(this->GetUseTheLargestObjectCCLFlag()); + DD(this->GetObjectCCLSelectionFlag()); + DD(this->GetObjectCCLSelectionDimension()); + DD(this->GetObjectCCLSelectionIgnoreSingleCCLFlag()); } //-------------------------------------------------------------------- @@ -183,10 +191,43 @@ GenerateOutputInformation() if ((!GetIgnoreEmptySliceObjectFlag()) || (nb!=0)) { // Select or not a single CCL ? - if (GetUseASingleObjectConnectedComponentBySliceFlag()) { + if (GetUseTheLargestObjectCCLFlag()) { mObjectSlices[i] = KeepLabels(mObjectSlices[i], 0, 1, 1, 1, true); } + // Select a single according to a position if more than one CCL + if (GetObjectCCLSelectionFlag()) { + // if several CCL, choose the most extrema according a direction, + // if not -> should we consider this slice ? + if (nb<2) { + if (GetObjectCCLSelectionIgnoreSingleCCLFlag()) { + mObjectSlices[i] = SetBackground(mObjectSlices[i], mObjectSlices[i], + 1, this->GetBackgroundValue(), + true); + } + } + int dim = GetObjectCCLSelectionDimension(); + int direction = GetObjectCCLSelectionDirection(); + std::vector centroids; + ComputeCentroids(mObjectSlices[i], this->GetBackgroundValue(), centroids); + uint index=1; + for(uint j=1; j centroids[index][dim]) index = j; + } + else { + if (centroids[j][dim] < centroids[index][dim]) index = j; + } + } + for(uint v=1; v(mObjectSlices[i], mObjectSlices[i], + (char)v, this->GetBackgroundValue(), + true); + } + } + } // end GetbjectCCLSelectionFlag = true + // Relative position typedef clitk::AddRelativePositionConstraintToLabelImageFilter RelPosFilterType; typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); @@ -197,10 +238,14 @@ GenerateOutputInformation() relPosFilter->SetInput(mInputSlices[i]); relPosFilter->SetInputObject(mObjectSlices[i]); relPosFilter->SetRemoveObjectFlag(this->GetRemoveObjectFlag()); + // This flag (InverseOrientation) *must* be set before + // AddOrientation because AddOrientation can change it. + relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag()); for(int j=0; jGetNumberOfAngles(); j++) { relPosFilter->AddOrientationTypeString(this->GetOrientationTypeString(j)); + //DD(this->GetOrientationTypeString(j)); } - relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag()); + //DD(this->GetInverseOrientationFlag()); //relPosFilter->SetOrientationType(this->GetOrientationType()); relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing()); relPosFilter->SetIntermediateSpacingFlag(this->GetIntermediateSpacingFlag()); @@ -211,11 +256,20 @@ GenerateOutputInformation() mInputSlices[i] = relPosFilter->GetOutput(); // Select main CC if needed - if (GetUniqueConnectedComponentBySlice()) { + if (GetUniqueConnectedComponentBySliceFlag()) { mInputSlices[i] = Labelize(mInputSlices[i], 0, true, 1); mInputSlices[i] = KeepLabels(mInputSlices[i], 0, 1, 1, 1, true); } + /* + // Select unique CC according to the most in a given direction + if (GetUniqueConnectedComponentBySliceAccordingToADirection()) { + int nb; + mInputSlices[i] = LabelizeAndCountNumberOfObjects(mInputSlices[i], 0, true, 1, nb); + std::vector & centroids; + ComputeCentroids + } + */ } }