X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=segmentation%2FclitkExtractLungFilter.txx;h=a0acdd5ad2ab48aa3669d58f8d9d22171b74d329;hb=d7f456d86ca398a89ccf9de43ab68a2b50b8ca1f;hp=ffca1df50276062599cbcd22e76666cc25ce9a07;hpb=5ce3eec189c720473972869df4dd44d91fd52bc4;p=clitk.git diff --git a/segmentation/clitkExtractLungFilter.txx b/segmentation/clitkExtractLungFilter.txx index ffca1df..a0acdd5 100644 --- a/segmentation/clitkExtractLungFilter.txx +++ b/segmentation/clitkExtractLungFilter.txx @@ -47,6 +47,8 @@ #include "itkOrientImageFilter.h" #include "itkSpatialOrientationAdapter.h" #include "itkImageDuplicator.h" +#include "itkRelabelComponentImageFilter.h" + #include //-------------------------------------------------------------------- @@ -67,6 +69,7 @@ ExtractLungFilter(): SetForegroundValue(1); SetMinimalComponentSize(100); VerboseRegionGrowingFlagOff(); + RemoveSmallLabelBeforeSeparationFlagOn(); // Step 1 default values SetUpperThreshold(-300); @@ -436,7 +439,7 @@ GenerateOutputInformation() //-------------------------------------------------------------------- //-------------------------------------------------------------------- StartNewStep("Separate Left/Right lungs"); - PrintMemory(GetVerboseMemoryFlag(), "Before Separate"); + PrintMemory(GetVerboseMemoryFlag(), "Before Separate"); // Initial label working_mask = Labelize(working_mask, GetBackgroundValue(), @@ -451,9 +454,33 @@ GenerateOutputInformation() statisticsImageFilter->SetInput(working_mask); statisticsImageFilter->Update(); unsigned int initialNumberOfLabels = statisticsImageFilter->GetMaximum(); - working_mask = statisticsImageFilter->GetOutput(); - + working_mask = statisticsImageFilter->GetOutput(); PrintMemory(GetVerboseMemoryFlag(), "After count label"); + + // If already 2 labels, but a too big differences, remove the + // smalest one (sometimes appends with the stomach + if (initialNumberOfLabels >1) { + if (GetRemoveSmallLabelBeforeSeparationFlag()) { + DD(GetRemoveSmallLabelBeforeSeparationFlag()); + typedef itk::RelabelComponentImageFilter RelabelFilterType; + typename RelabelFilterType::Pointer relabelFilter = RelabelFilterType::New(); + relabelFilter->SetInput(working_mask); + relabelFilter->SetMinimumObjectSize(10); + relabelFilter->Update(); + const std::vector & a = relabelFilter->GetSizeOfObjectsInPhysicalUnits(); + std::vector remove_label; + for(unsigned int i=1; i(working_mask, GetBackgroundValue(), remove_label); + statisticsImageFilter->SetInput(working_mask); + statisticsImageFilter->Update(); + initialNumberOfLabels = statisticsImageFilter->GetMaximum(); + } + } // Decompose the first label if (initialNumberOfLabels<2) { @@ -631,6 +658,9 @@ SearchForTracheaSeed2(int numberOfSlices) opening->Update(); typename SlicerFilterType::Pointer slicer = SlicerFilterType::New(); +#if ITK_VERSION_MAJOR >= 4 + slicer->SetDirectionCollapseToIdentity(); +#endif slicer->SetInput(opening->GetOutput()); // label result