From: dsarrut Date: Fri, 6 May 2011 12:36:58 +0000 (+0200) Subject: Add Opening and SliceBySliceKeepMainCCL X-Git-Tag: v1.2.1~4^2~4 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=004d8b63a5330e378d306d26c218c8bc04b2ead6;p=clitk.git Add Opening and SliceBySliceKeepMainCCL --- 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