From 3b072585d9fc4e6b21940531196cec798ee74796 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 3 Feb 2012 07:57:12 +0100 Subject: [PATCH] In SliceBySliceSetBackgroundFromLineSeparation add keepIfEqual option --- itk/clitkSegmentationUtils.h | 11 +++++++++- itk/clitkSegmentationUtils.txx | 40 +++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index a63fd28..e8e2f89 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -339,7 +339,16 @@ namespace clitk { std::vector & lB, typename ImageType::PixelType BG, int mainDirection, - double offsetToKeep); + double offsetToKeep, + bool keepIfEqual=false); + template + void + SliceBySliceSetBackgroundFromLineSeparation(ImageType * input, + std::vector & lA, + std::vector & lB, + typename ImageType::PixelType BG, + typename ImageType::PointType offsetToKeep, + bool keepIfEqual=false); //-------------------------------------------------------------------- diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index de243ad..0d758e4 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -768,9 +768,24 @@ namespace clitk { std::vector & lB, typename ImageType::PixelType BG, int mainDirection, - double offsetToKeep) + double offsetToKeep, + bool keepIfEqual) { assert((mainDirection==0) || (mainDirection==1)); + typename ImageType::PointType offset; + offset[0] = offset[1] = offset[2] = 0.0; + offset[mainDirection] = offsetToKeep; + SliceBySliceSetBackgroundFromLineSeparation(input, lA, lB, BG, offset, keepIfEqual); + } + template + void + SliceBySliceSetBackgroundFromLineSeparation(ImageType * input, + std::vector & lA, + std::vector & lB, + typename ImageType::PixelType BG, + typename ImageType::PointType offsetToKeep, + bool keepIfEqual) + { typedef itk::ImageSliceIteratorWithIndex SliceIteratorType; SliceIteratorType siter = SliceIteratorType(input, input->GetLargestPossibleRegion()); siter.SetFirstDirection(0); @@ -795,7 +810,10 @@ namespace clitk { bool p = (A[0] == B[0]) && (A[1] == B[1]); if (!p) { - C[mainDirection] += offsetToKeep; // I know I must keep this point + //C[mainDirection] += offsetToKeep; // I know I must keep this point + C[0] += offsetToKeep[0]; + C[1] += offsetToKeep[1]; + //C[2] += offsetToKeep[2]; double s = (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]); bool isPositive = s<0; while (!siter.IsAtEndOfSlice()) { @@ -803,7 +821,9 @@ namespace clitk { // Very slow, I know ... but image should be very small input->TransformIndexToPhysicalPoint(siter.GetIndex(), C); double s = (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]); - if (s == 0) siter.Set(BG); // on the line, we decide to remove + if (s == 0) { + if (!keepIfEqual) siter.Set(BG); // on the line, we decide to remove + } if (isPositive) { if (s > 0) siter.Set(BG); } @@ -1346,14 +1366,14 @@ namespace clitk { } - // Debug dmap /* - typedef itk::Image FT; - FT::Pointer f = FT::New(); - typename FT::Pointer d1 = clitk::JoinSlices(dmaps1, S1, 2); - typename FT::Pointer d2 = clitk::JoinSlices(dmaps2, S2, 2); - writeImage(d1, "d1.mha"); - writeImage(d2, "d2.mha"); + // Debug dmap + typedef itk::Image FT; + FT::Pointer f = FT::New(); + typename FT::Pointer d1 = clitk::JoinSlices(dmaps1, S1, 2); + typename FT::Pointer d2 = clitk::JoinSlices(dmaps2, S2, 2); + writeImage(d1, "d1.mha"); + writeImage(d2, "d2.mha"); */ } //-------------------------------------------------------------------- -- 2.47.1