X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkSegmentationUtils.txx;h=f7b897e1f7805ffd4067af65af523ab9a3e4dbdc;hb=cf35c87a6dd45a7daf171d2adca9766846a0f127;hp=d2e17587cfdf246044231ad309059c7c662e8a0f;hpb=573d80d0f7a17607d2ee883c21c940c0ba020282;p=clitk.git diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index d2e1758..f7b897e 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -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 "clitkSetBackgroundImageFilter.h" @@ -32,6 +32,7 @@ #include #include #include +#include namespace clitk { @@ -420,7 +421,7 @@ namespace clitk { //-------------------------------------------------------------------- template typename ImageType::Pointer - CropImageAbove(const ImageType * image, + CropImageRemoveGreaterThan(const ImageType * image, int dim, double min, bool autoCrop, typename ImageType::PixelType BG) { @@ -435,7 +436,7 @@ namespace clitk { //-------------------------------------------------------------------- template typename ImageType::Pointer - CropImageBelow(const ImageType * image, + CropImageRemoveLowerThan(const ImageType * image, int dim, double max, bool autoCrop, typename ImageType::PixelType BG) { @@ -506,12 +507,55 @@ namespace clitk { statFilter->Update(); typename LabelMapType::Pointer labelMap = statFilter->GetOutput(); + centroids.clear(); + typename ImageType::PointType dummy; + centroids.push_back(dummy); // label 0 -> no centroid, use dummy point for BG + //DS FIXME (not useful ! to change ..) + for(uint i=0; iGetNumberOfLabelObjects(); i++) { + int label = labelMap->GetLabels()[i]; + centroids.push_back(labelMap->GetLabelObject(label)->GetCentroid()); + } + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + void + ComputeCentroids2(const ImageType * image, + typename ImageType::PixelType BG, + std::vector & centroids) + { + typedef long LabelType; + static const unsigned int Dim = ImageType::ImageDimension; + typedef itk::ShapeLabelObject< LabelType, Dim > LabelObjectType; + typedef itk::LabelMap< LabelObjectType > LabelMapType; + typedef itk::LabelImageToLabelMapFilter ImageToMapFilterType; + typename ImageToMapFilterType::Pointer imageToLabelFilter = ImageToMapFilterType::New(); + typedef itk::ShapeLabelMapFilter ShapeFilterType; + typename ShapeFilterType::Pointer statFilter = ShapeFilterType::New(); + imageToLabelFilter->SetBackgroundValue(BG); + imageToLabelFilter->SetInput(image); + statFilter->SetInput(imageToLabelFilter->GetOutput()); + statFilter->Update(); + typename LabelMapType::Pointer labelMap = statFilter->GetOutput(); + centroids.clear(); typename ImageType::PointType dummy; centroids.push_back(dummy); // label 0 -> no centroid, use dummy point for(uint i=1; iGetNumberOfLabelObjects()+1; i++) { centroids.push_back(labelMap->GetLabelObject(i)->GetCentroid()); } + + for(uint i=1; iGetNumberOfLabelObjects()+1; i++) { + DD(labelMap->GetLabelObject(i)->GetBinaryPrincipalAxes()); + DD(labelMap->GetLabelObject(i)->GetBinaryFlatness()); + DD(labelMap->GetLabelObject(i)->GetRoundness ()); + + // search for the point on the boundary alog PA + + } + } //-------------------------------------------------------------------- @@ -558,7 +602,7 @@ namespace clitk { //-------------------------------------------------------------------- template void - PointsUtils::Convert2DTo3DList(const MapPoint2DType & map, + PointsUtils::Convert2DMapTo3DList(const MapPoint2DType & map, const ImageType * image, VectorPoint3DType & list) { @@ -572,6 +616,24 @@ namespace clitk { } //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + template + void + PointsUtils::Convert2DListTo3DList(const VectorPoint2DType & p2D, + int slice, + const ImageType * image, + VectorPoint3DType & list) + { + for(uint i=0; i void @@ -668,6 +730,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, @@ -820,6 +910,7 @@ namespace clitk { typedef itk::BinaryThresholdImageFilter BinaryThresholdFilterType; typename BinaryThresholdFilterType::Pointer binarizeFilter = BinaryThresholdFilterType::New(); binarizeFilter->SetInput(input); + binarizeFilter->InPlaceOff(); binarizeFilter->SetLowerThreshold(lower); binarizeFilter->SetUpperThreshold(upper); binarizeFilter->SetInsideValue(FG); @@ -940,7 +1031,7 @@ namespace clitk { } // Convert 2D points in slice into 3D points - clitk::PointsUtils::Convert2DTo3DList(position2D, input, A); + clitk::PointsUtils::Convert2DMapTo3DList(position2D, input, A); // Create additional point just right to the previous ones, on the // given lineDirection, in order to create a horizontal/vertical line. @@ -957,5 +1048,33 @@ 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); + + // 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 + typename ImageType::Pointer output; + output = clitk::JoinSlices(o, input, d); + return output; + } + //-------------------------------------------------------------------- + + } // end of namespace