From 004d8b63a5330e378d306d26c218c8bc04b2ead6 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Fri, 6 May 2011 14:36:58 +0200 Subject: [PATCH] Add Opening and SliceBySliceKeepMainCCL --- itk/clitkSegmentationUtils.h | 18 ++++++++++ itk/clitkSegmentationUtils.txx | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index 532abd7..4d71298 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -308,6 +308,15 @@ namespace clitk { bool extendSupport); //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + Opening(const ImageType * image, typename ImageType::SizeType radius, + typename ImageType::PixelType BG, typename ImageType::PixelType FG); + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void ConvertOption(std::string optionName, uint given, @@ -389,6 +398,15 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + SliceBySliceKeepMainCCL(const ImageType * input, + typename ImageType::PixelType BG, + typename ImageType::PixelType FG); + //-------------------------------------------------------------------- + + } #include "clitkSegmentationUtils.txx" diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index 16c184c..36594aa 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -32,6 +32,7 @@ #include #include #include +#include namespace clitk { @@ -730,6 +731,34 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + Opening(const ImageType * image, typename ImageType::SizeType radius, + typename ImageType::PixelType BG, + typename ImageType::PixelType FG) + { + // Kernel + typedef itk::BinaryBallStructuringElement KernelType; + KernelType structuringElement; + structuringElement.SetRadius(radius); + structuringElement.CreateStructuringElement(); + + // Filter + typedef itk::BinaryMorphologicalOpeningImageFilter OpeningFilterType; + typename OpeningFilterType::Pointer open = OpeningFilterType::New(); + open->SetInput(image); + open->SetBackgroundValue(BG); + open->SetForegroundValue(FG); + open->SetKernel(structuringElement); + open->Update(); + return open->GetOutput(); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- template void ConvertOption(std::string optionName, uint given, @@ -1020,5 +1049,37 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + SliceBySliceKeepMainCCL(const ImageType * input, + typename ImageType::PixelType BG, + typename ImageType::PixelType FG) { + + // Extract slices + const int d = ImageType::ImageDimension-1; + typedef typename itk::Image SliceType; + std::vector slices; + clitk::ExtractSlices(input, d, slices); + DD(slices.size()); + + // Labelize and keep the main one + std::vector o; + for(uint i=0; i(slices[i], BG, false, 1)); + o[i] = clitk::KeepLabels(o[i], BG, FG, 1, 1, true); + } + + // Join slices + DD("join"); + typename ImageType::Pointer output; + output = clitk::JoinSlices(o, input, d); + DD("return"); + return output; + } + //-------------------------------------------------------------------- + + } // end of namespace -- 2.47.1