X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkSegmentationUtils.txx;h=00f3392f17a91477f3c4bc5790da0c97f05f95a0;hb=1361e8457bdc0d189ab0d44530a20cc2d5e04393;hp=9b226b25bac46543891b8652fff5d12e52eaf872;hpb=9a4f7a1a65fcaa160878e50a12a61bdacf78607a;p=clitk.git diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index 9b226b2..00f3392 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -297,7 +297,8 @@ namespace clitk { { typename ImageType::Pointer working_image; working_image = Labelize(input, BG, isFullyConnected, minimalComponentSize); - working_image = RemoveLabels(working_image, BG, param->GetLabelsToRemove()); + if (param->GetLabelsToRemove().size() != 0) + working_image = RemoveLabels(working_image, BG, param->GetLabelsToRemove()); working_image = KeepLabels(working_image, BG, FG, param->GetFirstKeep(), @@ -336,7 +337,8 @@ namespace clitk { std::string orientation, bool uniqueConnectedComponent, double spacing, - bool inverseflag) + bool autocropFlag, + bool singleObjectCCL) { typedef SliceBySliceRelativePositionFilter SliceRelPosFilterType; typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New(); @@ -350,8 +352,10 @@ namespace clitk { sliceRelPosFilter->SetIntermediateSpacingFlag((spacing != -1)); sliceRelPosFilter->SetIntermediateSpacing(spacing); sliceRelPosFilter->SetUniqueConnectedComponentBySlice(uniqueConnectedComponent); - sliceRelPosFilter->SetInverseOrientationFlag(inverseflag); - // sliceRelPosFilter->SetAutoCropFlag(true); ?? + sliceRelPosFilter->SetUseASingleObjectConnectedComponentBySliceFlag(singleObjectCCL); + // sliceRelPosFilter->SetInverseOrientationFlag(inverseflag); + sliceRelPosFilter->SetAutoCropFlag(autocropFlag); + sliceRelPosFilter->IgnoreEmptySliceObjectFlagOn(); sliceRelPosFilter->Update(); return sliceRelPosFilter->GetOutput(); } @@ -384,7 +388,7 @@ namespace clitk { /* loop over input pixels, store the index in the fg that is max according to the given direction. - */ + */ typedef itk::ImageRegionConstIteratorWithIndex IteratorType; IteratorType iter(input, input->GetLargestPossibleRegion()); iter.GoToBegin(); @@ -531,27 +535,6 @@ namespace clitk { //-------------------------------------------------------------------- - //-------------------------------------------------------------------- - template - typename ImageType::Pointer - JoinSlices(std::vector::Pointer > & slices, - const ImageType * input, - int direction) { - typedef typename itk::Image SliceType; - typedef itk::JoinSeriesImageFilter JoinSeriesFilterType; - typename JoinSeriesFilterType::Pointer joinFilter = JoinSeriesFilterType::New(); - joinFilter->SetOrigin(input->GetOrigin()[direction]); - joinFilter->SetSpacing(input->GetSpacing()[direction]); - for(unsigned int i=0; iPushBackInput(slices[i]); - } - joinFilter->Update(); - return joinFilter->GetOutput(); - } - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- template void @@ -831,8 +814,8 @@ namespace clitk { Binarize(const ImageType * input, typename ImageType::PixelType lower, typename ImageType::PixelType upper, - typename ImageType::PixelType BG=0, - typename ImageType::PixelType FG=1) + typename ImageType::PixelType BG, + typename ImageType::PixelType FG) { typedef itk::BinaryThresholdImageFilter BinaryThresholdFilterType; typename BinaryThresholdFilterType::Pointer binarizeFilter = BinaryThresholdFilterType::New(); @@ -919,5 +902,60 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + /* Consider an input object, for each slice, find the extrema + position according to a given direction and build a line segment + passing throught this point in a given direction. Output is a + vector of line (from point A to B), for each slice; + */ + template + void + SliceBySliceBuildLineSegmentAccordingToExtremaPosition(const ImageType * input, + typename ImageType::PixelType BG, + int sliceDimension, + int extremaDirection, + bool extremaOppositeFlag, + int lineDirection, + double margin, + std::vector & A, + std::vector & B) + { + // Type of a slice + typedef typename itk::Image SliceType; + + // Build the list of slices + std::vector slices; + clitk::ExtractSlices(input, sliceDimension, slices); + + // Build the list of 2D points + std::map position2D; + for(uint i=0; i(slices[i], BG, + extremaDirection, extremaOppositeFlag, p); + if (found) { + position2D[i] = p; + } + } + + // Convert 2D points in slice into 3D points + clitk::PointsUtils::Convert2DTo3DList(position2D, input, A); + + // Create additional point just right to the previous ones, on the + // given lineDirection, in order to create a horizontal/vertical line. + for(uint i=0; i