X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkSegmentationUtils.txx;h=75e5ef35f982b2d7e33fff174af5ae7b77c8ad40;hb=5f801bf0b07486889123e941d6913d4369dfc86f;hp=de243adc2bc5394f0623ade2b1b490e976991ab6;hpb=02f230e65dbfde06e84da374bb085643e29b5090;p=clitk.git diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index de243ad..75e5ef3 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_pt(input, lA, lB, BG, offset, keepIfEqual); + } + template + void + SliceBySliceSetBackgroundFromLineSeparation_pt(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); @@ -785,6 +800,8 @@ namespace clitk { // Check that the current slice correspond to the current point input->TransformIndexToPhysicalPoint(siter.GetIndex(), C); if ((fabs(C[2] - lA[i][2]))>0.01) { // is !equal with a tolerance of 0.01 mm + // FIXME : if not the same slices, should advance i or slice (not done yet) + // clitkExceptionMacro("Error list of point and slice do not start at the same location"); } else { // Define A,B,C points @@ -795,20 +812,27 @@ 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()) { while (!siter.IsAtEndOfLine()) { - // 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 (isPositive) { - if (s > 0) siter.Set(BG); - } - else { - if (s < 0) siter.Set(BG); + if (siter.Get() != BG) { // do only if not BG + // 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) { + if (!keepIfEqual) siter.Set(BG); // on the line, we decide to remove + } + if (isPositive) { + if (s > 0) siter.Set(BG); + } + else { + if (s < 0) siter.Set(BG); + } } ++siter; } @@ -1346,14 +1370,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"); */ } //--------------------------------------------------------------------